Administrator
2025-06-09 fd088787bc52e93bbce8f6aeb080fa8f472015aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import json
import multiprocessing
import threading
import time
 
import requests
 
from api import outside_api_callback
from api.outside_api_command_manager import ApiCommandManager
from huaxin_client import l2_market_client, trade_client
from log_module.log import logger_debug
from server import data_server
from strategy.env_info import RealTimeEnvInfo
from third_data import hx_qc_value_util
from trade.huaxin import huaxin_trade_api
from utils import tool, middle_api_protocol
 
 
def __run_l2_market_subscript():
    def read_results():
        while True:
            try:
                data = queue_l1_w_strategy_r.get()
                if data.get("type") == 'set_target_codes':
                    # [(代码, 时间戳, 价格, 总交易量, 总交易额, 买5, 卖5)]
                    market_data_list = data["data"]["data"]
                    RealTimeEnvInfo().ticks = (tool.get_now_time_str(), len(market_data_list))
            except:
                time.sleep(0.1)
 
    queue_l1_w_strategy_r: multiprocessing.Queue = multiprocessing.Queue()
    l2MarketProcess = multiprocessing.Process(target=l2_market_client.run,
                                              args=(queue_l1_w_strategy_r,))
    l2MarketProcess.start()
    read_results()
 
 
def test():
    time.sleep(10)
    result = huaxin_trade_api.get_money(blocking=True)
    logger_debug.info(f"测试交易账户获取:{result}")
    # 发送信息
    requests.post("http://127.0.0.1:9008/upload_big_order_datas", json=json.dumps({"data": [(1, 2, 3, 4, 5)]}))
    # 获取增值服务API
    result = hx_qc_value_util.get_next_trading_date("2025-06-06")
    logger_debug.info(f"测试获取下一个交易日:{result}")
 
 
if __name__ == "__main__":
    # -----启动data_server-----
    threading.Thread(target=lambda: data_server.run("127.0.0.1", 9008), daemon=True).start()
 
    # --------启动本地API接口----------
    manager = ApiCommandManager(middle_api_protocol.SERVER_HOST, middle_api_protocol.SERVER_PORT, outside_api_callback.MyAPICallback())
    manager.run(blocking=False)
 
    # -------启动华鑫增值服务api------
    threading.Thread(target=hx_qc_value_util.run, daemon=True).start()
    # --------启动交易----------
    huaxin_trade_api.run()
 
    threading.Thread(target=test, daemon=True).start()
    test()
 
    # -------启动L2 market订阅------
    __run_l2_market_subscript()
    print("启动完成")