【D6】试用厨具:合约资料(Contracts)

前言

当可以登入後,我们首先要做的是取得商品资料,有商品才能做後续的交易,因此要取得商品或合约资讯。

本篇主要是参考文件:https://sinotrade.github.io/tutor/contract/


登入

首先登入,一样套用import shioaji as sj,并且登入,然後把可取得的商品资料印出。

# 载入shioaji套件
import shioaji as sj

# Initialization
api = sj.Shioaji()

# Login: (ID, password)
accounts = api.login(
    "注册的ID",
    "注册的密码",
    contracts_cb=lambda security_type: print(f"{repr(security_type)} fetch done."),
)

这边显示商品以及其代码:

<SecurityType.Index: 'IND'> fetch done.
<SecurityType.Future: 'FUT'> fetch done.
<SecurityType.Stock: 'STK'> fetch done.
<SecurityType.Option: 'OPT'> fetch done.

取得股票资讯

使用:api.Contracts,可以取得合约资讯,也就是商品的基本资料。这边後面接Stock,表示股票资讯,然後再用股票代码,就可以取得资讯。

contract_0050 = api.Contracts.Stocks["0050"]
print(contract_0050)

0050来说,可以取得商品代码、名称,涨跌最大树等等。

exchange=<Exchange.TSE: 'TSE'> code='0050' symbol='TSE0050' name='元大台湾50' category='00' unit=1000 limit_up=154.1 limit_down=126.1 reference=140.1 update_date='2021/09/17' margin_trading_balance=6478 day_trade=<DayTrade.Yes: 'Yes'>

资料型态

在股票中的资料型态为:

exchange (Exchange): Attributes of industry.
    {OES, OTC, TSE ...etc}
code (str): Id.
symbol (str): Symbol.
name (str): Name.
category (str): Category.
limit_up (float): Limit up.
limit_down (float): Limit down.
reference (float): Reference price.
update_date (str): Update date.
margin_trading_balance (int): Margin trading balance.
short_selling_balance (int): Short selling balance.
day_trade (DayTrade): Day trade.
    {Yes, No, OnlyBuy}

取得期货资讯

同样的api.Contracts,後面接Futures,接着就是期货的代码,这边会这样的格式:「期货代码」+「月份」+「年的个位数」。其中月份为1~12月的英文代码,分别从AL

contract_txf = api.Contracts.Futures["TXFJ1"]
print(contract_txf)

然後印出的结果如下:

code='TXFJ1' symbol='TXF202110' name='台股期货' category='TXF' delivery_month='202110' underlying_kind='I' unit=1 limit_up=19023.0 limit_down=15565.0 reference=17294.0 update_date='2021/09/18'

资料型态

在股票中的资料型态为:

code (str): Id.
symbol (str): Symbol.
name (str): Name.
category (str): Category.
limit_up (float): Limit up.
limit_down (float): Limit down.
reference (float): Reference price.
update_date (str): Update date.
delivery_month (str): Delivery Month.
underlying_kind (str): Underlying Kind.

<<:  Day 20 - Native Speech Recognition

>>:  [Day7] - Django 专案设定,创建 Django app

虹语岚访仲夏夜-27(打杂的Allen篇)

要说这小七学东西,就是快,还在测试中的系统,她只用了几个月,就学会了,还顺便自己POC了一遍,真是认...

【Day28】清除轨迹 ─ Windows篇(二)

哈罗~ 昨天我们介绍了Windows Event log, 今天要来试试看怎麽清除Windows的l...

D-27-变数 variable ? int ? string

认识变数 variable 在昨天的历程中小光学习到如何透过dotnet cli来产生专案跟方案,并...

[Day-21] 呼叫自订函式(二)

上次练习了基本的函式语法 今天要接续着练习 我上次宣告的函式是int型态的 所以不管怎样都会回传值给...

Day 23 dio函数库

昨天提到Flutter最常用的网路函数库有HttpClient和http函数库,但其实还有一种叫做d...