Beispiel #1
0
def run_tianqin_code(bid, user_id, pwd, td_url):
    api = TqApi(TqAccount(bid, user_id, pwd),
                auth="[email protected],MaYanQiong",
                _stock=True,
                _td_url=td_url,
                debug="c.log")
    is_ctp = False if bid == "快期模拟" else True
    account = api.get_account()
    if bid == "快期模拟":
        assert account.ctp_balance == '-' or math.isnan(account.ctp_balance)
        assert account.ctp_available == '-' or math.isnan(
            account.ctp_available)
    else:
        logger.info(f"{account.ctp_balance}, {account.ctp_available}")

    logger.info(f"{'='*30} 登录成功后,账户初始状态 {'='*30}")
    positions = api._data["trade"][user_id]["positions"]
    orders = api._data["trade"][user_id]["orders"]
    check_orders(orders, api, is_ctp)
    check_positions(positions, api, is_ctp)
    check_account(account, positions, is_ctp)
    check_risk_rule(api, None)
    check_risk_data(api, "SSE.10002504")

    api.set_risk_management_rule("SZSE", True)

    logger.info(f"{'='*12} 期权 开仓 {'='*12}")
    # quote = api.get_quote("SZSE.91000999")  # ETF 期权  SSE.10002504
    # print(quote)
    # 挂单
    # order = api.insert_order(symbol="SSE.10002504", direction="BUY", offset="OPEN", limit_price=quote.lower_limit + quote.price_tick, volume=2)
    # order = api.insert_order(symbol="SSE.10002504", direction="SELL", offset="OPEN", limit_price=quote.upper_limit - quote.price_tick, volume=2)
    # 可成交
    # order = api.insert_order(symbol="SSE.10002513", direction="BUY", offset="OPEN", limit_price=quote.ask_price1, volume=3)
    # 可成交 FAK 下单失败,CTP:交易所不支持的价格类型
    # order = api.insert_order(symbol="SSE.10002513", direction="BUY", offset="OPEN", limit_price=quote.ask_price1, volume=2, advanced="FAK")
    # 可成交 FOK
    # order = api.insert_order(symbol="SSE.10002513", direction="BUY", offset="OPEN", limit_price=quote.ask_price1, volume=2, advanced="FOK")

    # BEST
    order = api.insert_order(symbol="SZSE.91000999",
                             direction="BUY",
                             offset="OPEN",
                             limit_price="BEST",
                             volume=5)
    # BEST FOK 下单失败,已撤单报单被拒绝12038,合约代码:SSE.10002513,下单方向:买,开平标志:开仓,委托价格:最优价,委托手数:3
    # order = api.insert_order(symbol="SSE.10002513", direction="SELL", offset="CLOSE", limit_price="BEST", volume=3, advanced="FOK")

    # any_price 通知: 下单失败,CTP:交易所不支持的价格类型
    # order = api.insert_order(symbol="SSE.10002513", direction="BUY", offset="OPEN", volume=3)
    # FIVELEVEL 通知: 下单失败,CTP:交易所不支持的价格类型
    # order = api.insert_order(symbol="SSE.10002513", direction="BUY", offset="OPEN", limit_price="FIVELEVEL", volume=3)
    api.wait_update()
    # api.cancel_order(order)
    while order.status == "ALIVE":
        api.wait_update()
    check_all(api, bid, user_id)
    # check_risk_rule(api,None)
    check_risk_data(api, "SZSE.91000999")
    api.close()
from otg_check_helper import check_orders, check_positions, check_account, check_risk_rule, check_risk_data, check_all
from test_for_etf.base_info import bid, user_id, pwd, td_url, test_logger

if __name__ == '__main__':
    api = TqApi(TqAccount(bid, user_id, pwd),
                auth="ringo,Shinnytech123",
                _stock=True,
                _td_url=td_url)

    # 成交持仓比风控规则
    rule = api.set_risk_management_rule("SSE",
                                        True,
                                        trade_units_limit=6,
                                        trade_position_ratio_limit=150)

    test_logger.info(f"{'='*12} 期权 开仓 {'='*12}")
    symbol = "SSE.10002477"
    quote = api.get_quote(symbol)  # ETF 期权
    # 挂单
    buy_order = api.insert_order(symbol=symbol,
                                 direction="BUY",
                                 offset="OPEN",
                                 limit_price=quote.ask_price1,
                                 volume=10)
    while buy_order.status == "ALIVE":
        api.wait_update()
    check_all(api, bid, user_id)
    check_risk_rule(api, None)
    check_risk_data(api, symbol)
    api.close()
Beispiel #3
0
#!/usr/bin/env python
#  -*- coding: utf-8 -*-
"""
买开
"""

from tqsdk import TqApi, TqAccount

from otg_check_helper import check_orders, check_positions, check_account, check_risk_rule, check_risk_data
from test_for_etf.base_info import bid, user_id, pwd, td_url, test_logger

if __name__ == '__main__':
    api = TqApi(TqAccount(bid, user_id, pwd),
                url=td_url,
                auth="ringo,Shinnytech123")

    account = api.get_account()
    positions = api._data["trade"][api._account._account_id]["positions"]
    orders = api._data["trade"][api._account._account_id]["orders"]

    # 显示各种信息
    test_logger.info(f"{'=' * 30} 登录成功后,账户初始状态 {'=' * 30}")
    is_ctp = False if api._account._broker_id == "快期模拟" else True
    check_orders(orders, api, is_ctp)
    check_positions(positions, api, is_ctp)
    check_account(account, positions, is_ctp)
    check_risk_rule(api)
    check_risk_data(api)
    api.close()