| | |
| | | |
| | | import constant |
| | | from db.redis_manager import RedisUtils |
| | | from utils import tool |
| | | from utils import tool, middle_api_protocol |
| | | from db import redis_manager |
| | | import gm.api as gmapi |
| | | |
| | |
| | | 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): |
| | |
| | | redis = cls.__redisManager.getRedis() |
| | | try: |
| | | account_id = RedisUtils.get(redis, "juejin-account-id", auto_free=False) |
| | | strategy_id =RedisUtils.get(redis, "juejin-strategy-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): |
| | |
| | | |
| | | if __name__ == "__main__": |
| | | constant.JUEJIN_LOCAL_API = False |
| | | list_ = JueJinApi.get_exchanges_codes(["SHSE","SZSE"]) |
| | | fdatas = [] |
| | | for d in list_: |
| | | if d["sec_id"].find("60") != 0 and d["sec_id"].find("00") != 0: |
| | | continue |
| | | if d["sec_level"] != 1: |
| | | continue |
| | | if d["pre_close"] * 1.1 > 40: |
| | | continue |
| | | if (d["listed_date"] + datetime.timedelta(days=100)).timestamp() > datetime.datetime.now().timestamp(): |
| | | continue |
| | | fdatas.append(d) |
| | | print(len(fdatas)) |
| | | print(HistoryKDatasUtils.get_lowest_price_rate("000725", 30)) |