Skip to main content

帳務


我們可以透過成交及庫存查詢來確認損益等資訊。

info

查詢發送的次數為每秒5次,若超出上限,請稍後再試試!

庫存查詢

inventories = sdk.accounting.inventories(accounts.data[0])
print(inventories)
Result {
is_success: true,
message: None,
data : [
Inventory{
date: "2023/09/20", # 查詢庫存日期 (string)
account: "26", # 帳號 (string)
branch_no: "6460", # 分公司代號 (string)
stock_no: "1101", # 股票代號 (string)
order_type: Stock, # 委託類別 (OrderType)
lastday_qty: 2000, # 昨日整股餘額 (int)
buy_qty: 0, # 整股委買股數 (int)
buy_filled_qty: 0, # 整股買進成交股數 (int)
buy_value: 0, # 整股買進成交價金 (int)
today_qty: 2000, # 整股餘額 (int)
tradable_qty: 2000, #可委託整股庫存數 (int)
sell_qty: 0, # 整股委賣股數 (int)
sell_filled_qty: 0, # 整股賣出成交股數 (int)
sell_value: 0, # 整股賣出成交價金 (int)
odd: InventoryOdd{ # 零股
lastday_qty: 0, # 昨日零股餘額 (int)
buy_qty: 0, # 零股委買股數 (int)
buy_filled_qty: 0, # 零股買進成交股數 (int)
buy_value: 0, # 零股買進成交價金 (int)
today_qty: 0, # 零股餘額 (int)
tradable_qty: 0, # 可委託零股餘額 (int)
sell_qty: 0, # 零股委賣股數 (int)
sell_filled_qty: 0, # 零股賣出成交股數 (int)
sell_value: 0 # 零股賣出成交價金 (int)
}},
...
]
}
  • 以下範例回傳僅擷取data內容

未實現損益查詢

unrealized_pnl = sdk.accounting.unrealiezd_gains_and_loses(accounts.data[0])
print(unrealized_pnl.data)
[UnrealizedData({
date: "2023/05/23", # 庫存建立日期 (string)
account: "482", # 帳號 (string)
branch_no: "6460", # 分公司代號 (string)
stock_no: "2442", # 股票代號 (string)
buy_sell: Buy, # 買賣別 (BSAction)
order_type: Margin, # 委託類別 (OrderType)
cost_price: 19.95, # 成本價 (int)
tradable_qty: 6000, # 可委託庫存數 (int)
unrealized_profit: 0, # 未實現獲利 (int)
unrealized_loss: 10002 # 未實現損失 (int)
}),
...
]

交割資訊

可以查詢交割資訊,確認我們今日或近三日的應收付金額。

settlement = sdk.accounting.query_settlement(accounts.data[0],"0d")
print(settlement.data)

以下查詢的結果代表9/12時應付1,429,513元交割款:

SettlementData{
account: AccountRes{ # 帳號資訊
branch_no: "6460", # 帳號 (string)
account: "26" # 分公司代號 (string)
},
details: [ # 交割資訊
{
date: "2023/09/08", # 查詢日期 (string)
settlement_date: "2023/09/12", # 交割日期 (string)
buy_value: 735500, # 買進金額 (int)
buy_fee: 313, # 買進手續費 (int)
buy_settlement: -1429513, # 買進應收付款 (int)
buy_tax: 0, # 買進交易稅 (int)
sell_value: 770500, # 賣出金額 (int)
sell_fee: 320, # 賣出手續費 (int)
sell_settlement: 0, # 賣出應收付款 (int)
sell_tax: 2309, # 賣出交易稅 (int)
total_bs_value: 1506000, # 合計買賣金額 (int)
total_fee: 633, # 合計手續費 (int)
total_tax: 2309, # 合計交易稅 (int)
total_settlement_amount: -1429513, # 合計交割金額 (int)
currency: "TWD", # 幣別 (string)
}
]
}