Account

account

下單ok後接著看帳務部分,帳務部份我們為了方便的與python的ecosystem結合,我們製作了將帳務的物件快速地轉換,就可以直接地變成pandas的Dataframe方便各位與自己的機器學習或深度學習模型直接介接。

權益數帳務

input

api.get_account_margin?

output

Signature: api.get_account_margin(currency='NTD', margin_type='1', account={})
Docstring:
query margin    currency: {NTX, USX, NTD, USD, HKD, EUR, JPY, GBP}
the margin calculate in which currency
    - NTX: 約當台幣
    - USX: 約當美金
    - NTD: 新台幣
    - USD: 美元
    - HKD: 港幣
    - EUR: 歐元
    - JPY: 日幣
    - GBP: 英鎊
margin_type: {'1', '2'}
    query margin type
    - 1 : 即時
    - 2 : 風險

input

account_margin = api.get_account_margin()
account_margin

output

AccountMargin
    Currency: NTD
    Account: F0020009104000
    Detail:
        OrderPSecurity: 207000.0
        ProfitAccCount: 207000.0
        FProfit: 0.0
        FMissConProfit: 0.0
        OMissConProfit: 0.0
        OColse: 0.0
        OMarketPrice: 0.0
        OTodayDiff: 0.0
        HandCharge: 0.0
        TradeTax: 0.0
        Security: 0.0
        StartSecurity: 0.0
        UpKeepSecurity: 0.0
        Statistics: 99999.0
        Flow: 999.0
        orderBid: 0.0
        orderAsk: 0.0
        Conclusionbid: 0.0
        Conclusionask: 0.0
        YesterdayBalance: 207000.0
        PayMoney: 0.0
        Equity: 207000.0
        Ogain: 0.0
        exrate: 1.0
        xgdamt: 0.0
        agtamt: 0.0
        YesterdayEquity: 207000.0
        Munet: 0.0
        Cashamt: 207000.0
        Bapamt: 0.0
        Sapamt: 0.0
        Adps: 0.0
        Adamt: 0.0
        Ybaln: 207000.0

直接用將物件傳入pandas.DataFrame就可以簡單的拿到常用的dataframe了

input

df_margin = pd.DataFrame([{**account_margin}])
df_margin

output

Adamt Adps Bapamt Cashamt Conclusionask Conclusionbid Equity FMissConProfit FProfit Flow TradeTax UpKeepSecurity Ybaln YesterdayBalance YesterdayEquity agtamt exrate orderAsk orderBid xgdamt
0 0.0 0.0 0.0 288000.0 0.0 0.0 288000.0 0.0 0.0 999.0 0.0 0.0 207000.0 207000.0 207000.0 0.0 1.0 0.0 0.0 0.0

1 rows × 34 columns

未平倉帳務

input

api.get_account_openposition?

output

Signature: api.get_account_openposition(product_type='0', query_type='0', account={})
Docstring:
query open position
product_type: {0, 1, 2, 3}
    filter product type of open position
    - 0: all
    - 1: future
    - 2: option
    - 3: usd base
query_type: {0, 1}
    query return with detail or summary
    - 0: detail
    - 1: summary

input

positions = api.get_account_openposition(query_type='1', account=api.fut_account)
positions

output

AccountOpenPosition

轉換成dataframe

input

df_positions = pd.DataFrame(positions.data())
df_positions

output

Account Code CodeName ContractAverPrice Currency Date FlowProfitLoss MTAMT OTAMT OrderBS OrderNum OrderType RealPrice SettlePrice SettleProfitLoss StartSecurity UpKeepSecurity Volume paddingByte
0 FF0020009104000 TXFA9 台指期貨 01 9508.4137 NTD 00000000 4795201.620000 6438000.000000 8352000.000000 B 9784.0 9784.00 4795201.620000 8352000.000000 6438000.000000 87.000000
1 FF0020009104000 XJFF9 日圓期貨 06 80.0000 JPY 00000000 31400.000000 47000.000000 61000.000000 B 0.0 81.57 31400.000000 61000.000000 47000.000000 1.000000
2 FF0020009104000 TXO08000L8 台指選擇權 8000 C 12 1870.0000 NTD 00000000 -14000.000000 0.000000 0.000000 B 1730.0 1810.00 -6000.000000 0.000000 0.000000 2.000000
3 FF0020009104000 TXO09200L8 台指選擇權 9200 C 12 720.0000 NTD 00000000 11250.000000 147000.000000 162000.000000 S 645.0 660.00 9000.000000 162000.000000 147000.000000 3.000000
4 FF0020009104000 TXO09400X8 台指選擇權 9400 P 12 199.0000 NTD 00000000 21200.000000 57600.000000 65600.000000 S 93.0 93.00 21200.000000 65600.000000 57600.000000 4.000000
5 FF0020009104000 TXO10200L8 台指選擇權 10200 C 12 111.0000 NTD 00000000 33550.000000 125950.000000 147950.000000 S 50.0 50.00 33550.000000 147950.000000 125950.000000 11.000000

平倉損益

input

api.get_account_settle_profitloss?

output

    Signature: api.get_account_settle_profitloss(product_type='0', summary='Y', start_date='', end_date='', currency='', account={})
    Docstring:
    query settlement profit loss
    product_type: {0, 1, 2}
        filter product type of open position
        - 0: all
        - 1: future
        - 2: option
    summary: {Y, N}
        query return with detail or summary
        - Y: summary
        - N: detail
    start_date: str
        the start date of query range format with %Y%m%d
        ex: 20180101
    end_date: str
        the end date of query range format with %Y%m%d
        ex: 20180201
    currency: {NTD, USD, HKD, EUR, CAD, BAS}
        the profit loss calculate in which currency
        - NTD: 新台幣
        - USD: 美元
        - HKD: 港幣
        - EUR: 歐元
        - CAD: 加幣 
        - BAS: 基幣

input

st_date = (date.today() - timedelta(days=60)).strftime('%Y%m%d')
settle_profitloss = api.get_account_settle_profitloss(summary='Y', start_date=st_date)
settle_profitloss

output

AccountSettleProfitLoss

轉換成dataframe

input

df_profitloss = pd.DataFrame(settle_profitloss.data())
df_profitloss

output

account averagePrice code codeName currency floatProfitLoss handCharge ord_bs ord_type ordno ordno_b settleAvgPrc settleDate settleVolume tFlag tdate tradeProfitLoss tradeTax unVolume volume
0 F0020009104000 9900.0 TXFK8 台指期貨 11 NTD 460.000000 60.000000 S 00 kY002 kY003 9897.0 20181022 1.000000 1 20181022 600.000000 80.000000 0.000000 1.000000