开个六给他,让他赢庄家一百块 - 根据五档报价之期货买卖

原本想要实作根据五档挂买卖下单,发现 snapshots 没有五档买卖价格

假如我今天就是想挂某一档价格的话怎麽办呢?

这样的下单没有价格根据,只好用 streaming marketing data 的 BidAsk


api.quote.subscribe(
    api.Contracts.Futures.TXF['TXF202107'],
    quote_type = sj.constant.QuoteType.BidAsk, # or 'bidask'
    version = sj.constant.QuoteVersion.v1 # or 'v1'
)

回传结果为


Response Code: 200 | Event Code: 16 | Info: QUO/v1/FOP/*/TFE/TXFG1 | Event: Subscribe or Unsubscribe ok

Exchange.TAIFEX 
BidAsk(
    code = 'TXFG1', 
    datetime = datetime.datetime(2021, 7, 1, 10, 51, 31, 999000), 
    bid_total_vol = 66,  # total bid volume (lot, 买量总计)
    ask_total_vol = 101,  # total ask volume (lot, 卖量总计)
    bid_price = [Decimal('17746'), Decimal('17745'), Decimal('17744'), Decimal('17743'), Decimal('17742')], 
    bid_volume = [1, 14, 19, 17, 15], 
    diff_bid_vol = [0, 1, 0, 0, 0],  # (lot, 买价增减量)
    ask_price = [Decimal('17747'), Decimal('17748'), Decimal('17749'), Decimal('17750'), Decimal('17751')], 
    ask_volume = [6, 22, 25, 32, 16], 
    diff_ask_vol = [0, 0, 0, 0, 0],  # (lot, 卖价增减量)
    first_derived_bid_price = Decimal('17743'),  # first derived bid price (衍生一档买价)
    first_derived_ask_price = Decimal('17751'),  # first derived ask price (衍生一档卖价)
    first_derived_bid_vol = 1,  # first derived bid volume (衍生一档买量)
    first_derived_ask_vol = 1,  # first derived bid volume (衍生一档卖量)
    underlying_price = Decimal('17827.94'),  # underlying price (标的物价格)
    simtrade = 0
)

想到简单的做法为先订阅五档报价之後挑选一档下单,这里的作法是挂买盘的第二档,也就是口数14口的17745 quote['BidPrice'][1]

买盘
bid_price = [Decimal('17746'), Decimal('17745'), Decimal('17744'), Decimal('17743'), Decimal('17742')]

卖盘
ask_price = [Decimal('17747'), Decimal('17748'), Decimal('17749'), Decimal('17750'), Decimal('17751')]

口数 委买(bid) 委卖(ask) 口数
----- ----- 17751 16
----- ----- 17750 32
----- ----- 17749 25
----- ----- 17748 22
----- ----- 17747 6
1 17746 ----- -----
14 17745 ----- -----
19 17744 ----- -----
17 17743 ----- -----
15 17742 ----- -----
import time

for i in range(0,1):

    api.quote.subscribe(api.Contracts.Futures.TXF.TXF202110, quote_type=shioaji.constant.QuoteType.BidAsk)

    @api.quote.on_quote
    def quote_callback(topic: str, quote: dict):
        print(f"Topic: {topic}, Quote: {quote}")
        order = api.Order(action=shioaji.constant.Action.Buy,
                  price=quote['BidPrice'][1],
                  quantity=1,
                  price_type=shioaji.constant.StockPriceType.LMT,
                  order_type=shioaji.constant.FuturesOrderType.ROD, 
                  octype=shioaji.constant.FuturesOCType.Auto,
                  account=api.futopt_account)
        print(order)

    time.sleep(1)

    api.quote.unsubscribe(api.Contracts.Futures.TXF.TXF202110, quote_type=shioaji.constant.QuoteType.BidAsk)

回传结果


Topic: Q/TFE/TXFJ1, Quote: {'AskPrice': [16929.0, 16930.0, 16931.0, 16932.0, 16933.0], 'AskVolSum': 47, 'AskVolume': [1, 6, 13, 16, 11], 'BidPrice': [16928.0, 16927.0, 16926.0, 16925.0, 16924.0], 'BidVolSum': 50, 'BidVolume': [5, 9, 14, 10, 12], 'Code': 'TXFJ1', 'Date': '', 'DiffAskVol': [0, 0, 0, 0, 0], 'DiffAskVolSum': 0, 'DiffBidVol': [1, 0, 5, -5, 0], 'DiffBidVolSum': 0, 'FirstDerivedAskPrice': 0.0, 'FirstDerivedAskVolume': 0, 'FirstDerivedBidPrice': 0.0, 'FirstDerivedBidVolume': 0, 'TargetKindPrice': 17181.44, 'Time': '23:55:13.064000'}
action=<Action.Buy: 'Buy'> price=16930.0 quantity=1 account=FutureAccount(person_id='', broker_id='', account_id='', signed=True, username='') price_type=<StockPriceType.LMT: 'LMT'> order_type=<FuturesOrderType.ROD: 'ROD'>

接下来送出订单就可以等看看是否交易成功了


<<:  D27 第十四周 (回忆篇)

>>:  Day13 Composition(组合) vs Inheritance (继承)

Day 27 : Python - 什麽是列表推导式?又该如何将它和if、if-else一起做使用?

如标题,这篇想和大家聊聊「列表推导式」是什麽东西 我们先看看范例再说明,这样大家会比较好理解 Ex ...

[第15天]理财达人Mx. Ada-持仓部位(库存)(positions)

前言 本文说明持仓部位(库存)(positions)资讯。 程序实作 程序 positions =a...

Day02-制作Line Bot 前置作业(注册Line Developers帐号

要将自己的聊天机器人发布在Line这个平台之前,我们需要有Line开发者(Line Develope...

[DAY 05]物品拍卖价格查询功能(3/4)

接续昨天要做的功能,我们要在discord上直接输入中文就能查询到物品的拍卖价格网址,今天主要是介绍...

#11 CSS3 Flexbox: RWD

How do RWD control columns displaying on devices o...