【D12】发现新厨具:Snapshot

前言

有个Snapshot的功能,可以看当下的商品状况,让我们看看这个功能可以做啥吧!

参考网站:Snapshot

本日程序码使用:d12_snapshot.ipynb


取得资料

首先取得资料,看看资料内容是什麽,才能决定他可以做什麽事情。

  • 首先登入
# 登入shioaji
api = sj.Shioaji()
api.login(
    person_id="id是我",
    passwd="密码是我",
)

登入後,就使用api.snapshots(合约)取得snapshot,里面「合约」要存放的参数是之前探讨的合约-Contracts,。这次也是使用台积电(2330)的资料。

contract = [api.Contracts.Stocks['2330']]
snapshot = api.snapshots(contract)
snapshot

可以得到:

[Snapshot(ts=1632493800000000000, code='2330', exchange='TSE', open=591.0, high=598.0, low=590.0, close=598.0, tick_type=<TickType.Buy: 'Buy'>, change_price=10.0, change_rate=1.7, change_type=<ChangeType.Up: 'Up'>, average_price=594.7, volume=54, total_volume=16736, amount=32292000, total_amount=9952872854, yesterday_volume=21696.0, buy_price=597.0, buy_volume=41.0, sell_price=598.0, sell_volume=2, volume_ratio=0.77)]

当然也可以转换成dataframe,更好阅读也更好处理数据:

# 转换成dataframe
df = pandas.DataFrame(snapshot)

比对Yahoo资料与资料格式

来看一下他的栏位:

ts (int): TimeStamp.
code (str): Contract id.
exchange (Exchange): Attributes of industry.
open (float): open
high (float): high
low (float): low
close (float): close
tick_type (TickType): Close is buy or sell price.
    {None, Buy, Sell}
change_price (float): change price.
change_rate (float): change rate.
change_type (ChangeType):
    {LimitUp, Up, Unchanged, Dowm, LimitDown}
avgerage_price (float): avgerage of price.
volume (int): volume.
total_volume (int): total volume.
amount (int): Deal amount.
total_amount (int): Total deal amount.
yestoday_volume (float): Volume of yestoday.
buy_price (float): Price of buy.
buy_volume (float): Volume of sell.
sell_price (float): Price of sell.
sell_volume (int): Volume of sell.
volume_ratio (float): total_volume/yestoday_volume.

来跟Yahoo股票的资料比对9/24的资料,看看是否相同。

Yahoo的资料为:

开:591  高:598  低:590  收:598  量:16700  涨跌:10.00
  • 开高低收:取得的资料是open=591.0, high=598.0, low=590.0, close=598.0,资料相同。
  • 量为:total_volume=16736,实际上证交所提供的为「17,302,848」股,两者皆有落差。
  • 昨量也有落差,从API取得的yesterday_volume=21696.0,但实际上为「22,736,266」仍有不同。

结论

以这个snapshot来说,他是当下的状态,而例子中的timestamp为1632493800000000000,也就是Friday, September 24, 2021 2:30:00 PM零股的时间,但是数量又对不起来...

看来可以那个的准确度要观察,不过价格应该是可以使用。


<<:  Day12 - 祖父元件与孙子元件间的传音入密

>>:  D25 第十二周 (回忆篇)

Day 30 | 将flutter web 部署至 netlify

最後一天就来部署我们的flutter web吧,也算是这系列文中真的跟「web」唯一有关的一篇文XD...

Day28 - 云端交易主机 - GCP云端平台申请&架设(Windows)

云端交易主机 - GCP云端平台申请&架设(Windows) 考虑到大部分使用者仍然习惯 W...

[ Day 30 ] - 初学者升级啦~完赛心得

初学者升级啦 YA!30天了~代表我连续 30 天学习 JS 了!(拍手~) 第一次参加铁人赛,其实...

企业资料通讯Week6 (2) | P2P architecture

P2P architecture P2P(Peer-to-peer,点对点的传输),这是一个无中心服...

Day 20. 用 Figma 来设计基本 icon 吧!

Figma 的介面布局与一般的设计软件很类似,上方(1)为工具列,左方(2)可切换 Layer, P...