Skip to content

Position

Query account of unrealized gain or loss

First, you need login.

In

api.list_positions?

Out

Signature:
    api.list_positions(
    account: shioaji.account.Account = None,
    timeout: int = 5000,
    cb: Callable[[List[shioaji.position.Position]], NoneType] = None,
    ) -> List[shioaji.position.Position]
Docstring:
    query account of unrealized gain or loss
    Args:
        account (:obj:Account):
            choice the account from listing account (Default: stock account)

Stocks

In

api.list_positions(api.stock_account)

Out

[Position(code='2890', direction=<Action.Buy: 'Buy'>, quantity=10, price=10.1, pnl=1234.0, yd_quantity=10)]

Shares

In

api.list_positions(api.stock_account, unit="Share")

Out

[Position(code='2890', direction=<Action.Buy: 'Buy'>, quantity=10000, price=10.1, pnl=1234.0, yd_quantity=10000)]

Stock to dataframe

In

positions = api.list_positions(api.stock_account)
df = pd.DataFrame(positions)
df

Out

code cond direction pnl price quantity yd_quantity
2890 StockOrderCond.Cash Action.Buy -1234.0 10.1 10 10

Attributes:

code (str): contract id.
direction (Action): action.
    {Buy, Sell}
quantity (int): quantity.
price (float): the average price.
pnl (float): unrealized profit.
yd_quantity (int): yesterday
cond (StockOrderCond): Default Cash.
    {Cash(現股), Netting(餘額交割), MarginTrading(融資), ShortSelling(融券), Emerging(興櫃)}