| | |
| | | from third_data.third_blocks_manager import CodeThirdBlocksManager, SOURCE_TYPE_KPL, BlockMapManager |
| | | from trade import trade_manager, l2_trade_util, trade_data_manager, trade_constant |
| | | import l2_data_util as l2_data_util_old |
| | | from trade.buy_money_count_setting import BuyMoneyAndCountSetting |
| | | |
| | | from trade.huaxin import huaxin_trade_api, huaxin_trade_data_update, \ |
| | | huaxin_trade_record_manager, huaxin_trade_order_processor, huaxin_sell_util |
| | |
| | | self.send_response({"code": 0, "data": data, "msg": f""}, |
| | | client_id, |
| | | request_id) |
| | | elif ctype == "set_buy_money_count_setting": |
| | | # 设置买入金额和数量 |
| | | normal = data["normal"] |
| | | radical = data["radical"] |
| | | BuyMoneyAndCountSetting().set_normal_buy_data(normal[0],json.loads( normal[1])) |
| | | BuyMoneyAndCountSetting().set_radical_buy_data(radical[0],json.loads( radical[1])) |
| | | data = { |
| | | "normal": BuyMoneyAndCountSetting().get_normal_buy_setting(), |
| | | "radical": BuyMoneyAndCountSetting().get_radical_buy_setting() |
| | | } |
| | | self.send_response({"code": 0, "data": data, "msg": f""}, |
| | | client_id, |
| | | request_id) |
| | | elif ctype == "get_buy_money_count_setting": |
| | | # 设置买入金额和数量 |
| | | data = { |
| | | "normal": BuyMoneyAndCountSetting().get_normal_buy_setting(), |
| | | "radical": BuyMoneyAndCountSetting().get_radical_buy_setting() |
| | | } |
| | | self.send_response({"code": 0, "data": data, "msg": f""}, |
| | | client_id, |
| | | request_id) |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | logger_debug.exception(e) |
New file |
| | |
| | | """ |
| | | 买入金额与数量设置 |
| | | """ |
| | | import json |
| | | |
| | | import constant |
| | | from db.mysql_data_delegate import Mysqldb |
| | | |
| | | |
| | | class BuyMoneyAndCountSetting: |
| | | __mysql = Mysqldb() |
| | | __instance = None |
| | | # 常规买 |
| | | __normal_buy = [10, [("15:00:00", constant.BUY_MONEY_PER_CODE)]] # (数量, [("时间", 金额)]) |
| | | # 扫入买 |
| | | __radical_buy = [4, [("15:00:00", constant.BUY_MONEY_PER_CODE)]] # (数量, [("时间", 金额)]) |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | | cls.__instance = super(BuyMoneyAndCountSetting, cls).__new__(cls, *args, **kwargs) |
| | | cls.__load_data() |
| | | return cls.__instance |
| | | |
| | | @classmethod |
| | | def __load_data(cls): |
| | | keys = ["normal_buy_money_setting", "radical_buy_money_setting", "normal_buy_count_setting", |
| | | "radical_buy_count_setting"] |
| | | sql = "select `key`, `value` from config where " + " or ".join([f"`key`='{k}'" for k in keys]) |
| | | results = cls.__mysql.select_all(sql) |
| | | if results: |
| | | for result in results: |
| | | if result[0] == keys[0]: |
| | | # 常规买金额设置 |
| | | if result[1]: |
| | | cls.__normal_buy[1] = json.loads(result[1]) |
| | | elif result[0] == keys[1]: |
| | | # 扫入买金额设置 |
| | | if result[1]: |
| | | cls.__radical_buy[1] = json.loads(result[1]) |
| | | elif result[0] == keys[2]: |
| | | if result[1]: |
| | | # 常规买数量设置 |
| | | cls.__normal_buy[0] = int(result[1]) |
| | | elif result[0] == keys[3]: |
| | | if result[1]: |
| | | # 扫入买数量设置 |
| | | cls.__radical_buy[0] = int(result[1]) |
| | | |
| | | def set_normal_buy_data(self, max_count, money_list: list): |
| | | """ |
| | | 常规买数据设置 |
| | | @param max_count: |
| | | @param money_list: |
| | | @return: |
| | | """ |
| | | self.__normal_buy = [max_count, money_list] |
| | | self.__mysql.execute(f"update config set `value` = '{max_count}' where `key` = 'normal_buy_count_setting'") |
| | | self.__mysql.execute( |
| | | f"update config set `value` = '{json.dumps(money_list)}' where `key` = 'normal_buy_money_setting'") |
| | | |
| | | def set_radical_buy_data(self, max_count, money_list: list): |
| | | """ |
| | | 扫入买数据设置 |
| | | @param max_count: |
| | | @param money_list: |
| | | @return: |
| | | """ |
| | | self.__radical_buy = [max_count, money_list] |
| | | self.__mysql.execute(f"update config set `value` = '{max_count}' where `key` = 'radical_buy_count_setting'") |
| | | self.__mysql.execute( |
| | | f"update config set `value` = '{json.dumps(money_list)}' where `key` = 'radical_buy_money_setting'") |
| | | |
| | | def get_normal_buy_setting(self): |
| | | return self.__normal_buy |
| | | |
| | | def get_radical_buy_setting(self): |
| | | return self.__radical_buy |
| | | |
| | | |
| | | class BuyMoneyUtil: |
| | | @classmethod |
| | | def get_buy_money(cls, time_str, money_list: list): |
| | | """ |
| | | @param time_str: |
| | | @param money_list:[("09:30:00",20000)] |
| | | @return: |
| | | """ |
| | | if len(money_list) == 0: |
| | | return constant.BUY_MONEY_PER_CODE |
| | | for money_info in money_list: |
| | | if int(time_str.replace(":", "")) <= int(money_info[0].replace(":", "")): |
| | | return money_info[1] |
| | | return constant.BUY_MONEY_PER_CODE |
| | | |
| | | |
| | | def set_buy_money(deal_codes, delegate_codes): |
| | | """ |
| | | 设置买入金额 |
| | | @param deal_codes: |
| | | @param delegate_codes: |
| | | @return: |
| | | """ |
| | | codes = set() |
| | | if deal_codes: |
| | | codes |= deal_codes |
| | | if delegate_codes: |
| | | codes |= delegate_codes |
| | | if len(codes) < 4: |
| | | constant.BUY_MONEY_PER_CODE = 50000 |
| | | else: |
| | | constant.BUY_MONEY_PER_CODE = 20000 |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | set_buy_money({"000333"}, None) |
| | |
| | | from code_attribute import gpcode_manager |
| | | from huaxin_client import constant as huaxin_client_constant |
| | | from log_module import async_log_util |
| | | from log_module.log import hx_logger_trade_debug, logger_system |
| | | from trade import trade_manager, trade_data_manager |
| | | from log_module.log import hx_logger_trade_debug, logger_system, logger_debug |
| | | from trade import trade_manager, trade_data_manager, buy_money_count_setting |
| | | from trade.huaxin import huaxin_trade_api, huaxin_trade_record_manager |
| | | |
| | | from trade.huaxin.huaxin_trade_order_processor import HuaxinOrderEntity, TradeResultProcessor |
| | |
| | | insertDate=insertDate, direction=direction, |
| | | is_shadow_order=is_shadow_order) |
| | | TradeResultProcessor.process_buy_order(order) |
| | | if huaxin_util.is_can_cancel(orderStatus): |
| | | if huaxin_util.is_can_cancel(orderStatus) and str(direction) == str( |
| | | huaxin_util.TORA_TSTP_D_Buy): |
| | | codes.append(code) |
| | | trade_manager.delegate_codes = set(codes) |
| | | buy_money_count_setting.set_buy_money(trade_manager.deal_codes, |
| | | trade_manager.delegate_codes) |
| | | if codes: |
| | | try: |
| | | trade_manager.process_trade_delegate_data([{"code": c} for c in codes]) |
| | |
| | | print("成交响应:", dataJSON) |
| | | if dataJSON["code"] == 0: |
| | | datas = dataJSON["data"] |
| | | if datas is None: |
| | | datas = [] |
| | | try: |
| | | buy_deal_codes = set() |
| | | for d in datas: |
| | | if str(d['direction']) == str(huaxin_util.TORA_TSTP_D_Buy): |
| | | buy_deal_codes.add(d['securityID']) |
| | | trade_manager.deal_codes = buy_deal_codes |
| | | buy_money_count_setting.set_buy_money(trade_manager.deal_codes, trade_manager.delegate_codes) |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | huaxin_trade_record_manager.DealRecordManager.add(datas) |
| | | if datas: |
| | | tempList = [ |
| | | {"time": d["tradeTime"], "type": int(d['direction']), "code": d['securityID']} |
| | | for d in datas] |
| | | try: |
| | | |
| | | trade_manager.process_trade_success_data(tempList) |
| | | except Exception as e: |
| | | logging.exception(e) |
| | |
| | | |
| | | latest_trade_delegate_data = [] |
| | | |
| | | # 成交的代码 |
| | | deal_codes = set() |
| | | # 委托代码 |
| | | delegate_codes = set() |
| | | |
| | | |
| | | # 关闭购买入口 |
| | | # 开启购买入口 |