Skip to content

未實現損益

用於查詢帳戶未實現損益,需要先登入

未實現損益

證券

證券

var positions = _api.ListPositions(account:_api.StockAccount);
Console.WriteLine(positions);
foreach (var position in (List<StockPosition>)positions)
{
    Console.WriteLine(position);
}
var positions = _api.ListPositions(account:_api.StockAccount, unit: Unit.Share);
Console.WriteLine(positions);
foreach (var position in (List<StockPosition>)positions)
{
    Console.WriteLine(position);
}

Out

System.Collections.Generic.List`1[Sinopac.Shioaji.StockPosition]
{
    yd_quantity=2, 
    cond=Cash, 
    margin_purchase_amount=0, 
    collateral=0, 
    short_sale_margin=0, 
    interest=0, 
    id=0, 
    code=1101, 
    direction=Buy, 
    quantity=2, 
    price=45.35, 
    last_price=31.0, 
    pnl=-31786.0
}
System.Collections.Generic.List`1[Sinopac.Shioaji.StockPosition]
{
    yd_quantity=2199, 
    cond=Cash, 
    margin_purchase_amount=0, 
    collateral=0, 
    short_sale_margin=0, 
    interest=0, 
    id=0, 
    code=1101, 
    direction=Buy, 
    quantity=2199, 
    price=45.35, 
    last_price=39.5, 
    pnl=-13158.0
}

StockPosition

id (int): 部位代碼
code (string): 商品代碼
direction (Action): {Buy: , Sell: }
quantity (int): 數量
price (decimal): 平均價格
last_price (decimal): 目前股價
pnl (decimal): 損益
yd_quantity (int): 昨日庫存數量
cond (StockOrderCond): {
    Cash: 現股(預設值), 
    Netting: 餘額交割,
    MarginTrading: 融資, 
    ShortSelling: 融券, 
    Emerging: 興櫃
    }
margin_purchase_amount (int): 融資金額 
collateral (int): 擔保品 
short_sale_margin (int): 保證金
interest (int): 除息

期貨選擇權

期貨

var positions = _api.ListPositions(account:_api.FutureAccount);
Console.WriteLine(positions);
foreach (var position in (List<FuturePosition>)positions)
{
    Console.WriteLine(position);
}

Out

System.Collections.Generic.List`1[Sinopac.Shioaji.FuturePosition]
{
    id=0, 
    code=TX400130J2, 
    direction=Buy, 
    quantity=1, 
    price=68.0, 
    last_price=78.0, 
    pnl=500.0
}

FuturePosition

id (int): 部位代碼
code (string): 商品代碼
direction (Action): {Buy: , Sell: }
quantity (int): 數量
price (decimal): 平均價格
last_price (decimal): 目前價格
pnl (decimal): 損益

未實現損益明細

證券

證券

var listPositions = _api.ListPositions();
var positionDetail = _api.ListPositionDetail(_api.StockAccount, listPositions[0].id);
foreach (var detail in (List<StockPositionDetail>)positionDetail)
{
    Console.WriteLine($"PositionDetail: {detail}");
}

Out

System.Collections.Generic.List`1[Sinopac.Shioaji.StockPositionDetail]
{
    code=2377, 
    date=2021-05-06, 
    quantity=1, 
    price=180998.0, 
    last_price=141006.0, 
    cond=Cash, 
    ex_dividends=16600, 
    interest=0, 
    margintrading_amt=0, 
    collateral=0,           
    dseq=IB859, 
    direction=Buy, 
    pnl=-39992.0, 
    currency=TWD, 
    fee=98.0
}

StockPositionDetail

code (string): 商品代碼
date (string): 交易日期
quantity (int): 數量
price (decimal): 付出成本
last_price (decimal): 現值
cond (StockOrderCond): {
    Cash: 現股(預設值), 
    Netting: 餘額交割,
    MarginTrading: 融資, 
    ShortSelling: 融券, 
    Emerging: 興櫃
    }
ex_dividends(int): 除息金額
interest (int): 除息
margintrading_amt(int): 融資金額
collateral (int): 擔保品 
dseq (string): 委託書號
direction (Action): {Buy: , Sell: }
pnl (decimal): 損益
currency (string): 幣別 {NTD, USD, HKD, EUR, CAD, BAS}
fee (decimal): 交易手續費

期貨選擇權

期貨

var listPositions = _api.ListPositions(account: _api.FutureAccount);
var positionDetail = _api.ListPositionDetail(_api.FutureAccount, listPositions[0].id);
foreach (var detail in (List<FuturePositionDetail>)positionDetail)
{
    Console.WriteLine($"PositionDetail: {detail}");
}

Out

System.Collections.Generic.List`1[Sinopac.Shioaji.FuturePositionDetail]
{
    entry_quantity=1, 
    date=2023-02-14, 
    code=MXFC3, 
    quantity=1, 
    price=15611.0, 
    last_price=15542.0, 
    dseq=tA0n8, 
    direction=Buy, 
    pnl=-3450.0, 
    currency=TWD, 
    fee=0
}

FuturePositionDetail

code (string): 商品代碼
date (string): 交易日期
quantity (int): 數量
price (decimal): 價格
last_price (decimal): 目前股價    
dseq (string): 委託書號
direction (Action): {Buy: , Sell: }
pnl (decimal): 損益
currency (string): 幣別 {NTD, USD, HKD, EUR, CAD, BAS}
fee (decimal): 交易手續費
entry_quantity(): 新倉數量