举例,比如螺纹钢
当价格超过3800的时候,TargetPosTask设置,建立10手,做多,目标是希望能够建仓价格控制在3800最好
问题:
核心问题:TargetPosTask的建仓优先级是否是首先满足建仓手数,然后才是价格
1、“PASSIVE”的设置下,建仓机制是如何的,比如现在买一价格是3799,卖一价格是3801,超过3800,是否此时下单的价格就是3799,如果不能成交,那么多久会撤单,又如何下单?如何这个时候行情猛拉,会否不断撤单,挂单,然后随着行情的上升,最终建仓价格也可能提升很多,高过3800很多,会否有这样的情况
2、“ACTIVE”下,也是如此,极端情况下,如何行情猛拉,我是想买,这个时候ACTIVE是下的价格是对价卖一价格,还是直接下涨停价格?如何是涨停价格,当手数过大的时候,会否把上面的单子自己吃了,然后自己把价格拉了上去
问题较细,多谢耐心解答哈,谢谢
appleman4000 已回答的问题 2022年9月29日
使用insert_order完成下单,如果价格远离5跳以上则停止下单,包含大单拆分小单功能
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | lots = 200 min_volume = 20 max_volume = 100 # 开多单 init_price = quote.ask_price1 while position.pos_long < lots: if quote.ask_price1 > = init_price + 5 * quote.price_tick: break if lots - position.pos_long > max_volume: lot = random.randint(min_volume, max_volume) else : lot = lots - position.pos_long limit_price = quote.ask_price1 order = api.insert_order(symbol = underlying_symbol, direction = 'BUY' , offset = 'OPEN' , volume = lot, limit_price = limit_price) print (quote.datetime, end = ' ' ) print ( '开多单(' + str (lot) + '手)' , end = ' ' ) print (limit_price) while order.status ! = 'FINISHED' : api.wait_update() if order.insert_date_time = = 0 : continue if api.is_changing(quote, [ 'ask_price1' ]) and \ quote.ask_price1 > order.limit_price + 2 * quote.price_tick: api.cancel_order(order) if order.volume_orign - order.volume_left > 0 : print (quote.datetime, end = ' ' ) print ( '已成交(' + str (order.volume_orign - order.volume_left) + '手),共' + str (position.pos_long) + '手' , end = ' ' ) print (order.trade_price) # 开空单 init_price = quote.bid_price1 while position.pos_short < lots: if quote.bid_price1 < = init_price - 5 * quote.price_tick: break if lots - position.pos_short > max_volume: lot = random.randint(min_volume, max_volume) else : lot = lots - position.pos_short limit_price = quote.bid_price1 order = api.insert_order(symbol = underlying_symbol, direction = 'SELL' , offset = 'OPEN' , volume = lot, limit_price = limit_price) current = datetime.datetime.fromtimestamp(klines_30m.datetime.iloc[ - 1 ] / 1e9 ) print (quote.datetime, end = ' ' ) print ( '开空单(' + str (lot) + '手)' , end = ' ' ) print (limit_price) while order.status ! = 'FINISHED' : api.wait_update() if order.insert_date_time = = 0 : continue if api.is_changing(quote, [ 'bid_price1' ]) and \ quote.bid_price1 < order.limit_price - 2 * quote.price_tick: api.cancel_order(order) if order.volume_orign - order.volume_left > 0 : print (quote.datetime, end = ' ' ) print ( '已成交(' + str (order.volume_orign - order.volume_left) + '手),共' + str (position.pos_short) + '手' , end = ' ' ) print (order.trade_price) |
tfintech2022 发表新评论 2022年10月2日
感谢解答,这个代码是对targetpos的功能替代,还是其内在运作的逻辑解释,因为在api中我没有找到targetpos的内在运作逻辑,所以问的比较细致