Skip to main content

Sinopac All New Trading Api.

Project description

Shioaji

shioaji-logosinopac-logo

PyPI - Status PyPI - Python Version PyPI - Downloads Build - Status

Coverage Binder doc Gitter

Shioaji is sinopac provide the most pythonic api for trading the taiwan and global financial market. You can use your favorite Python packages such as numpy, scipy, pandas, pytorch or tensorflow to build your own trading model with intergrated the shioaji api on cross platform.

We are in early-release alpha. Expect some adventures and rough edges.

Installation

Binaries

simple using pip to install

pip install shioaji

Docker Image

simple run with interactive mode in docker

docker run -it sinotrade/shioaji:latest

run with jupyter lab or notebook

docker run -p 8888:8888 sinotrade/shioaji:jupyter

Getting Started

from datetime import date, timedelta
import pandas as pd

Just import Our api like other popular python library to get start

import shioaji as sj

Use Shioaji object to setup setting and login

sj.Shioaji?
Init signature: sj.Shioaji(backend='http', simulation=True, proxies={}, currency='NTD')
Docstring:    
shioaji api 

Functions:
    login 
    activate_ca
    list_accounts
    set_default_account
    get_account_margin 
    get_account_openposition
    get_account_settle_profitloss
    place_order
    update_order
    update_status
    list_trades

Objects:
    Contracts
    Order
Init docstring:
initialize Shioaji to start trading

Args:
    backend (str): {http, socket} 
        use http or socket as backend currently only support http, async socket backend coming soon.
    simulation (bool): 
        - False: to trading on real market (just use your Sinopac account to start trading)
        - True: become simulation account(need to contract as to open simulation account)
    proxies (dict): specific the proxies of your https
        ex: {'https': 'your-proxy-url'}
    currency (str): {NTX, USX, NTD, USD, HKD, EUR, JPY, GBP}
        set the default currency for display
File:           shioaji/shioaji.py
Type:           type
api = sj.Shioaji(backend='http', simulation=False)
api.login?
Signature: api.login(person_id, passwd)
Docstring:
login to trading server

Args:
    person_id (str): Same as your eleader, ileader login id(usually your person ID)
    passwd  (str): the password of your eleader login password(not ca password)
File:      shioaji/shioaji.py
Type:     method
person_id = 'SCCEIEFAJA'
api.login(person_id=person_id, passwd='2222')
api.fut_account
FutureAccount(person_id='SCCEIEFAJA', broker_id='F002000', account_id='9104000', username='莊*芬')

List all your account

api.list_accounts()
[Account(account_type='H', person_id='QCCAHIFFDH', broker_id='1300', account_id='09800762', username='n*m'),
 FutureAccount(person_id='SCCEIEFAJA', broker_id='F002000', account_id='9104000', username='莊*芬'),
 StockAccount(person_id='SCCEIEFAJA', broker_id='9A92', account_id='9802195', username='莊*芬')]

Set your default trading account

api.set_default_account(api.fut_account)

Activate your cetifacation to start ordering

api.activate_ca?
Signature: api.activate_ca(ca_path, ca_passwd, person_id)
Docstring:
activate your ca for trading

Args: 
    ca_path (str):
        the path of your ca, support both absloutely and relatively path, use same ca with eleader
    ca_passwd (str): password of your ca
    person_id (str): the ca belong which person ID
File:     shioaji/shioaji.py
Type:     method
api.activate_ca(ca_path='../ca/Sinopac.pfx', ca_passwd='SCCEIEFAJA', person_id=person_id)
Ca Initial Done.
0

Making Order object to place order

api.Order?
Init signature: api.Order(action, price_type, order_type, price, quantity, *args, **kwargs)
Docstring:     
The basic order object to place order

Attributes:
    product_id (str): the code of product that order to placing
    action (srt): {B, S}, order action to buy or sell
        - B: buy
        - S: sell
    price_type (str): {LMT, MKT, MKP}, pricing type of order
        - LMT: limit
        - MKT: market
        - MKP: market range
    order_type (str): {ROD, IOC, FOK}, the type of order
        - ROD: Rest of Day
        - IOC: Immediate-or-Cancel
        - FOK: Fill-or-Kill
    octype (str): {' ', '0', '1', '6'}, the type or order to open new position or close position 
        - ' ': auto
        - '0': new position
        - '1': close position
        - '6': day trade
    price (float or int): the price of order
    quantity (int): the quantity of order
    account (:obj:Account): which account to place this order
    ca (binary): the ca of this order
Init docstring:
the __init__ method of order

