Skip to content

已實現損益

需要先登錄

已實現損益

In

var listProfitLoss = _api.ListProfitLoss(
        begin_date:"2021-03-01", 
        end_date:"2021-03-31",
        account: _api.StockAccount,
        unit: Unit.Common
    );

Console.WriteLine(listProfitLoss);
foreach (var profitLoss in (List<StockProfitLoss>)listProfitLoss)
{
    Console.WriteLine($"{profitLoss}");
}
var listProfitLoss = _api.ListProfitLoss(
        begin_date:"2022-10-19", 
        end_date:"2022-10-19", 
        account:_api.FutureAccount
    );

Console.WriteLine(listProfitLoss);
foreach (var profitLoss in (List<FutureProfitLoss>)listProfitLoss)
{
    Console.WriteLine($"{profitLoss}");
}

Out

System.Collections.Generic.List`1[Sinopac.Shioaji.StockProfitLoss]
{
    id=0, 
    seqno=21272, 
    dseq=ID884, 
    price=40.3, 
    pr_ratio=0.0048, 
    cond=Cash,             
    code=2031, 
    quantity=1, 
    pnl=191.0, 
    date=2021-03-15
}
System.Collections.Generic.List`1[Sinopac.Shioaji.FutureProfitLoss]
{            
    id=0, 
    entry_price=63, 
    cover_price=0, 
    tax=3, 
    fee=20,             
    code=TXO01350J2, 
    quantity=1, 
    pnl=-3150.0, 
    date=20221019
}

Attributes:

id (int): 可利用此id查詢明細
code (string): 商品代碼
seqno (string): seqno no.
dseq (string): seqno no.
quantity (int): 數量
price (decimal): 價格
pnl (fldecimaloat): 損益
pr_ratio (decimal): 損益比
cond (StockOrderCond): {
                Cash: 現股(預設值), 
                Netting: 餘額交割,
                MarginTrading: 融資, 
                ShortSelling: 融券, 
                Emerging: 興櫃
            }
date (string): 交易日期
id (int): 可利用此id查詢明細
code (string): 商品代碼
quantity (int): 數量
pnl (decimal): 損益
date (string): 交易日期
entry_price (int): 進倉價格
cover_price (int): 平倉價格
tax (int): 交易稅
fee (int): 交易手續費

已實現損益 - 明細

可從針對ListProfitLossDetail得到的結果,將id帶入detail_id查詢該筆明細。

In

var listProfitLoss = _api.ListProfitLoss(
        begin_date:"2021-03-01", 
        end_date:"2021-03-31",
        account:_api.StockAccount,
        unit: Unit.Common
    );
Console.ReadKey();
var listProfitLossDetail = _api.ListProfitLossDetail(detail_id:listProfitLoss[0].id);
Console.WriteLine($"{listProfitLossDetail}");
foreach (var detail in (List<StockProfitDetail>)listProfitLossDetail)
{
    Console.WriteLine($"{detail}");
}
var listProfitLoss = _api.ListProfitLoss(
        begin_date:"2022-10-19", 
        end_date:"2022-10-19", 
        account:_api.FutureAccount
    );
Console.ReadKey();
var listProfitLossDetail = _api.ListProfitLossDetail(detail_id:listProfitLoss[0].id);
Console.WriteLine($"{listProfitLossDetail}");
foreach (var detail in (List<FutureProfitDetail>)listProfitLossDetail)
{
    Console.WriteLine($"{detail}");
}

Out

System.Collections.Generic.List`1[Sinopac.Shioaji.StockProfitDetail]
{
    price=39.95, 
    cost=39969, 
    rep_margintrading_amt=0, 
    rep_collateral=0, 
    rep_margin=0, 
    shortselling_fee=0, 
    ex_dividend_amt=0, 
    interest=0, 
    trade_type=Common, 
    cond=Cash, 
    date=2021-03-11, 
    code=2031, 
    quantity=1, 
    dseq=IN383, 
    fee=19, 
    tax=0, 
    currency=NTD
}
System.Collections.Generic.List`1[Sinopac.Shioaji.FutureProfitDetail]
{
    direction=Buy, 
    entry_price=56, 
    cover_price=0, 
    pnl=-2800, 
    date=20221019, 
    code=TXO01350J2, 
    quantity=1, 
    dseq=vA0op, 
    fee=20, 
    tax=3, 
    currency=NTD
}

