| | |
| | | # 载入量 |
| | | global_data_loader.load_volumn() |
| | | |
| | | # 9点25之前删除所有代码 |
| | | if tool.trade_time_sub(tool.get_now_time_str(), "09:25:00") <= 0: |
| | | gpcode_manager.clear_listen_codes() |
| | | |
| | | # TODO 删除所有首板代码 |
| | | |
| | | |
| | | # 每日初始化 |
| | | def everyday_init(): |
| | |
| | | for c in clients: |
| | | for i in range(0, 8): |
| | | gpcode_manager.init_listen_code_by_pos(int(c), i) |
| | | codes = gpcode_manager.get_gp_list(); |
| | | result = JueJinManager.get_gp_latest_info(codes); |
| | | codes = gpcode_manager.get_gp_list() |
| | | result = JueJinManager.get_gp_latest_info(codes) |
| | | for item in result: |
| | | sec_level = item['sec_level'] |
| | | symbol = item['symbol'] |
| | |
| | | |
| | | # 获取到现价 |
| | | def accept_prices(prices): |
| | | # 获取首板代码 |
| | | first_codes = gpcode_manager.get_first_gp_codes() |
| | | |
| | | print("价格代码数量:", len(prices)) |
| | | |
| | | __actualPriceProcessor.save_current_price_codes_count(len(prices)) |
| | | # 采集的代码数量不对 |
| | | if len(gpcode_manager.get_gp_list()) - len(prices) > 2: |
| | |
| | | pricePre = gpcode_manager.get_price_pre(code) |
| | | if pricePre is not None: |
| | | rate = round((price - pricePre) * 100 / pricePre, 2) |
| | | if first_codes and code in first_codes: |
| | | rate = rate / 2 |
| | | if rate >= 0: |
| | | # 暂存涨幅为正的代码 |
| | | _code_list.append((rate, code)) |
| | |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | |
| | | # -------------------------------处理交易位置分配--------------------------------- |
| | | # 排序 |
| | | new_code_list = sorted(_code_list, key=lambda e: e.__getitem__(0), reverse=True) |
| | | new_code_list = sorted(_code_list, key=lambda e: (e.__getitem__(0), e.__getitem__(1)), reverse=True) |
| | | # 预填充下单代码 |
| | | _buy_win_codes = [] |
| | | for d in new_code_list: |
| | |
| | | logging.exception(e) |
| | | pass |
| | | |
| | | # -------------------------------处理L2监听--------------------------------- |
| | | |
| | | client_ids = client_manager.getValidL2Clients() |
| | | # 最多填充的代码数量 |
| | | max_count = len(client_ids) * 8 |
| | | max_count = len(client_ids) * constant.L2_CODE_COUNT_PER_DEVICE |
| | | if max_count == 0: |
| | | max_count = 8 |
| | | max_count = constant.L2_CODE_COUNT_PER_DEVICE |
| | | |
| | | _delete_list = [] |
| | | for item in new_code_list: |
| | | if l2_trade_util.is_in_forbidden_trade_codes(item[1]) or item[0] < 0: |
| | | _delete_list.append(item) |
| | | |
| | | for item in _delete_list: |
| | | new_code_list.remove(item) |
| | | # 截取前几个代码填充 |
| | | add_list = new_code_list[:max_count] |
| | | # 后面的代码全部删除 |
| | | _delete_list.extend(new_code_list[max_count:]) |
| | | |
| | | add_code_list = [] |
| | | del_list = [] |
| | | del_code_list = [] |
| | | for d in add_list: |
| | | add_code_list.append(d[1]) |
| | | |
| | | for d in _delete_list: |
| | | del_list.append(d[1]) |
| | | del_code_list.append(d[1]) |
| | | |
| | | # 后面的代码数量 |
| | | # 先删除应该删除的代码 |
| | | for code in del_list: |
| | | for code in del_code_list: |
| | | if gpcode_manager.is_listen_old(code): |
| | | # 判断是否在监听里面 |
| | | L2CodeOperate.get_instance().add_operate(0, code, "现价变化") |
| | | # 增加应该增加的代码 |
| | | for code in add_code_list: |
| | | if not gpcode_manager.is_listen_old(code): |
| | | if not l2_trade_util.is_in_forbidden_trade_codes(code): |
| | | L2CodeOperate.get_instance().add_operate(1, code, "现价变化") |
| | | else: |
| | | if l2_trade_util.is_in_forbidden_trade_codes(code): |
| | | L2CodeOperate.get_instance().add_operate(0, code, "现价变化") |
| | | |
| | | print(add_code_list, del_list) |
| | | print(add_code_list, del_code_list) |
| | | |
| | | |
| | | def on_bar(context, bars): |
| | |
| | | t1.setDaemon(True) |
| | | t1.start() |
| | | |
| | | @staticmethod |
| | | def get_gp_latest_info(codes): |
| | | @classmethod |
| | | def get_gp_latest_info(cls, codes): |
| | | account_id, s_id, token = getAccountInfo() |
| | | symbols = gpcode_manager.get_gp_list_with_prefix(codes) |
| | | gmapi.set_token(token) |
| | |
| | | print(data) |
| | | return data |
| | | |
| | | @staticmethod |
| | | def get_now_price(codes): |
| | | @classmethod |
| | | def get_now_price(cls, codes): |
| | | data = JueJinManager.get_gp_current_info(codes) |
| | | prices = [] |
| | | for item in data: |
| | |
| | | return prices |
| | | |
| | | # 获取代码的涨幅 |
| | | @staticmethod |
| | | def get_codes_limit_rate(codes): |
| | | @classmethod |
| | | def get_codes_limit_rate(cls, codes): |
| | | datas = JueJinManager.get_gp_latest_info(codes) |
| | | pre_price_dict = {} |
| | | for data in datas: |
| | |
| | | f_results.reverse() |
| | | return f_results |
| | | |
| | | @staticmethod |
| | | def get_gp_current_info(codes): |
| | | @classmethod |
| | | def get_history_tick_n(cls, code, count): |
| | | account_id, s_id, token = getAccountInfo() |
| | | symbols = gpcode_manager.get_gp_list_with_prefix([code]) |
| | | gmapi.set_token(token) |
| | | results = gmapi.history_n(symbol=symbols[0], frequency="1d", count=count) |
| | | return results |
| | | |
| | | @classmethod |
| | | def get_lowest_price_rate(cls, code, count): |
| | | datas = cls.get_history_tick_n(code, count) |
| | | low_price = datas[0]["close"] |
| | | for data in datas: |
| | | if low_price > data["close"]: |
| | | low_price = data["close"] |
| | | return (datas[-1]["close"] - low_price) / low_price |
| | | |
| | | @classmethod |
| | | def get_gp_current_info(cls, codes): |
| | | account_id, s_id, token = getAccountInfo() |
| | | symbols = gpcode_manager.get_gp_list_with_prefix(codes) |
| | | gmapi.set_token(token) |
| | | data = gmapi.current(symbols=",".join(symbols)) |
| | | print(data) |
| | | return data |
| | | |
| | | @classmethod |
| | | def get_gp_codes_names(cls, codes): |
| | | datas = cls.get_gp_latest_info(codes) |
| | | results = {} |
| | | for data in datas: |
| | | code = data["symbol"].split(".")[1] |
| | | code_name = data['sec_name'] |
| | | results[code] = code_name |
| | | return results |
| | | |
| | | def start(self): |
| | | account_id, s_id, token = getAccountInfo() |
| | |
| | | return _fresult |
| | | |
| | | |
| | | # 获取近90天的最大量与最近的量 |
| | | def get_volumn(code) -> object: |
| | | end = datetime.datetime.now() |
| | | account_id, s_id, token = getAccountInfo() |
| | | gmapi.set_token(token) |
| | | gmapi.set_account_id(account_id) |
| | | results = gmapi.history_n(symbol=gpcode_manager.get_gp_list_with_prefix([code])[0], frequency="1d", |
| | | count=60, |
| | | fields="volume", |
| | | end_time=end) |
| | | if not results: |
| | | return None |
| | | yes_volume = results[-1]["volume"] |
| | | max_volume = results[0]["volume"] |
| | | for result in results: |
| | | volumn = int(result["volume"]) |
| | | if volumn > max_volume: |
| | | max_volume = volumn |
| | | return (max_volume, yes_volume) |
| | | |
| | | |
| | | # 根据涨幅高低分配交易窗口 |
| | | def distribute_buy_win(): |
| | | if tool.trade_time_sub(tool.get_now_time_str(),"09:30:00") > 0: |
| | |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | distribute_buy_win() |
| | | print(get_volumn("002115")) |
| | | print(JueJinManager.get_lowest_price_rate("002713", 15)) |