QIFIAccount icon indicating copy to clipboard operation
QIFIAccount copied to clipboard

QAQIFIAccount 中A股交易的qapos的问题

Open zhongjyyy opened this issue 4 years ago • 1 comments

关于当日买入后, volume_frozen_today , volume_today 值问题

  1. 空仓建仓后应为
assert pos.volume_long_his == 0
assert pos.volume_long == amount
assert pos.volume_long_today == amount  # 此项源码作为结算使用
assert pos.volume_long_frozen_today == 0  # TODO 买入是否需要冻结?
  1. 当日空仓建仓后应无法卖出
r = acc.send_order(code, amount=amount, price=price, towards=ORDER_DIRECTION.BUY).copy()
acc.make_deal(r)
r1 = acc.send_order(code, amount=amount, price=price, towards=ORDER_DIRECTION.SELL).copy()
assert r1 == False  # 此处应为交易前置检查失败
acc.make_deal(r1)
  1. 测试源码
def test_sell():
    # 委托状态:委托全部成交
    code, price, amount = '000001', 10, 1000
    acc: QIFI_Account = QIFI_Account("x4", "x4")
    acc.initial()
    r = acc.send_order(code, amount=amount, price=price, towards=ORDER_DIRECTION.BUY).copy()
    acc.make_deal(r)
    pos: QA_Position = acc.positions.get(code)
    volume_his = pos.volume_long_his
    print("建仓买入", pos.hold_detail)
    assert pos.volume_long_his == 0
    assert pos.volume_long == amount
    assert pos.volume_long_today == amount
    assert pos.volume_long_frozen_today == 0  # TODO 买入是否需要冻结?
    if volume_his == 0:
        r = acc.send_order(code, amount=amount, price=price, towards=ORDER_DIRECTION.SELL).copy()
        print("卖出委托", r)
        assert r == False  # 此处应为交易前置检查失败
        if r:
            acc.make_deal(r)
        # {'volume_long_today': 0, 'volume_long_his': 0, 'volume_long': 1000, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'volume_long_frozen_today': 1000, 'volume_short_frozen_today': 0}
        print("卖出委托后", pos.hold_detail)
        assert pos.volume_long == amount
        assert pos.volume_long_today == amount
        assert pos.volume_long_frozen_today == 0  # TODO 买入是否需要冻结?
    acc.settle()
    print("结算后", pos.hold_detail)
    assert pos.volume_long == amount
    assert pos.volume_long_his == amount
    assert pos.volume_long_today == 0
    assert pos.volume_long_frozen_today == 0

zhongjyyy avatar Jul 05 '20 15:07 zhongjyyy

already fixed

yutiansut avatar Aug 25 '21 01:08 yutiansut