From 4d7dc5090ebbf169e46996e5f31e3499cb85831d Mon Sep 17 00:00:00 2001 From: admin <admin@example.com> Date: 星期二, 16 九月 2025 14:47:42 +0800 Subject: [PATCH] ForbiddenStocksManager 方法部署 --- utils/juejin_api.py | 80 ++++++++++++++++++++++++++++++++------- 1 files changed, 65 insertions(+), 15 deletions(-) diff --git a/utils/juejin_api.py b/utils/juejin_api.py index fcdec00..eceb52a 100644 --- a/utils/juejin_api.py +++ b/utils/juejin_api.py @@ -1,7 +1,10 @@ import datetime import time import strategy.data_cache - +try: + import gm.api as gmapi +except: + pass from trade import middle_api_protocol @@ -12,6 +15,7 @@ if type(val) == str and val.find('T') > -1 and val.find(':') > -1 and val.find('+') > -1: return datetime.datetime.fromisoformat(val) return val + fdata = middle_api_protocol.load_juejin(path_str, data_json) __start_time = time.time() try: @@ -42,15 +46,36 @@ def current(cls, symbols, fields): return cls.__request("current", {"symbols": symbols, "fields": fields}) + @classmethod + def history_n(cls, symbol, frequency, count, adjust, fields, end_time=None): + params = {"symbol": symbol, "frequency": frequency, "count": count, "adjust": adjust, "fields": fields} + if end_time: + params["end_time"] = end_time + params["adjust_end_time"] = end_time + return cls.__request("history_n", params) + + @classmethod + def get_previous_trading_date(cls, exchange, date): + return cls.__request("get_previous_trading_date", {"exchange": exchange, "date": date}) + + @classmethod + def get_next_trading_date(cls, exchange, date): + return cls.__request("get_next_trading_date", {"exchange": exchange, "date": date}) + + @classmethod + def get_trading_dates(cls, exchange, start_date, end_date): + return cls.__request("get_trading_dates", + {"exchange": exchange, "start_date": start_date, "end_date": end_date}) + class JueJinApi: # 鑾峰彇浜ゆ槗鎵�鐨勪唬鐮� @classmethod def get_exchanges_codes(cls, exchanges, skip_suspended=True, skip_st=True): return JueJinHttpApi.get_exchanges_codes(exchanges=exchanges, sec_types=[1], skip_suspended=skip_suspended, - skip_st=skip_st, - fields="symbol,sec_type,sec_id,sec_name,listed_date,sec_level," - "is_suspended,pre_close") + skip_st=skip_st, + fields="symbol,sec_type,sec_id,sec_name,listed_date,sec_level," + "is_suspended,pre_close") @classmethod def get_target_codes(cls): @@ -82,17 +107,42 @@ # current_datas==[{'symbol': 'SZSE.001288', 'open': 30.27, 'high': 31.77, 'low': 30.27, 'price': 30.77, 'quotes': [{'bid_p': 30.77, 'bid_v': 500, 'ask_p': 30.78, 'ask_v': 3900}, {'bid_p': 30.76, 'bid_v': 800, 'ask_p': 30.79, 'ask_v': 3100}, {'bid_p': 30.75, 'bid_v': 21900, 'ask_p': 30.8, 'ask_v': 22100}, {'bid_p': 30.72, 'bid_v': 1300, 'ask_p': 30.82, 'ask_v': 300}, {'bid_p': 30.7, 'bid_v': 600, 'ask_p': 30.83, 'ask_v': 2700}], 'cum_volume': 2586914, 'cum_amount': 80020708.18, 'trade_type': 8, 'created_at': datetime.datetime(2025, 2, 12, 14, 50, 18, tzinfo=datetime.timezone(datetime.timedelta(seconds=28800)))}] return current + @classmethod + def history_n(cls, symbol, frequency, count, adjust, fields): + return JueJinHttpApi.history_n(symbol, frequency, count, adjust, fields) + @classmethod + def history_tick_n(cls, symbol, count, end_time, adjust, fields=None, local_dwonload=True): + if local_dwonload: + gmapi.set_token("6c1dbe95191fb77cced9d805cb9c853805551ddb") + return gmapi.history_n(symbol, 'tick', count, end_time=end_time, adjust_end_time=end_time, adjust=adjust, fields=fields) + else: + return JueJinHttpApi.history_n(symbol, 'tick', count, adjust, fields, end_time=end_time) -if __name__ == '__main__': - # 鑾峰彇鐩爣浠g爜锛堣幏鍙栫洰鏍囩エ锛� - # print(f"JueJinApi.get_exchanges_codes==={JueJinApi.get_exchanges_codes(['SHSE', 'SZSE'])}") - symbols = ['SZSE.001288', 'SZSE.000042'] - fields = 'symbol,open' - # JueJinApi.get_codes_open(symbols, fields) - # - # strategy.data_cache.all_stocks = JueJinApi.get_exchanges_codes(["SHSE", "SZSE"]) - # current = JueJinHttpApi.current(symbols, fields) - # print(current) - # print(f"JueJinApi.get_exchanges_codes(['SHSE', 'SZSE'])=={len(JueJinApi.get_exchanges_codes(['SHSE', 'SZSE']))}") + @classmethod + def get_previous_trading_date(cls, date): + return JueJinHttpApi.get_previous_trading_date("SHSE", date) + # 杩斿洖鎸囧畾鏃ユ湡鐨勪笅涓氦鏄撴棩 + @classmethod + def get_next_trading_date(cls, date): + return JueJinHttpApi.get_next_trading_date("SHSE", date) + + @classmethod + def get_trading_dates(cls, start_date, end_date): + return JueJinHttpApi.get_trading_dates("SHSE", start_date, end_date) + +# if __name__ == '__main__': +# datas = JueJinApi.history_n("SHSE.000300", "1d", 10, 1, "high") +# print(datas) + +# 鑾峰彇鐩爣浠g爜锛堣幏鍙栫洰鏍囩エ锛� +# print(f"JueJinApi.get_exchanges_codes==={JueJinApi.get_exchanges_codes(['SHSE', 'SZSE'])}") +# symbols = ['SZSE.001288', 'SZSE.000042'] +# fields = 'symbol,open' +# JueJinApi.get_codes_open(symbols, fields) +# +# strategy.data_cache.all_stocks = JueJinApi.get_exchanges_codes(["SHSE", "SZSE"]) +# current = JueJinHttpApi.current(symbols, fields) +# print(current) +# print(f"JueJinApi.get_exchanges_codes(['SHSE', 'SZSE'])=={len(JueJinApi.get_exchanges_codes(['SHSE', 'SZSE']))}") -- Gitblit v1.8.0