Args:
    product_id (str, optional): the code of product that order to placing 
                                if not provide will gen from contract when placing order 
    action (srt): {B, S}, order action to buy or sell
        - B: buy
        - S: sell
    price_type (str): {LMT, MKT, MKP}, pricing type of order
        - LMT: limit
        - MKT: market
        - MKP: market range
    order_type (str): {ROD, IOC, FOK}, the type of order
        - ROD: Rest of Day
        - IOC: Immediate-or-Cancel
        - FOK: Fill-or-Kill
    octype (str, optional): {' ', '0', '1', '6'}, the type or order 
                            to open new position or close position 
                            if not provide will become auto mode 
        - ' ': auto
        - '0': new position
        - '1': close position
        - '6': day trade
    price (float or int): the price of order
    quantity (int): the quantity of order
File:          shioaji/order.py
Type:          type

using tab to direct get all the Order properties with autocomplete

api.OrderProps.
shioaji.backend.http.order.Order_props
api.OrderProps.order_type.IOC
'IOC'

using tab to direct get avaliable trading product with Contracts

api.Contracts
Contracts(Futures=(BRF, CAF, CBF, CCF, CDF, CEF, CFF, CGF, CHF, CJ1, CJF, CKF, CLF, CM1, CMF, CNF, CQF, CRF, CSF, CUF, CWF, CXF, CYF, CZ1, CZF, DC1, DCF, DDF, DE1, DEF, DF1, DFF, DGF, DHF, DJF, DKF, DLF, DN1, DNF, DOF, DP1, DPF, DQF, DSF, DUF, DVF, DWF, DX1, DXF, DYF, DZ1, DZF, EEF, EGF, EHF, EMF, EPF, ERF, ESF, EXF, EY1, EYF, FF1, FFF, FGF, FKF, FQF, FRF, FTF, FVF, FWF, FXF, FYF, FZF, GAF, GBF, GCF, GDF, GHF, GIF, GJF, GLF, GMF, GNF, GOF, GPF, GRF, GTF, GUF, GWF, GXF, GZF, HAF, HBF, HCF, HHF, HIF, HLF, HMF, HOF, HS1, HSF, HY1, HYF, I5F, IA1, IAF, IHF, IIF, IJF, IMF, IOF, IPF, IQF, IRF, ITF, IVF, IXF, IYF, IZF, JBF, JDF, JFF, JGF, JIF, JNF, JPF, JSF, JWF, JZF, KAF, KCF, KDF, KFF, KG1, KGF, KIF, KKF, KLF, KOF, KPF, KSF, KWF, LBF, LCF, LIF, LMF, LO1, LOF, LQF, LRF, LTF, LUF, LV1, LVF, LWF, LX1, LXF, LZF, MAF, MBF, MCF, MEF, MIF, MJF, MKF, ML1, MPF, MQF, MVF, MXF, MYF, NAF, NBF, NCF, NDF, NEF, NGF, NHF, NI1, NIF, NJF, NLF, NMF, NNF, NOF, NQF, NSF, NTF, NUF, NVF, NWF, NXF, NYF, NZF, OAF, OBF, OCF, ODF, OEF, OFF, OGF, OHF, OJF, OKF, OLF, OMF, ONF, OOF, OPF, OQF, ORF, OSF, OTF, OUF, OVF, OWF, OXF, OYF, OZF, PAF, PBF, RHF, RTF, SPF, T5F, TGF, TJF, TXF, UDF, XAF, XBF, XEF, XIF, XJF), Options=(CAO, CBA, CBO, CCO, CDO, CEO, CFO, CGA, CGO, CHO, CJA, CJO, CKO, CLA, CLO, CMA, CMO, CNO, CQO, CRO, CSO, CXO, CZA, CZO, DCO, DEA, DEO, DFA, DFO, DGO, DHA, DHO, DJO, DKA, DKO, DLO, DNA, DNO, DOO, DPO, DQO, DSO, DUO, DVO, DWO, DXA, DXO, GIA, GIO, GTO, GXO, HCO, IJA, IJO, LOA, LOO, NYA, NYO, NZO, OAO, OBO, OCO, OJO, OKO, OOO, OZA, OZO, RHO, RTO, TEO, TFO, TGO, TXO, XIO))
api.Contracts.Futures
(BRF, CAF, CBF, CCF, CDF, CEF, CFF, CGF, CHF, CJ1, CJF, CKF, CLF, CM1, CMF, CNF, CQF, CRF, CSF, CUF, CWF, CXF, CYF, CZ1, CZF, DC1, DCF, DDF, DE1, DEF, DF1, DFF, DGF, DHF, DJF, DKF, DLF, DN1, DNF, DOF, DP1, DPF, DQF, DSF, DUF, DVF, DWF, DX1, DXF, DYF, DZ1, DZF, EEF, EGF, EHF, EMF, EPF, ERF, ESF, EXF, EY1, EYF, FF1, FFF, FGF, FKF, FQF, FRF, FTF, FVF, FWF, FXF, FYF, FZF, GAF, GBF, GCF, GDF, GHF, GIF, GJF, GLF, GMF, GNF, GOF, GPF, GRF, GTF, GUF, GWF, GXF, GZF, HAF, HBF, HCF, HHF, HIF, HLF, HMF, HOF, HS1, HSF, HY1, HYF, I5F, IA1, IAF, IHF, IIF, IJF, IMF, IOF, IPF, IQF, IRF, ITF, IVF, IXF, IYF, IZF, JBF, JDF, JFF, JGF, JIF, JNF, JPF, JSF, JWF, JZF, KAF, KCF, KDF, KFF, KG1, KGF, KIF, KKF, KLF, KOF, KPF, KSF, KWF, LBF, LCF, LIF, LMF, LO1, LOF, LQF, LRF, LTF, LUF, LV1, LVF, LWF, LX1, LXF, LZF, MAF, MBF, MCF, MEF, MIF, MJF, MKF, ML1, MPF, MQF, MVF, MXF, MYF, NAF, NBF, NCF, NDF, NEF, NGF, NHF, NI1, NIF, NJF, NLF, NMF, NNF, NOF, NQF, NSF, NTF, NUF, NVF, NWF, NXF, NYF, NZF, OAF, OBF, OCF, ODF, OEF, OFF, OGF, OHF, OJF, OKF, OLF, OMF, ONF, OOF, OPF, OQF, ORF, OSF, OTF, OUF, OVF, OWF, OXF, OYF, OZF, PAF, PBF, RHF, RTF, SPF, T5F, TGF, TJF, TXF, UDF, XAF, XBF, XEF, XIF, XJF)
api.Contracts.Futures.TXF
TXF(TXF201903, TXF201906, TXF201809, TXF201810, TXF201811, TXF201812)
api.Contracts.Futures.TXF.TXF201903
Future(symbol='TXF201903', code='TXFC9', name='台指期貨', category='TXF', delivery_month='201903', underlying_kind='I', underlying_code='#001', unit=1.0)
TXFR3 = api.Contracts.Futures.TXF.TXF201903
sample_order = api.Order(product_id=TXFR3.code, 
                         price=9600,
                         action=api.OrderProps.action.Buy,
                         price_type=api.OrderProps.price_type.LMT,
                         order_type=api.OrderProps.order_type.ROD,
                         octype=api.OrderProps.octype.auto,
                         quantity=5,
                         account=api.fut_account,
                        )
