109 浏览
0

对于那些不区分CLOSE 和CLOSETODAY的交易所,即使是今天的仓位,是否都是显示在pos_short_his上的,而pos_short_today永远显示0?因为下面这个是今仓,但是显示pos_short_his是45,而交易所的volume_short_his却是0,反而volume_short_today是45。

{'exchange_id': 'DCE', 'instrument_id': 'cs2607', 'pos_long_his': 0, 'pos_long_today': 0, 'pos_short_his': 45, 'pos_short_today': 0, 'volume_long_today': 0, 'volume_long_his': 0, 'volume_long': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_today': 45, 'volume_short_his': 0, 'volume_short': 45, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'open_price_long': nan, 'open_price_short': 2666.5, 'open_cost_long': nan, 'open_cost_short': 1199925.0, 'position_price_long': nan, 'position_price_short': 2668.5, 'position_cost_long': 0.0, 'position_cost_short': 1200825.0, 'float_profit_long': nan, 'float_profit_short': -675.0, 'float_profit': -675.0, 'position_profit_long': 0.0, 'position_profit_short': 225.0, 'position_profit': 225.0, 'margin_long': nan, 'margin_short': 60480.0, 'margin': 60480.0, 'market_value_long': nan, 'market_value_short': nan, 'market_value': nan, 'pos': -45, 'pos_long': 0, 'pos_short': 45, 'user_id': '569003aa-985b-4e47-8474-8b587f2faa91', 'volume_long_yd': 0, 'volume_short_yd': 45, 'last_price': 2668.0}
chaos 已回答的问题 2天 前
0

不会,如果是今仓应该也在pos_short_today上,可以再测试一下或者给个最小复现问题的代码

zhupengyu97 编辑评论 2天 前

有其他问题欢迎加入官方Q群748265037一起交流

上面是昨天夜盘position字段,45分别显示在pos_short_his和volume_short_today上面。simnow模拟环境。所以交易所的volume字段永远不要相信对吗?还是只是simnow的问题?

昨天的夜盘也在今天的交易日,也算今仓,pos_short_today应该要显示今天的开仓,打印出来的信息看上去不符合预期

你可以用另个合约再重新开仓试试,看看表现是什么样

这里pos_long_his应该是对的,但是volume_long_today还是显示值。如果我按照volume long today关仓的话,就会影响关仓了。还是大家都直接不用closetoday,直接反向锁仓?或者能否明确pos_long_his/today肯定是对的,volume那个就是不要用吗?主要我担心有时候别pos_long_his/today也会出错?
CFFEX.TF2609: {‘exchange_id’: ‘CFFEX’, ‘instrument_id’: ‘TF2609’, ‘pos_long_his’: 14, ‘pos_long_today’: 0, ‘pos_short_his’: 0, ‘pos_short_today’: 0, ‘volume_long_today’: 14, ‘volume_long_his’: 0, ‘volume_long’: 14, ‘volume_long_frozen_today’: 0, ‘volume_long_frozen_his’: 0, ‘volume_long_frozen’: 0, ‘volume_short_today’: 0, ‘volume_short_his’: 0, ‘volume_short’: 0, ‘volume_short_frozen_today’: 0, ‘volume_short_frozen_his’: 0, ‘volume_short_frozen’: 0, ‘open_price_long’: 106.43, ‘open_price_short’: nan, ‘open_cost_long’: 14900200, ‘open_cost_short’: nan, ‘position_price_long’: 106.415, ‘position_price_short’: nan, ‘position_cost_long’: 14898100.000000002, ‘position_cost_short’: nan, ‘float_profit_long’: -8400, ‘float_profit_short’: nan, ‘float_profit’: -8400, ‘position_profit_long’: -6300.000000001863, ‘position_profit_short’: nan, ‘position_profit’: -6300.000000001863, ‘margin_long’: 327758.20000000007, ‘margin_short’: nan, ‘margin’: 327758.20000000007, ‘market_value_long’: nan, ‘market_value_short’: nan, ‘market_value’: nan, ‘pos’: 14, ‘pos_long’: 14, ‘pos_short’: 0, ‘last_price’: 106.37, ‘margin_long_his’: ‘-‘, ‘margin_long_today’: 327758.20000000007, ‘margin_short_his’: ‘-‘, ‘margin_short_today’: ‘-‘, ‘market_status’: 1, ‘open_cost_long_his’: ‘-‘, ‘open_cost_long_today’: 14900200, ‘open_cost_short_his’: ‘-‘, ‘open_cost_short_today’: ‘-‘, ‘position_cost_long_his’: ‘-‘, ‘position_cost_long_today’: 14898100.000000002, ‘position_cost_short_his’: ‘-‘, ‘position_cost_short_today’: ‘-‘, ‘user_id’: ‘265317’, ‘volume_long_yd’: 14, ‘volume_short_yd’: 0}

先一个问题一个问题来解决,第一个问题当天下单是会落在今仓的,你可以用下面代码测试

from tqsdk import TqApi, TqAuth, TqAccount

api = TqApi(TqAccount(“simnow”, “”, “”), auth=TqAuth(“”, “”))

symbol = “CFFEX.TF2612”
quote = api.get_quote(symbol)
position = api.get_position(symbol)

try:
# 等行情刷新出盘口价
while True:
api.wait_update()
if quote.ask_price1 == quote.ask_price1: # 过滤 nan
break

print(“下单前:”)
print(“long_today:”, position.pos_long_today, “long_his:”, position.pos_long_his)
print(“short_today:”, position.pos_short_today, “short_his:”, position.pos_short_his)

order = api.insert_order(
symbol=symbol,
direction=”BUY”,
offset=”OPEN”,
volume=1,
limit_price=quote.ask_price1
)

# 等订单结束
while True:
api.wait_update()

if api.is_changing(order):
print(“委托状态:”, order.status, “剩余:”, order.volume_left, “信息:”, order.last_msg)

if order.status == “FINISHED”:
break

# 等持仓刷新
while True:
api.wait_update()

if api.is_changing(position):
print(“下单后:”)
print(“pos_long_today:”, position.pos_long_today, “position.pos_long_his:”, position.pos_long_his)
print(“pos_short_today:”, position.pos_short_today, “pos_short_his:”, position.pos_short_his)
print(“volume_long_today:”, position.volume_long_today, “volume_long_his:”, position.volume_long_his)
print(“volume_short_today:”, position.volume_short_today, “volume_short_his:”, position.volume_short_his)
break

finally:
api.close()

您正在查看1个答案中的1个,单击此处查看所有答案。