| | |
| | | import json |
| | | |
| | | import constant |
| | | from db import redis_manager |
| | | from db.mysql_data_delegate import Mysqldb |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from l2.l2_data_manager import OrderBeginPosInfo |
| | | from utils import tool |
| | | |
| | | |
| | | class BuyMoneyAndCountSetting: |
| | |
| | | return self.__radical_buy |
| | | |
| | | |
| | | class RadicalBuyBlockCodeCountManager: |
| | | """ |
| | | 扫入目标板块的代码个数限制管理 |
| | | """ |
| | | __db = 2 |
| | | __redisManager = redis_manager.RedisManager(2) |
| | | __instance = None |
| | | __block_count_dict = {} |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | | cls.__instance = super(RadicalBuyBlockCodeCountManager, cls).__new__(cls, *args, **kwargs) |
| | | cls.__load_data() |
| | | return cls.__instance |
| | | |
| | | @classmethod |
| | | def __get_redis(cls): |
| | | return cls.__redisManager.getRedis() |
| | | |
| | | @classmethod |
| | | def __load_data(cls): |
| | | val = RedisUtils.get(cls.__get_redis(), "radical_block_code_count_setting") |
| | | if val: |
| | | val = json.loads(val) |
| | | cls.__block_count_dict = val |
| | | |
| | | def set_block_code_count(self, block_count_infos): |
| | | """ |
| | | 设置板板块买入的代码数量 |
| | | @param block_count_infos:[("名称", 数量)] |
| | | @return: |
| | | """ |
| | | if block_count_infos is None: |
| | | block_count_infos = [] |
| | | temp_dict = {x[0]: x[1] for x in block_count_infos} |
| | | self.__block_count_dict = temp_dict |
| | | RedisUtils.setex_async(self.__db, "radical_block_code_count_setting", tool.get_expire(), json.dumps(temp_dict)) |
| | | |
| | | def get_block_code_count(self, block): |
| | | """ |
| | | 获取板块最多买入代码的数量 |
| | | @param block: |
| | | @return: 最大数量,默认1 |
| | | """ |
| | | if block not in self.__block_count_dict: |
| | | return 1 |
| | | return self.__block_count_dict.get(block) |
| | | |
| | | def get_block_code_count_settings(self): |
| | | """ |
| | | 获取所有的板块设置 |
| | | @return: |
| | | """ |
| | | results = [(k, self.__block_count_dict[k]) for k in self.__block_count_dict] |
| | | results.sort(key=lambda x: x[0]) |
| | | return results |
| | | |
| | | |
| | | class BuyMoneyUtil: |
| | | @classmethod |
| | | def get_buy_data(cls, time_str, buy_mode, deals, delegates): |
| | |
| | | # [(委托代码, 委托时间)] |
| | | # delegates = DealAndDelegateWithBuyModeDataManager().get_delegates_codes_info(buy_mode) |
| | | if delegates is None: |
| | | delegates =[] |
| | | delegates = [] |
| | | # 最大委托数量 |
| | | max_count = 0 |
| | | # 配置数据:[(时间,金额,数量)] |