示例#1
0
if __name__ == '__main__':
    data = pd.read_excel(io_in, sheet_name=0, converters={'stk_code':
                                                          str})  # excel读取的品种集合
    log.logger.info('品种数:{0}'.format(len(data['stk_code'])))
    g_security = data['stk_code'].tolist()  # "'a' 品种前缀 g_security
    # wt_data = pd.DataFrame(columns=['date', 'stk_code', 'win_rate', 'short_val', 'long_val']) #输出落地的excel字段
    # wt_data.to_excel(io_out, index=False)
    # 登录连接信易快期账户
    api = TqApi(TqKq(), web_gui=True, auth=TqAuth(ACCT_ID, ACCT_PWD))
    account = api.get_account()
    log.logger.info('初始账户权益:{0}'.format(account.balance))
    log.logger.info('初始浮动盈亏:{0}'.format(account.float_profit))
    SEC_LIST = []
    for g_sec in g_security:
        ls = api.query_cont_quotes(product_id=g_sec)
        SEC_LIST.append(ls[0])
    log.logger.info('品种集合:{0}'.format(SEC_LIST))
    # 获取主力合约
    # domain = api.get_quote("[email protected]")
    # 获取主力合约的K线引用
    for sec in SEC_LIST:
        positions[sec] = api.get_position(sec)
        klines_dict[sec] = api.get_kline_serial(sec, BAR_UNIT, BAR_NUM + 1)
        quotes[sec] = api.get_quote(sec)
        ticks[sec] = api.get_tick_serial(sec)
    while True:
        api.wait_update()
        for sec in SEC_LIST:
            if api.is_changing(klines_dict[sec].iloc[-1], "datetime"):
                log.logger.info('------------------------------------------')
示例#2
0
tq_account = input('天勤量化账号: ')
tq_password = input('天勤量化密码: ')
try:
    api = TqApi(auth=TqAuth(tq_account, tq_password))
except Exception as err:
    print(err, '\n')
    input(f"{'连接失败, 按任意键程序将退出, 请检查后重试'}")
    raise SystemExit()
quotes = []
labels = []
product = input("\n请输入品种代码(例rb/hc): ").lower()
try:
    available_contracts = sorted(
        api.query_quotes(ins_class="FUTURE", product_id=product,
                         expired=False))
    m_contract = api.query_cont_quotes(product_id=product)[0]
except IndexError:
    available_contracts = sorted(
        api.query_quotes(ins_class="FUTURE",
                         product_id=product.upper(),
                         expired=False))
    m_contract = api.query_cont_quotes(product_id=product.upper())[0]
m_contract_index = available_contracts.index(m_contract)


def batch_get_quote(contracts_list):
    for code_full in contracts_list:
        quotes.append(api.get_quote(code_full))
        labels.append(code_full.split(".")[1])
    if product == 'rb' or product == 'hc':
        labels.insert(0, '现货')