sample_order
Order(product_id='TXFC9', action='B', price_type='LMT', order_type='ROD', price=9600, quantity=5, account=FutureAccount(person_id='SCCEIEFAJA', broker_id='F002000', account_id='9104000', username='莊*芬')
print(api.LimitOrder.__init__.__doc__)
 LimitOrder

        Args:
            product_id (str, optional): the code of product that order to placing 
                                        if not provide will gen from contract when placing order 
            action (srt): {B, S}, order action to buy or sell
                - B: buy
                - S: sell
            price (float or int): the price of order
            quantity (int): the quantity of order
            order_type (str, optional): {ROD, IOC, FOK}, the type of order
                - ROD: Rest of Day
                - IOC: Immediate-or-Cancel
                - FOK: Fill-or-Kill
            octype (str, optional): {' ', '0', '1', '6'}, the type or order 
                                    to open new position or close position 
                                    if not provide will become auto mode 
                - ' ': auto
                - '0': new position
                - '1': close position
                - '6': day trade
sample_limit_order = api.LimitOrder('B', 9700, 5)
sample_limit_order
LimitOrder(action='B', order_type='ROD', price=9700, quantity=5)

Using LimitOrder, MarketOrder, etc.

print(api.MarketOrder.__init__.__doc__)
 MarketOrder

        Args:
            product_id (str, optional): the code of product that order to placing 
                                        if not provide will gen from contract when placing order 
            action (srt): {B, S}, order action to buy or sell
                - B: buy
                - S: sell
            quantity (int): the quantity of order
            order_type (str, optional): {IOC, FOK}, the type of order
                - IOC: Immediate-or-Cancel
                - FOK: Fill-or-Kill
            octype (str, optional): {' ', '0', '1', '6'}, the type or order 
                                    to open new position or close position 
                                    if not provide will become auto mode 
                - ' ': auto
                - '0': new position
                - '1': close position
                - '6': day trade
sample_mkt_order = api.MarketOrder('B', 5)
sample_mkt_order
MarketOrder(action='B', order_type='IOC', quantity=5)

just pass Order object to place_order fuction to place order then will get the Trade object return

trade = api.place_order(TXFR3, sample_order)
trade
Trade(contract=Future(symbol='TXF201903', code='TXFC9', name='台指期貨', category='TXF', delivery_month='201903', underlying_kind='I', underlying_code='#001', unit=1.0), order=Order(product_id='TXFC9', action='B', price_type='LMT', order_type='ROD', price=9600, quantity=5, account=FutureAccount(person_id='SCCEIEFAJA', broker_id='F002000', account_id='9104000', username='莊*芬')), status=OrderStatus(seqno='701124', order_id='7521840eb43914f94f98f025b1762e0b250ded21', status='PendingSubmit', order_datetime=datetime.datetime(2019, 1, 16, 12, 39, 28)))

Update the trade object status to get the trade information

api.update_status()
trade
Trade(contract=Future(symbol='TXF201903', code='TXFC9', name='台指期貨', category='TXF', delivery_month='201903', underlying_kind='I', underlying_code='#001', unit=1.0), order=Order(product_id='TXFC9', action='B', price_type='LMT', order_type='ROD', price=9600, quantity=5, account=FutureAccount(person_id='SCCEIEFAJA', broker_id='F002000', account_id='9104000', username='莊*芬')), status=OrderStatus(seqno='701124', ordno='ky00P', order_id='7521840eb43914f94f98f025b1762e0b250ded21', status='Submitted', status_code='0000', msg='ky00P', modified_price=9600.0, remaining=5, order_datetime=datetime.datetime(2019, 1, 16, 12, 39, 28)))

Modify price or qty of trade

trade = api.update_order(trade, price=9800, qty=1)
trade
Trade(contract=Future(symbol='TXF201903', code='TXFC9', name='台指期貨', category='TXF', delivery_month='201903', underlying_kind='I', underlying_code='#001', unit=1.0), order=Order(product_id='TXFC9', action='B', price_type='LMT', order_type='ROD', price=9600, quantity=5, account=FutureAccount(person_id='SCCEIEFAJA', broker_id='F002000', account_id='9104000', username='莊*芬')), status=OrderStatus(seqno='701124', ordno='ky00P', order_id='7521840eb43914f94f98f025b1762e0b250ded21', status='Submitted', status_code='0000', msg='ky00P', modified_price=9800.0, remaining=5, order_datetime=datetime.datetime(2019, 1, 16, 12, 39, 28)))

Quote Api

api.quote?
Type:        Quote
String form: <shioaji.backend.solace.quote.Quote object at 0x7fe4bba6d828>
File:        shioaji/backend/solace/quote.py
Docstring:  
Quote Api

Functions:
    set_callback
    set_event_callback
    subscribe 

Set event and quote callback

api.quote.set_callback?
Signature: api.quote.set_callback(func)
Docstring:
set quote callback

Args: 
    func (:function): func(topic: str, quote_msg: dict) -> int
        when receive quote will call this function to processed the msg
File:      shioaji/backend/solace/quote.py
Type:      method
api.quote.set_event_callback?
Signature: api.quote.set_event_callback(func)
Docstring:
set event callback

Args:
    func (:function): func(resp_code: int, event_code: int, event: str) -> None
        when event happend will call this function to deal with event
File:      shioaji/backend/solace/quote.py
Type:      method

Prepare your callback, now just keep it simple

@sj.on_quote
def quote_callback(topic, quote_msg):
    print(topic, quote_msg)

@sj.on_event
def event_callback(resp_code, event_code, event):
    print("Respone Code: {} | Event Code: {} | Event: {}".format(resp_code, event_code, event))
api.quote.set_callback(quote_callback)
api.quote.set_event_callback(event_callback)

Subscribe quote of the contract

api.quote.subscribe?
Signature: api.quote.subscribe(contract, quote_type='tick')
Docstring:
subscribe the quote of contract 

Args:
    contract (:obj:Shioaji.Contract): the contract you want to subscribe
    quote_type (str): {tick, bidask}
File:      shioaji/backend/solace/quote.py
Type:      method
TXFR1 = api.Contracts.Futures.TXF.TXF201903
TSE2330 = api.Contracts.Stocks.TSE.TSE2330
api.quote.subscribe(TXFR1)
api.quote.subscribe(TXFR1, quote_type='bidask')
api.quote.subscribe(TSE2330)
api.quote.subscribe(TSE2330, quote_type='bidask')
Respone Code: 200 | Event Code: 16 | Event: Subscribe or Unsubscribe ok
Respone Code: 200 | Event Code: 16 | Event: Subscribe or Unsubscribe ok
Respone Code: 200 | Event Code: 16 | Event: Subscribe or Unsubscribe ok
MKT/redisrd/TSE/2330 {'Close': [239.5], 'Time': '11:11:42.624718', 'VolSum': [12206], 'Volume': [5]}
QUT/redisrd/TSE/2330 {'AskPrice': [240.0, 240.5, 241.0, 241.5, 242.0], 'AskVolume': [1808, 1789, 1645, 582, 1170], 'BidPrice': [239.5, 239.0, 238.5, 238.0, 237.5], 'BidVolume': [204, 765, 389, 475, 359], 'Date': '2019/03/18', 'Time': '11:11:42.624718'}
L/TFE/TXFC9 {'Amount': [10466.0], 'AmountSum': [631295113.0], 'AvgPrice': [10465.247302024103], 'Close': [10466.0], 'Code': 'TXFC9', 'Date': '2019/03/18', 'DiffPrice': [53.0], 'DiffRate': [0.508979160664554], 'DiffType': [2], 'High': [10474.0], 'Low': [10420.0], 'Open': 10437.0, 'TargetKindPrice': 10476.09, 'TickType': [2], 'Time': '11:11:44.457000', 'TradeAskVolSum': 29697, 'TradeBidVolSum': 27732, 'VolSum': [60323], 'Volume': [1]}
MKT/redisrd/TSE/2330 {'Close': [240.0], 'Time': '11:11:47.643968', 'VolSum': [12208], 'Volume': [2]}
QUT/redisrd/TSE/2330 {'AskPrice': [240.0, 240.5, 241.0, 241.5, 242.0], 'AskVolume': [1807, 1791, 1645, 582, 1170], 'BidPrice': [239.5, 239.0, 238.5, 238.0, 237.5], 'BidVolume': [207, 763, 389, 475, 359], 'Date': '2019/03/18', 'Time': '11:11:47.643968'}

Account & Portfolio

Account Margin

api.get_account_margin?
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 : 風險
account_margin = api.get_account_margin()
account_margin
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

directly pass our AccountMargin object to pandas to using your model

df_margin = pd.DataFrame([{**account_margin}])
df_margin
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 207000.0 0.0 0.0 207000.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

Get Open Position

api.get_account_openposition?
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
positions = api.get_account_openposition(query_type='1', account=api.fut_account)
positions
AccountOpenPosition
df_positions = pd.DataFrame(positions.data())
df_positions
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

Get Settle ProfitLoss

api.get_account_settle_profitloss?
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: 基幣
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
AccountSettleProfitLoss
df_profitloss = pd.DataFrame(settle_profitloss.data())
df_profitloss
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

Communication

Gitter

  • Gitter: general chat, online discussions, collaboration etc.
  • GitHub issues: bug reports, feature requests, install issues, RFCs, thoughts, etc.

Releases and Contributing

Shioaji current state is Pre-Alpha, we expect no obvious bugs. Please let us know if you encounter a bug by filing an issue.

We appreciate all suggestions. If you have any idea want us to implement, please discuss with us in gitter.

The Team

Shioaji is currently maintained by Yvictor, TK Huang, Sky Wu and Po Chien Yang with major contributions.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

shioaji-0.0.5.dev5-cp37-cp37m-win_amd64.whl (1.7 MB view hashes)

Uploaded CPython 3.7m Windows x86-64

shioaji-0.0.5.dev5-cp37-cp37m-manylinux1_x86_64.whl (3.9 MB view hashes)

Uploaded CPython 3.7m

shioaji-0.0.5.dev5-cp36-cp36m-win_amd64.whl (1.7 MB view hashes)

Uploaded CPython 3.6m Windows x86-64

shioaji-0.0.5.dev5-cp36-cp36m-manylinux1_x86_64.whl (3.9 MB view hashes)

Uploaded CPython 3.6m

shioaji-0.0.5.dev5-cp35-cp35m-win_amd64.whl (1.8 MB view hashes)

Uploaded CPython 3.5m Windows x86-64

shioaji-0.0.5.dev5-cp35-cp35m-manylinux1_x86_64.whl (3.8 MB view hashes)

Uploaded CPython 3.5m

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page