Skip to main content

Accounting


We can query profit and loss information through trade and inventory inquiries.

info

The limit of queries is 5 times / sec. If it exceeds the limit, please wait a moment and try again.

Inventory

inventories = sdk.accounting.inventories(accounts.data[0])
print(inventories)
Result {
is_success: true,
message: None,
data : [
Inventory{
date: "2023/09/20", # Query date(Today) (string)
account: "26", # Account (string)
branch_no: 6460, # Branch number (number)
stock_no: "1101", # Symbol (string)
order_type: Stock, # Order Type (OrderType)
lastday_qty: 2000, # Yesterday Share balacne (number)
buy_qty: 0, # Total volume purchased today (number)
buy_filled_qty: 0, # Total purchased filled today (number)
buy_value: 0, # Total amount purchased today (number)
today_qty: 2000, # Today Share balacne (number)
tradable_qty: 2000, #Available quantity (number)
sell_qty: 0, # Total volume sell today (number)
sell_filled_qty: 0, # Total sell filled today (number)
sell_value: 0, # Total amount sell today (number)
odd: InventoryOdd{ # odd lot
lastday_qty: 0, # Yesterday odd lot balacne (number)
buy_qty: 0, # Total volume purchased today (number)
buy_filled_qty: 0, # Total purchased filled today (number)
buy_value: 0, # Total amount purchased today (number)
today_qty: 0, # Today odd lot balacne (number)
tradable_qty: 0, # Available quantity (number)
sell_qty: 0, # Total volume sell today (number)
sell_filled_qty: 0,# Total sell filled today (number)
sell_value: 0 # Total amount sell today (number)
}},
...
]
}
  • Below example only extract data content

Unrealized profit and loss

unrealized_pnl = sdk.accounting.unrealized_gains_and_loses(accounts.data[0])
print(unrealized_pnl.data)
[UnrealizedData({
date: "2023/05/23", # Date of inquiry (string)
account: "482", # Account (string)
branch_no: "6460", # Branch number (string)
stock_no: "2442", # Symbol (string)
buy_sell: Buy, # Transaction direction (BSAction)
order_type: Margin, # Order Type (OrderType)
cost_price: 19.95, # Holding cost (number)
tradable_qty: 6000, # Available quantity (number)
unrealized_profit: 0, # Unrealized profit (number)
unrealized_loss: 10002 # Unrealized loss (number)
}),
...
]

Settlement information

You can inquire about Settlement information to confirm the amount receivable or payable for today or the past three days.

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

The results of the following inquiry represent a receivable delivery amount of 68,100 TWD for September 12th:

SettlementData({
account: AccountRes { # Account Information
branch_no: "6460", # Account (string)
account: "26" # Branch number (string)
},
details: [ # Settlement Information
{
date: "2023/09/08", # Query Date (Today) (string)
settlement_date: "2023/09/12", # Settlement Date (string)
buy_value: 735500, # Buying Value (int)
buy_fee: 313, # Buying Fee (int)
buy_settlement: -1429513, # Buying Payable / Receivable Amount (int)
buy_tax: 0, # Buying Tax (int)
sell_value: 770500, # Selling Value (int)
sell_fee: 320, # Selling Fee (int)
sell_settlement: 0, # Selling Payable / Receivable Amount (int)
sell_tax: 2309, # Selling Tax (int)
total_bs_value: 1506000, # Total Buying & Selling Value (int)
total_fee: 633, # Total Fee (int)
total_tax: 2309, # Total Tax (int)
total_settlement_amount: -1429513, # Total Payable & Receivable Amount (int)
currency: "TWD", # Currency (string)
}
]
})