| | |
| | | import threading |
| | | import time |
| | | |
| | | from code_attribute import target_codes_manager, gpcode_manager |
| | | from code_attribute import target_codes_manager, gpcode_manager, code_market_manager |
| | | from huaxin_client import l2_client_for_cb, trade_client_for_cb |
| | | from huaxin_client.client_network import SendResponseSkManager |
| | | from log_module import async_log_util |
| | | from records import huaxin_trade_record_manager |
| | | from trade import huaxin_trade_api, huaxin_trade_data_update, huaxin_sell_util |
| | | from utils import middle_api_protocol, outside_api_command_manager, constant, tool, huaxin_util, socket_util, sell_util |
| | | from utils import middle_api_protocol, outside_api_command_manager, constant, tool, huaxin_util, socket_util, sell_util, \ |
| | | output_util |
| | | |
| | | middle_api_protocol.SERVER_PORT = 10008 |
| | | middle_api_protocol.SERVER_HOST = "43.138.167.68" |
| | |
| | | # 查询此仓 |
| | | code = data.get("code") |
| | | results = huaxin_trade_record_manager.PositionManager().list_by_day(tool.get_now_date_str("%Y%m%d"), code) |
| | | for r in results: |
| | | cb_code = r["securityID"] |
| | | underlying_code = target_codes_manager.get_underlying_code(cb_code) |
| | | cb_market = code_market_manager.get_market_info(code) |
| | | underlying_market = code_market_manager.get_market_info(underlying_code) |
| | | if cb_market: |
| | | r["marketInfo"] = {"code": cb_market.code, "name": r["securityName"], |
| | | "rate": f"{cb_market.rate * 100}%", |
| | | "price": cb_market.price, "lastVolume": cb_market.total_bid_volume // 100, |
| | | "buy1Money": output_util.money_desc(cb_market.buy1_price * cb_market.buy1_volume)} |
| | | if underlying_market: |
| | | if not gpcode_manager.CodesNameManager().get_code_name(underlying_market.code): |
| | | # 异步请求名称 |
| | | threading.Thread( |
| | | target=lambda: gpcode_manager.CodesNameManager().request_code_name(underlying_market.code), |
| | | daemon=True).start() |
| | | |
| | | r["underlyingMarketInfo"] = {"code": underlying_market.code, |
| | | "name": gpcode_manager.CodesNameManager().get_code_name( |
| | | underlying_market.code), "rate": f"{underlying_market.rate * 100}%", |
| | | "price": underlying_market.price, |
| | | "lastVolume": underlying_market.total_bid_volume // 100, |
| | | "buy1Money": output_util.money_desc( |
| | | underlying_market.buy1_price * underlying_market.buy1_volume)} |
| | | |
| | | send_response({"code": 0, "data": results}, client_id, request_id) |
| | | elif type_ == "refresh_trade_data": |
| | | # 刷新交易数据 |
| | |
| | | pass |
| | | |
| | | |
| | | def __read_market_data(queue_market: multiprocessing.Queue): |
| | | while True: |
| | | try: |
| | | result = queue_market.get() |
| | | if result: |
| | | # 代码, 最近的价格, 涨幅, 买1价, 买1量, 成交总量 |
| | | code_market_manager.set_market_info(result) |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | time.sleep(1) |
| | | finally: |
| | | pass |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | # ===========初始化数据========== |
| | | try: |
| | |
| | | # ===========异步日志持久化========== |
| | | threading.Thread(target=async_log_util.run_sync, daemon=True).start() |
| | | # 运行L2数据监听队列 |
| | | l2_client_for_cb.run(trade_call_back_queue) |
| | | queue_market = multiprocessing.Queue() |
| | | threading.Thread(target=__read_market_data, args=(queue_market,), daemon=True).start() |
| | | l2_client_for_cb.run(trade_call_back_queue, queue_market) |