{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import shioaji as sj" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "api = sj.Shioaji(simulation=False)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "person_id = 'your person id'\n", "passwd = 'your password'" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "api.login(person_id, passwd)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "@sj.on_quote\n", "def on_quote(topic, quote_dict):\n", " print(topic, quote_dict)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "api.quote.set_callback(on_quote)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Contracts(Stocks=(OTC, TSE), Futures=(BRF, CAF, CBF, CCF, CDF, CEF, CFF, CGF, CHF, CJF, CKF, CLF, CMF, CNF, CQF, CRF, CSF, CUF, CWF, CXF, CYF, CZ1, CZ2, CZF, DCF, DD1, DDF, DEF, DFF, DGF, DH1, DHF, DIF, DJF, DKF, DLF, DNF, DOF, DPF, DQF, DSF, DUF, DVF, DWF, DXF, DYF, DZF, EEF, EGF, EHF, EMF, EPF, ERF, EXF, EYF, FEF, FFF, FGF, FKF, FQF, FRF, FTF, FVF, FWF, FXF, FYF, FZF, GAF, GBF, GCF, GDF, GHF, GIF, GJF, GLF, GMF, GNF, GOF, GRF, GTF, GUF, GWF, GXF, GZF, HAF, HBF, HCF, HHF, HIF, HLF, HOF, HS1, HSF, HYF, I5F, IA1, IAF, IHF, IIF, IJF, IMF, INF, IOF, IPF, IQF, IRF, ITF, IVF, IXF, IYF, IZF, JBF, JFF, JIF, JNF, JPF, JSF, JWF, JZF, KAF, KCF, KDF, KFF, KGF, KIF, KKF, KLF, KOF, KPF, KSF, KWF, LBF, LCF, LEF, LIF, LMF, LOF, LQF, LRF, LTF, LUF, LVF, LWF, LXF, MAF, MBF, MCF, MEF, MIF, MJF, MKF, MPF, MQF, MVF, MXF, MYF, NAF, NBF, NCF, NDF, NEF, NGF, NHF, NIF, NJF, NLF, NMF, NNF, NOF, NQF, NSF, NTF, NUF, NVF, NWF, NXF, NYF, NZF, OAF, OBF, OCF, ODF, OEF, OGF, OHF, OJF, OKF, OLF, OMF, OOF, OPF, OQF, ORF, OSF, OTF, OUF, OVF, OWF, OXF, OYF, OZF, PAF, PBF, PCF, PDF, PEF, PFF, PGF, PHF, PIF, RHF, RTF, SPF, T5F, TGF, TJF, TXF, UDF, XAF, XBF, XEF, XIF, XJF), Options=(CAO, CBO, CCO, CDO, CEO, CFO, CGO, CHO, CJO, CKO, CLO, CMO, CNO, CQO, CRO, CSO, CXO, CZO, DCO, DEO, DFO, DGO, DHO, DJO, DKO, DLO, DNO, DOO, DPO, DQO, DSO, DUO, DVO, DWO, DXO, GIO, GTO, GXO, HCO, IJO, LOO, NYO, NZO, OAO, OBO, OCO, OJO, OKO, OOO, OZO, RHO, RTO, TEO, TFO, TGO, TXO, XIO))" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "api.Contracts" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(CAO, CBO, CCO, CDO, CEO, CFO, CGO, CHO, CJO, CKO, CLO, CMO, CNO, CQO, CRO, CSO, CXO, CZO, DCO, DEO, DFO, DGO, DHO, DJO, DKO, DLO, DNO, DOO, DPO, DQO, DSO, DUO, DVO, DWO, DXO, GIO, GTO, GXO, HCO, IJO, LOO, NYO, NZO, OAO, OBO, OCO, OJO, OKO, OOO, OZO, RHO, RTO, TEO, TFO, TGO, TXO, XIO)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "api.Contracts.Options" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Option(symbol='TXO201904W2C10800', code='TX210800D9', name='W2週台選', category='TXO', delivery_month='201904W2', strike_price='10800.0', option_right='C', underlying_kind='I', underlying_code='#001', unit=0.1)" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "api.Contracts.Options.TXO.TXO201904W2C10800" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "TXO10800Cw2 = api.Contracts.Options.TXO.TXO201904W2C10800" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "L/OPT/TX210800D9 {'Amount': [36.5], 'AmountSum': [103012.0], 'AvgPrice': [37.14821492967905], 'Close': [36.5], 'Code': 'TX210800D9', 'Date': '2019/04/08', 'DiffPrice': [4.5], 'DiffRate': [14.0625], 'DiffType': [2], 'High': [39.5], 'Low': [34.0], 'Open': 36.0, 'TargetKindPrice': 10800.57, 'TickType': [2], 'Time': '20:09:31.813000', 'TradeAskVolSum': 722, 'TradeBidVolSum': 764, 'VolSum': [2773], 'Volume': [1]}\n" ] } ], "source": [ "api.quote.subscribe(TXO10800Cw2)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TXF(TXF202003, TXF201904, TXF201905, TXF201906, TXF201909, TXF201912)" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "api.Contracts.Futures.TXF" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Future(symbol='TXF201904', code='TXFD9', name='台指期貨', category='TXF', delivery_month='201904', underlying_kind='I', underlying_code='#001', unit=1.0)" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "api.Contracts.Futures.TXF.TXF201904" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "TXF1 = api.Contracts.Futures.TXF.TXF201904" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "L/TFE/TXFD9 {'Amount': [10781.0], 'AmountSum': [46010010.0], 'AvgPrice': [10782.753691117881], 'Close': [10781.0], 'Code': 'TXFD9', 'Date': '2019/04/08', 'DiffPrice': [11.0], 'DiffRate': [0.1021355617455896], 'DiffType': [2], 'High': [10789.0], 'Low': [10776.0], 'Open': 10782.0, 'TargetKindPrice': 10800.57, 'TickType': [1], 'Time': '20:10:00.491000', 'TradeAskVolSum': 2464, 'TradeBidVolSum': 2320, 'VolSum': [4267], 'Volume': [1]}\n", "L/OPT/TX210800D9 {'Amount': [74.0], 'AmountSum': [103086.0], 'AvgPrice': [37.14810810810811], 'Close': [37.0], 'Code': 'TX210800D9', 'Date': '2019/04/08', 'DiffPrice': [5.0], 'DiffRate': [15.625], 'DiffType': [2], 'High': [39.5], 'Low': [34.0], 'Open': 36.0, 'TargetKindPrice': 10800.57, 'TickType': [1], 'Time': '20:10:00.693000', 'TradeAskVolSum': 723, 'TradeBidVolSum': 765, 'VolSum': [2775], 'Volume': [2]}\n", "L/TFE/TXFD9 {'Amount': [10782.0], 'AmountSum': [46020792.0], 'AvgPrice': [10782.75351452671], 'Close': [10782.0], 'Code': 'TXFD9', 'Date': '2019/04/08', 'DiffPrice': [12.0], 'DiffRate': [0.11142061281337047], 'DiffType': [2], 'High': [10789.0], 'Low': [10776.0], 'Open': 10782.0, 'TargetKindPrice': 10800.57, 'TickType': [1], 'Time': '20:10:10.305000', 'TradeAskVolSum': 2465, 'TradeBidVolSum': 2321, 'VolSum': [4268], 'Volume': [1]}\n", "L/TFE/TXFD9 {'Amount': [10782.0], 'AmountSum': [46031574.0], 'AvgPrice': [10782.75333801827], 'Close': [10782.0], 'Code': 'TXFD9', 'Date': '2019/04/08', 'DiffPrice': [12.0], 'DiffRate': [0.11142061281337047], 'DiffType': [2], 'High': [10789.0], 'Low': [10776.0], 'Open': 10782.0, 'TargetKindPrice': 10800.57, 'TickType': [1], 'Time': '20:10:10.305000', 'TradeAskVolSum': 2466, 'TradeBidVolSum': 2322, 'VolSum': [4269], 'Volume': [1]}\n", "L/TFE/TXFD9 {'Amount': [21564.0], 'AmountSum': [46053138.0], 'AvgPrice': [10782.752985249355], 'Close': [10782.0], 'Code': 'TXFD9', 'Date': '2019/04/08', 'DiffPrice': [12.0], 'DiffRate': [0.11142061281337047], 'DiffType': [2], 'High': [10789.0], 'Low': [10776.0], 'Open': 10782.0, 'TargetKindPrice': 10800.57, 'TickType': [1], 'Time': '20:10:10.403000', 'TradeAskVolSum': 2468, 'TradeBidVolSum': 2323, 'VolSum': [4271], 'Volume': [2]}\n", "L/TFE/TXFD9 {'Amount': [10782.0], 'AmountSum': [46063920.0], 'AvgPrice': [10782.752808988764], 'Close': [10782.0], 'Code': 'TXFD9', 'Date': '2019/04/08', 'DiffPrice': [12.0], 'DiffRate': [0.11142061281337047], 'DiffType': [2], 'High': [10789.0], 'Low': [10776.0], 'Open': 10782.0, 'TargetKindPrice': 10800.57, 'TickType': [2], 'Time': '20:10:11.238000', 'TradeAskVolSum': 2469, 'TradeBidVolSum': 2324, 'VolSum': [4272], 'Volume': [1]}\n" ] } ], "source": [ "api.quote.subscribe(TXF1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.2" } }, "nbformat": 4, "nbformat_minor": 2 }