| | |
| | | # print("下单:", huaxin_trade_api.order(1, "127075", 10, 140.5, blocking=True)) |
| | | |
| | | |
| | | def __get_buy_money(): |
| | | def __get_buy_money(strategy_type): |
| | | time_str = tool.get_now_time_str().replace(":", "") |
| | | if int(time_str) < int("103000"): |
| | | return 40000 |
| | | money = 40000 |
| | | elif int(time_str) < int("113000"): |
| | | return 30000 |
| | | money = 30000 |
| | | elif int(time_str) < int("140000"): |
| | | return 20000 |
| | | money = 20000 |
| | | else: |
| | | return 10000 |
| | | |
| | | money = 10000 |
| | | if strategy_type == buy_strategy.STRATEGY_TYPE_RISE_HIGH_WITH_BLOCKS: |
| | | return int(money*0.2) |
| | | elif strategy_type == buy_strategy.STRATEGY_TYPE_LIMIT_UP: |
| | | return int(money * 0.8) |
| | | else: |
| | | return money |
| | | |
| | | def read_l2_results(trade_call_back_queue): |
| | | while True: |
| | |
| | | # 获取股票代码的可转债代码 |
| | | cb_code = target_codes_manager.get_cb_code(code) |
| | | if CodeTradeStateManager().get_trade_state(cb_code, |
| | | strategy_type) == CodeTradeStateManager.TRADE_STATE_ALREADY_BUY and not WantBuyCodesManager().is_in_cache(cb_code, strategy_type): |
| | | strategy_type) == CodeTradeStateManager.TRADE_STATE_ALREADY_BUY and not WantBuyCodesManager().is_in_cache( |
| | | cb_code, strategy_type): |
| | | # 已经买了且没在想买单 |
| | | continue |
| | | # 获取可转债的涨停价 |
| | |
| | | async_log_util.info(logger_trade, f"可转债涨幅过高::{cb_code}-{market_info.rate}") |
| | | continue |
| | | |
| | | volume = int(__get_buy_money() / float(limit_up_price)) |
| | | volume = int(__get_buy_money(strategy_type) / float(limit_up_price)) |
| | | volume = (volume // 10) * 10 |
| | | buy_price = round(min(float(market_info.price * 1.02), float(limit_up_price)), 3) |
| | | async_log_util.info(logger_trade, f"准备下单:{cb_code}-{buy_price}-{buy_info}") |
| | |
| | | if not result: |
| | | # 新增数据 |
| | | mysqldb.execute( |
| | | "insert into hx_trade_deal_record values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')" % ( |
| | | "insert into hx_trade_deal_record values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',%s)" % ( |
| | | d["tradeID"], d["securityID"], d["orderLocalID"], d["direction"], |
| | | d["orderSysID"], round(d["price"], 3), d["tradeTime"], d["volume"], |
| | | d["tradeDate"], |
| | | d["tradingDay"], d["pbuID"], d["accountID"], |
| | | tool.get_now_datetime_str(), |
| | | tool.get_now_datetime_str())) |
| | | tool.get_now_datetime_str(),d["orderRef"])) |
| | | finally: |
| | | pass |
| | | |
| | |
| | | key_list = ["tradeID", "securityID", "orderLocalID", "direction", "orderSysID", "price", |
| | | "tradeTime", "volume", "tradeDate", "tradingDay", "pbuID", |
| | | "accountID", "createTime", |
| | | "updateTime"] |
| | | "updateTime","orderRef"] |
| | | fresults = [] |
| | | if results: |
| | | for r in results: |