lhr
2024-06-28 e87fdf363dbe7b6f708c946ee79019a54105880a
Merge branch 'master' of http://193.112.35.168:10101/r/gp_low_suction
3个文件已修改
108 ■■■■■ 已修改文件
gui.py 66 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
local_api/__init__.py 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
local_api/juejin.py 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
gui.py
@@ -12,6 +12,9 @@
__symbol_name_dict = {}
# 系统启动时间
system_start_time = tool.get_now_time_str()
def get_symbols_names(symbols):
    request_symbols = []
@@ -201,6 +204,7 @@
            price = tool.get_buy_min_price(price)
            result = local_api.trade_api.sell(code, int(volume), price)
            print("卖出结果:", result)
            print("持仓:", local_api.trade_api.position_by_symbol(symbol))
        else:
            wx.MessageBox("没有获取到tick数据")
@@ -238,22 +242,48 @@
                symbols_names_dict = get_symbols_names([x[0] for x in datas])
                for data in datas:
                    code = data[0].split(".")[1]
                    total_volume = data[2]
                    available_volume = data[3]
                    if data[0] in self.deal_dict:
                        deal_list = self.deal_dict[data[0]]
                        deal_volume = 0
                        if deal_list:
                            for d in deal_list:
                                if d[1] == 2 and tool.trade_time_sub(d[5], system_start_time) > 0:
                                    deal_volume += d[3]
                        total_volume -= deal_volume
                        available_volume -= deal_volume
                    index = self.list_ctrl_position.InsertItem(self.list_ctrl_position.GetItemCount(), data[0])
                    # 委托量
                    dvolume = 0
                    if data[0] in self.delegates_dict:
                        delegates_list = self.delegates_dict[data[0]]
                        if delegates_list:
                            dvolume = sum([x[3] for x in delegates_list])
                            self.list_ctrl_position.SetItem(index, 8, f'{delegates_list[-1][4]}')
                    available_volume -= dvolume
                    self.list_ctrl_position.SetItem(index, 1, symbols_names_dict.get(data[0]))
                    self.list_ctrl_position.SetItem(index, 2, str(round(data[1], 2)))
                    self.list_ctrl_position.SetItem(index, 3, str(data[2]))
                    self.list_ctrl_position.SetItem(index, 4, str(data[3]))
                    self.list_ctrl_position.SetItem(index, 3, str(total_volume))
                    self.list_ctrl_position.SetItem(index, 4, str(available_volume))
                    self.list_ctrl_position.SetItem(index, 5, str(round(data[4], 2)))
                    tick = local_api.latest_tick_dict.get(code)
                    if tick:
                        self.list_ctrl_position.SetItem(index, 6, str(tick[2]))
                    else:
                        self.list_ctrl_position.SetItem(index, 6, str(data[5]))
                    dvolume = 0
                    if data[0] in self.delegates_dict:
                        delegates_list = self.delegates_dict[data[0]]
                        if delegates_list:
                            dvolume = sum([x[3] for x in delegates_list])
                    if data[0] in self.deal_dict:
                        deal_list = self.deal_dict[data[0]]
                        deal_volume = 0
                        if deal_list:
                            for d in deal_list:
                                if d[1] == 2 and tool.trade_time_sub(d[5], system_start_time) > 0:
                                    deal_volume += d[3]
                            self.list_ctrl_position.SetItem(index, 8, f'{delegates_list[-1][4]}')
                    self.list_ctrl_position.SetItem(index, 7, f'{dvolume}')
@@ -291,6 +321,26 @@
                finally:
                    time.sleep(2)
        def __get_deal_list():
            # 获取委托
            while True:
                try:
                    deals = local_api.trade_api.get_execution_reports(blocking=True)
                    deals = [(x["symbol"], x["side"], x["price"], x["volume"], x["amount"],
                              x["created_at"].strftime('%H:%M:%S')) for x in
                             deals]
                    deal_dict = {}
                    for x in deals:
                        if x[0] not in deal_dict:
                            deal_dict[x[0]] = []
                        deal_dict[x[0]].append(x)
                    self.deal_dict = deal_dict
                    # wx.CallAfter(lambda: self.label_limit_up_info.SetLabelText(st))
                except:
                    pass
                finally:
                    time.sleep(2)
        """
        开始任务
        :return:
@@ -300,10 +350,12 @@
        threading.Thread(target=__show_limit_up_list_info, daemon=True).start()
        threading.Thread(target=__get_positions, daemon=True).start()
        threading.Thread(target=__get_delegates, daemon=True).start()
        threading.Thread(target=__get_deal_list, daemon=True).start()
    def __init_data(self):
        self.delegates_dict = {}
        self.deal_dict = {}
        logs = log_export.load_system_logs()
        self.system_log_ctrl.Clear()
        for l in logs:
local_api/__init__.py
@@ -127,6 +127,13 @@
            return
        return self.__read_result(commands[2], timeout=10)
    def position_by_symbol(self, symbol, blocking=True):
        commands = ("get_position_by_symbol", {"symbol": symbol}, self.__create_request_id("get_position_by_symbol"))
        self.command_queue.put_nowait(commands)
        if not blocking:
            return
        return self.__read_result(commands[2], timeout=10)
    def get_unfinish_orders(self, blocking=True):
        """
        获取委托列表
@@ -163,6 +170,14 @@
        results = JueJinApi().get_gp_latest_info(symbols, "symbol,sec_name")
        return {x["symbol"]: x["sec_name"] for x in results}
    def get_execution_reports(self, blocking=True):
        commands = ("get_execution_reports", {},
                    self.__create_request_id("cancel_order"))
        self.command_queue.put_nowait(commands)
        if not blocking:
            return
        return self.__read_result(commands[2], timeout=10)
    def start_read_results(self):
        while True:
            try:
local_api/juejin.py
@@ -59,6 +59,16 @@
        except:
            return []
    def queryPositionBySymbol(self, symbol):
        """
        持仓查询
        :return:
        """
        try:
            return self.context.account().position(symbol, PositionSide_Long)
        except:
            return []
    def queryUnfinishOrders(self):
        """
        查询未完成委托
@@ -78,6 +88,13 @@
        """
        async_log_util.info(logger_trade, f"撤单:{local_id}-{account_id}")
        return order_cancel([{"cl_ord_id": local_id, "account_id": account_id}])
    def getExecutionReports(self):
        """
        获取执行回报
        :return:
        """
        return get_execution_reports()
__JueJinTradeManager = JueJinTradeManager()
@@ -122,12 +139,22 @@
            elif type == 'position':
                results = __JueJinTradeManager.queryPosition()
                __send_request_response(request_id, results)
            elif type == 'get_position_by_symbol':
                results = __JueJinTradeManager.queryPositionBySymbol(data["symbol"])
                __send_request_response(request_id, results)
            elif type == 'get_unfinish_orders':
                results = __JueJinTradeManager.queryUnfinishOrders()
                __send_request_response(request_id, results)
            elif type == 'cancel_order':
                __JueJinTradeManager.cancelOrders(data["local_order_id"], data["account_id"])
                __send_request_response(request_id, {})
            elif type == 'get_execution_reports':
                __JueJinTradeManager.getExecutionReports()
                __send_request_response(request_id, {})
        except Exception as e:
            logger_print.exception(e)