| | |
| | | l2_trade_util.init_forbidden_trade_codes() |
| | | # 清空白名单 |
| | | l2_trade_util.WhiteListCodeManager.clear() |
| | | |
| | | # TODO 删除所有首板代码 |
| | | # 清空想要买 |
| | | gpcode_manager.WantBuyCodesManager.clear() |
| | | |
| | | |
| | | # 每日初始化 |
| | |
| | | return f_results |
| | | |
| | | @classmethod |
| | | def get_history_tick_n(cls, code, count): |
| | | def get_history_tick_n(cls, code, count, fields=None): |
| | | 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) |
| | | results = gmapi.history_n(symbol=symbols[0], frequency="1d", count=count, fields=fields) |
| | | return results |
| | | |
| | | @classmethod |
| | |
| | | |
| | | |
| | | # 获取近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) |
| | | datas = JueJinManager.get_history_tick_n(code, 60, "open,high,low,close,volume,pre_close,bob") |
| | | # 计算 |
| | | datas.sort(key=lambda x: x["bob"], reverse=True) |
| | | max_volume = 0 |
| | | for i in range(len(datas)): |
| | | # 查询涨停 |
| | | item = datas[i] |
| | | volume = item["volume"] |
| | | if max_volume < volume: |
| | | max_volume = volume |
| | | # 是否有涨停 |
| | | limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"])) |
| | | if abs(limit_up_price - item["high"]) < 0.01: |
| | | next_volume = 0 |
| | | if i > 0: |
| | | next_volume = datas[i - 1]["volume"] |
| | | return (max(volume, next_volume), max(volume, next_volume)) |
| | | return (max_volume, max_volume) |
| | | |
| | | |
| | | # 根据涨幅高低分配交易窗口 |
| | |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | free_count = 0 |
| | | if free_count < 2: |
| | | # 空闲位置不足 |
| | | listen_codes = gpcode_manager.get_listen_codes() |
| | | for code in listen_codes: |
| | | if not gpcode_manager.is_in_gp_pool(code): |
| | | client_id, pos = gpcode_manager.get_listen_code_pos(code) |
| | | gpcode_manager.set_listen_code_by_pos(client_id, pos, "") |
| | | free_count += 1 |
| | | if free_count > 2: |
| | | break |
| | | print(get_volumn("002291")) |