Attributes:

date (string): 交易日期
code (string): 商品代碼
quantity (int): 數量
dseq (string): 委託書號
fee (int): 交易手續費
tax (int): 交易稅
currency (string): 幣別 {NTD, USD, HKD, EUR, CAD, BAS}
price (decimal): 成交單價
cost (int): 付出成本
rep_margintrading_amt (int): 償還融資金額
rep_collateral (int): 償還擔保品
rep_margin (int): 償還保證金
shortselling_fee (decimal): 融券手續費
ex_dividend_amt: 除息金額
interest (int): 利息
trade_type (TradeType): {Common, DayTrade}
cond (StockOrderCond): {
                Cash: 現股(預設值), 
                Netting: 餘額交割,
                MarginTrading: 融資, 
                ShortSelling: 融券, 
                Emerging: 興櫃
            }
date (string): 交易日期
code (string): 商品代碼
quantity (int): 數量
dseq (string): 委託書號
fee (decimal): 交易手續費
tax (int): 交易稅
currency (string): 幣別 {NTD, USD, HKD, EUR, CAD, BAS}
direction (Action): 買賣別 {Buy, Sell}
entry_price (decimal): 進倉價格
cover_price (decimal): 平倉價格
pnl (decimal): 損益

已實現損益 - 彙總

用於查詢一段時間內的損益彙總。

In

var pfSumTotal = _api.ListProfitLossSummary(
        begin_date:"2021-03-01", 
        end_date:"2021-03-31", 
        account:_api.StockAccount
    );
Console.WriteLine(pfSumTotal);
var pfSumTotal = _api.ListProfitLossSummary(
        begin_date:"2022-10-19", 
        end_date:"2022-10-19" ,
        account:_api.FutureAccount
    );
Console.WriteLine(pfSumTotal);

Out

{
    profitloss_summary=
    [
        {
            entry_cost=111600, 
            cover_cost=108200, 
            buy_cost=111655, 
            sell_cost=107903, 
            pr_ratio=-3.36, 
            cond=Cash, 
            code=2338, 
            quantity=2000, 
            entry_price=55, 
            cover_price=54, 
            pnl=-3752, 
            currency=NTD
        },
    ], 
    total=
    {
        entry_amount=0, 
        cover_amount=0, 
        quantity=8000, 
        buy_cost=291092, 
        sell_cost=288172, 
        pnl=-2920.0, 
        pr_ratio=-1.0
    }
}
{
    profitloss_summary=
    [
        {
            direction=Buy, 
            tax=6, 
            fee=40, 
            code=TXO01350J2, 
            quantity=2, 
            entry_price=59, 
            cover_price=0, 
            pnl=-5950, 
            currency=NTD
        }, 
    ], 
    total=
    {
        entry_amount=0, 
        cover_amount=0, 
        quantity=2, 
        buy_cost=0, 
        sell_cost=0, 
        pnl=-5950.0, 
        pr_ratio=0.0
    }
}

Attributes:

code (string): 商品代碼
quantity (int): 數量
entry_price (int): 進倉價格
cover_price (int): 平倉價格
pnl (decimal): 損益
currency (string): 幣別
entry_cost (int): 進倉金額(不含手續費及交易稅)
cover_cost (int): 平倉金額(不含手續費及交易稅)
buy_cost (int): 付出成本
sell_cost (int): 賣出收入
pr_ratio (decimal): 損益比
cond (StockOrderCond): {
                Cash: 現股(預設值), 
                Netting: 餘額交割,
                MarginTrading: 融資, 
                ShortSelling: 融券, 
                Emerging: 興櫃
            }
code (string): 商品代碼
quantity (int): 數量
entry_price (int): 進倉價格
cover_price (int): 平倉價格
pnl (decimal): 損益
currency (string): 幣別
direction (Action): 買賣別 {Buy, Sell}
tax (int): 交易稅
fee (int): 交易手續費