admin
2024-02-29 07af91d1cb4e317065b8dc1db09f337f2014e8c7
middle_api_server.py
@@ -90,15 +90,14 @@
                                if not volume:
                                    raise Exception("请上传volume")
                                if round(float(price), 2) <= 0:
                                    prices = HistoryKDatasUtils.get_now_price([code])
                                    if not prices:
                                        raise Exception("现价获取失败")
                                    price = prices[0][1]
                                # if round(float(price), 2) <= 0:
                                #     prices = HistoryKDatasUtils.get_now_price([code])
                                #     if not prices:
                                #         raise Exception("现价获取失败")
                                #     price = prices[0][1]
                                # 下单
                                result = hosting_api_util.trade_order(hosting_api_util.TRADE_DIRECTION_BUY, code,
                                                                      volume,
                                                                      round(float(price), 2))
                                                                      volume, price)
                                if result:
                                    resultJSON = result
                                    print("下单结果:", resultJSON)
@@ -353,14 +352,29 @@
                            sk.sendall(socket_util.load_header(return_str.encode(encoding='utf-8')))
                            while True:
                                try:
                                    sk.recv(1024)
                                    buf = sk.recv(1024)
                                    print(f"收到数据:{buf.decode(encoding='utf-8')}")
                                    time.sleep(1)
                                except:
                                    print("数据断开")
                                    break
                        elif type_ == "get_latest_cancel_orders":
                            # 获取最近的撤单
                            results = huaxin_trade_record_manager.DelegateRecordManager.list_latest_cancel_records(10)
                            fresults = []
                            for result in results:
                                temp = {}
                                for key in result:
                                    if key in ["securityID", "securityName", "direction", "orderSysID", "acceptTime",
                                               "cancelTime", "limitPrice", "volume"]:
                                        temp[key] = result[key]
                                # 过滤虚拟单与卖单
                                if int(temp["volume"] <= 100):
                                    continue
                                if int(temp["direction"] != 0):
                                    continue
                                fresults.append(temp)
                                return_str = json.dumps(json.dumps({"code": 0, "data": fresults}))
                    finally:
                        log.request_info("middle_api_server", f"请求结束:{type_}")
                break