| | |
| | | import datetime |
| | | import time |
| | | import strategy.data_cache |
| | | |
| | | try: |
| | | import gm.api as gmapi |
| | | except: |
| | | pass |
| | | from trade import middle_api_protocol |
| | | |
| | | |
| | |
| | | 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: |
| | |
| | | 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): |
| | |
| | | # 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__': |
| | | # 获取目标代码(获取目标票) |
| | | # 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) |
| | | |
| | | # 获取目标代码(获取目标票) |
| | | # 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']))}") |