From 5a2ef3a696ddccbc1faef1e2e90f5b535ec24a0d Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 11 一月 2024 10:06:14 +0800 Subject: [PATCH] 看盘网页修改/接口本地化代理 --- juejin_core.py | 93 ++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 89 insertions(+), 4 deletions(-) diff --git a/juejin_core.py b/juejin_core.py index 17fdad6..44cea68 100644 --- a/juejin_core.py +++ b/juejin_core.py @@ -7,7 +7,7 @@ import xlwt import setting -import tool +from utils import tool def init(context): @@ -92,7 +92,7 @@ def on_tick(context, tick): print(tick) - if int(tick['created_at'].strftime("%H:%M:%S").replace(":","")) < int("092500"): + if int(tick['created_at'].strftime("%H:%M:%S").replace(":", "")) < int("092500"): return data = parse_tick(tick) data = {"type": 0, "data": data} @@ -120,8 +120,6 @@ # serv_addr='', backtest_match_mode=0, # token=token) subscript() - - class GPCodeManager: @@ -268,3 +266,90 @@ f.write("\n") +class JueJinApi: + __previous_trading_date_cache = {} + + # 鑾峰彇鎺橀噾鍙傛暟 + @classmethod + def getJueJinAccountInfo(cls): + strategy_id, token = setting.get_juejin_params() + return "", strategy_id, token + + @classmethod + def get_juejin_code_list_with_prefix(cls, codes): + list = [] + for d in codes: + if d[0:2] == '00': + list.append("SZSE.{}".format(d)) + elif d[0:2] == '60': + list.append("SHSE.{}".format(d)) + return list + + @classmethod + def get_gp_latest_info(cls, codes, fields=None): + if not codes: + return [] + symbols = cls.get_juejin_code_list_with_prefix(codes) + + account_id, s_id, token = cls.getJueJinAccountInfo() + gmapi.set_token(token) + data = gmapi.get_instruments(symbols=",".join(symbols), fields=fields) + return data + + @classmethod + def get_history_tick_n(cls, code, count, fields=None): + symbols = cls.get_juejin_code_list_with_prefix([code]) + + account_id, s_id, token = cls.getJueJinAccountInfo() + gmapi.set_token(token) + # 鍓嶉櫎鏉� + results = gmapi.history_n(symbol=symbols[0], frequency="1d", count=count, adjust=1, fields=fields) + return results + + @classmethod + def get_gp_current_info(cls, codes, fields=''): + if not codes: + return [] + symbols = cls.get_juejin_code_list_with_prefix(codes) + + account_id, s_id, token = cls.getJueJinAccountInfo() + gmapi.set_token(token) + data = gmapi.current(symbols=",".join(symbols), fields=fields) + return data + + # 鑾峰彇浜ゆ槗鎵�鐨勪唬鐮� + @classmethod + def get_exchanges_codes(cls, exchanges): + + account_id, s_id, token = cls.getJueJinAccountInfo() + gmapi.set_token(token) + return gmapi.get_instruments(exchanges=exchanges, sec_types=[1], skip_suspended=True, skip_st=True, + fields="symbol,sec_type,sec_id,sec_name,listed_date,sec_level,is_suspended,pre_close") + + @classmethod + def get_previous_trading_date(cls, date): + account_id, s_id, token = cls.getJueJinAccountInfo() + gmapi.set_token(token) + return gmapi.get_previous_trading_date("SHSE", date) + + @classmethod + def get_previous_trading_date_cache(cls, date): + if date not in cls.__previous_trading_date_cache: + pre_date = cls.get_previous_trading_date(date) + if pre_date: + cls.__previous_trading_date_cache[date] = pre_date + return cls.__previous_trading_date_cache.get(date) + + # 杩斿洖鎸囧畾鏃ユ湡鐨勪笅涓氦鏄撴棩 + @classmethod + def get_next_trading_date(cls, date): + + account_id, s_id, token = cls.getJueJinAccountInfo() + gmapi.set_token(token) + return gmapi.get_next_trading_date("SHSE", date) + + @classmethod + def get_trading_dates(cls, start_date, end_date): + account_id, s_id, token = cls.getJueJinAccountInfo() + gmapi.set_token(token) + return gmapi.get_trading_dates("SHSE", start_date, end_date) -- Gitblit v1.8.0