| | |
| | | import requests |
| | | |
| | | import constant |
| | | from utils import tool |
| | | from db import redis_manager |
| | | import gm.api as gmapi |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from utils import tool, middle_api_protocol |
| | | from db import redis_manager_delegate as redis_manager |
| | | # import gm.api as gmapi |
| | | |
| | | |
| | | class JueJinHttpApi: |
| | |
| | | return datetime.datetime.fromisoformat(val) |
| | | return val |
| | | |
| | | url = f'{cls.__BASE_URL}{path_str}' |
| | | # 发送POST请求 |
| | | response = requests.post(url, json=data_json) |
| | | result = response.text |
| | | resultJson = json.loads(result) |
| | | if resultJson['code'] == 0: |
| | | data = resultJson['data'] |
| | | if type(data) == list: |
| | | for d in data: |
| | | DELEGATE = True |
| | | fdata = None |
| | | if DELEGATE: |
| | | fdata = middle_api_protocol.load_juejin(path_str, data_json) |
| | | fdata = middle_api_protocol.request(fdata) |
| | | else: |
| | | url = f'{cls.__BASE_URL}{path_str}' |
| | | # 发送POST请求 |
| | | response = requests.post(url, json=data_json) |
| | | result = response.text |
| | | resultJson = json.loads(result) |
| | | if resultJson['code'] == 0: |
| | | fdata = resultJson['data'] |
| | | if fdata: |
| | | if type(fdata) == list: |
| | | for d in fdata: |
| | | if type(d) != dict: |
| | | continue |
| | | for k in d: |
| | | d[k] = deformat_date(d[k]) |
| | | elif type(data) == dict: |
| | | for k in data: |
| | | data[k] = deformat_date(data[k]) |
| | | return data |
| | | |
| | | return None |
| | | elif type(fdata) == dict: |
| | | for k in fdata: |
| | | fdata[k] = deformat_date(fdata[k]) |
| | | return fdata |
| | | else: |
| | | return None |
| | | |
| | | @classmethod |
| | | def get_instruments(cls, symbols, fields): |
| | |
| | | @classmethod |
| | | def current(cls, symbols, fields): |
| | | return cls.__request("current", {"symbols": symbols, "fields": fields}) |
| | | |
| | | @classmethod |
| | | def get_exchanges_codes(cls, exchanges, sec_types, skip_suspended, skip_st, fields): |
| | | return cls.__request("get_instruments", |
| | | {"exchanges": exchanges, "sec_types": sec_types, "skip_suspended": skip_suspended, |
| | | "skip_st": skip_st, "fields": fields}) |
| | | |
| | | @classmethod |
| | | def get_previous_trading_date(cls, exchange, date): |
| | |
| | | @classmethod |
| | | def getJueJinAccountInfo(cls): |
| | | redis = cls.__redisManager.getRedis() |
| | | account_id = redis.get("juejin-account-id") |
| | | strategy_id = redis.get("juejin-strategy-id") |
| | | token = redis.get("juejin-token") |
| | | return account_id, strategy_id, token |
| | | try: |
| | | account_id = RedisUtils.get(redis, "juejin-account-id", auto_free=False) |
| | | strategy_id = RedisUtils.get(redis, "juejin-strategy-id", auto_free=False) |
| | | token = RedisUtils.get(redis, "juejin-token", auto_free=False) |
| | | return account_id, strategy_id, token |
| | | finally: |
| | | RedisUtils.realse(redis) |
| | | |
| | | @classmethod |
| | | def get_juejin_code_list_with_prefix(cls, codes): |
| | |
| | | data = JueJinHttpApi.current(symbols=",".join(symbols), fields='') |
| | | return data |
| | | # 返回指定日期的上个交易日 |
| | | |
| | | # 获取交易所的代码 |
| | | @classmethod |
| | | def get_exchanges_codes(cls, exchanges): |
| | | if constant.JUEJIN_LOCAL_API: |
| | | 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") |
| | | else: |
| | | return JueJinHttpApi.get_exchanges_codes(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): |
| | |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | print(JueJinApi.get_gp_current_info(["000333", "600686"])) |
| | | constant.JUEJIN_LOCAL_API = False |
| | | print(HistoryKDatasUtils.get_lowest_price_rate("000725", 30)) |