gjdatac-api 0.1.9__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of gjdatac-api might be problematic. Click here for more details.
- {gjdatac_api-0.1.9 → gjdatac_api-0.2.0}/PKG-INFO +1 -1
- {gjdatac_api-0.1.9 → gjdatac_api-0.2.0}/gjdatac_api/data_api_class.py +23 -35
- {gjdatac_api-0.1.9 → gjdatac_api-0.2.0}/gjdatac_api/dict_data.py +138 -15
- {gjdatac_api-0.1.9 → gjdatac_api-0.2.0}/gjdatac_api.egg-info/PKG-INFO +1 -1
- {gjdatac_api-0.1.9 → gjdatac_api-0.2.0}/setup.py +1 -1
- {gjdatac_api-0.1.9 → gjdatac_api-0.2.0}/gjdatac_api/__init__.py +0 -0
- {gjdatac_api-0.1.9 → gjdatac_api-0.2.0}/gjdatac_api/dolphindb_info.py +0 -0
- {gjdatac_api-0.1.9 → gjdatac_api-0.2.0}/gjdatac_api/instrument_class.py +0 -0
- {gjdatac_api-0.1.9 → gjdatac_api-0.2.0}/gjdatac_api.egg-info/SOURCES.txt +0 -0
- {gjdatac_api-0.1.9 → gjdatac_api-0.2.0}/gjdatac_api.egg-info/dependency_links.txt +0 -0
- {gjdatac_api-0.1.9 → gjdatac_api-0.2.0}/gjdatac_api.egg-info/requires.txt +0 -0
- {gjdatac_api-0.1.9 → gjdatac_api-0.2.0}/gjdatac_api.egg-info/top_level.txt +0 -0
- {gjdatac_api-0.1.9 → gjdatac_api-0.2.0}/setup.cfg +0 -0
|
@@ -10,7 +10,7 @@ import chinese_calendar as calendar
|
|
|
10
10
|
import pandas as pd
|
|
11
11
|
import dolphindb as ddb
|
|
12
12
|
|
|
13
|
-
from
|
|
13
|
+
from .dict_data import (get_price_frequency_dict, get_price_data_type_dict, get_instruments_type_dict,
|
|
14
14
|
future_delivery_fee_return_fields, future_delivery_fee_return_fields_rename,
|
|
15
15
|
future_margin_ratio_return_fields, future_margin_ratio_return_fields_rename,
|
|
16
16
|
future_limit_position_return_fields, future_limit_position_return_fields_rename,
|
|
@@ -18,8 +18,8 @@ from utils.dict_data import (get_price_frequency_dict, get_price_data_type_dict,
|
|
|
18
18
|
tick_main_contract_return_fields, tick_main_contract_return_fields_rename,
|
|
19
19
|
gtja_mink_main_contract_return_fields, gtja_mink_main_contract_return_fields_rename
|
|
20
20
|
)
|
|
21
|
-
from
|
|
22
|
-
from
|
|
21
|
+
from .dolphindb_info import *
|
|
22
|
+
from .instrument_class import Instrument
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
class GJDataC:
|
|
@@ -2916,26 +2916,20 @@ class GJDataC:
|
|
|
2916
2916
|
except Exception as e:
|
|
2917
2917
|
raise e
|
|
2918
2918
|
|
|
2919
|
-
"""
|
|
2920
|
-
get_history_bars 此接口和下面的接口合并为一个,根据传入的参数进行判断,调用不同的方法
|
|
2921
|
-
查询合约指定日期前的行情数据(2024-12-24提出)
|
|
2922
|
-
"""
|
|
2919
|
+
""" get_history_bar 查询合约指定日期前的行情数据(2024-12-24提出) """
|
|
2923
2920
|
|
|
2924
|
-
def
|
|
2925
|
-
frequency=None, fields=None
|
|
2921
|
+
def get_history_bar(self, datetime_str=None, instrument_id=None, bar_count=None,
|
|
2922
|
+
frequency=None, fields=None):
|
|
2926
2923
|
"""
|
|
2927
|
-
(此接口根据接收的参数调用不同的功能函数)
|
|
2928
2924
|
查询合约指定日期时间前的行情数据
|
|
2929
2925
|
需要程序自行判断合约代码是期货还是期权(根据期货/期权合约信息表中的 mk_instrument_id 和 instrument_id 进行筛选)
|
|
2930
2926
|
mk_instrument_id: 米筐合约代码, instrument_id: CTP合约代码
|
|
2931
2927
|
Args:
|
|
2932
|
-
datetime_str: str, 查询的日期时间,格式为'YYYY
|
|
2928
|
+
datetime_str: str, 查询的日期时间,格式为'YYYY-MM-DD HH:MM:SS'
|
|
2933
2929
|
instrument_id: str or List[str], 合约代码,可以是单个合约或合约列表
|
|
2934
2930
|
bar_count: int, 获取的历史K线数量
|
|
2935
2931
|
frequency: str, 历史行情频率,可选值:'1d'或'1m'
|
|
2936
2932
|
fields: str, 返回的数据字段,如'close_price'表示收盘价
|
|
2937
|
-
start_date: str, 开始日期,格式为'YYYY.MM.DD' (此接口根据接收的参数调用不同的功能函数)
|
|
2938
|
-
end_date: str, 结束日期,格式为'YYYY.MM.DD' (此接口根据接收的参数调用不同的功能函数)
|
|
2939
2933
|
Returns:
|
|
2940
2934
|
如果instrument_id是字符串,返回一个浮点数列表 [619.70, 620.20, 618.40, 622.00, 610.10]
|
|
2941
2935
|
如果instrument_id是列表,返回一个浮点数列表的列表 [[619.70, 620.20], [618.40, 622.00]]
|
|
@@ -2943,25 +2937,21 @@ class GJDataC:
|
|
|
2943
2937
|
ValueError: 参数验证失败时抛出
|
|
2944
2938
|
"""
|
|
2945
2939
|
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
# 参数验证
|
|
2949
|
-
self._get_history_bar_validate_params(datetime_str, instrument_id, bar_count, frequency, fields)
|
|
2940
|
+
# 参数验证
|
|
2941
|
+
self._get_history_bar_validate_params(datetime_str, instrument_id, bar_count, frequency, fields)
|
|
2950
2942
|
|
|
2951
|
-
|
|
2952
|
-
|
|
2943
|
+
# 转换日期格式
|
|
2944
|
+
query_time = self._get_history_bar_parse_datetime(datetime_str)
|
|
2953
2945
|
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2946
|
+
# 执行查询并筛选数据
|
|
2947
|
+
result, bar_db_session = self._get_history_bar_execute_query(frequency, instrument_id, query_time,
|
|
2948
|
+
bar_count)
|
|
2949
|
+
# 此处在所有的查询筛选都在数据库层面进行完后,再关闭连接
|
|
2950
|
+
# 如果将dolphindb的Table对象转换成DataFrame时,如果数据量较大,那么需要耗费的时间较长,所以尽可能将所有的筛选在数据库层面完成
|
|
2951
|
+
bar_db_session.close()
|
|
2960
2952
|
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
else:
|
|
2964
|
-
return self.get_history_bar(instrument_id, start_date, end_date, frequency, fields)
|
|
2953
|
+
# 处理结果
|
|
2954
|
+
return self._get_history_bar_process_result(result, instrument_id, fields, bar_count)
|
|
2965
2955
|
|
|
2966
2956
|
def _get_history_bar_validate_params(self, datetime_str, instrument_id, bar_count,
|
|
2967
2957
|
frequency, fields):
|
|
@@ -2979,8 +2969,8 @@ class GJDataC:
|
|
|
2979
2969
|
# 验证时间格式
|
|
2980
2970
|
if not datetime_str or not isinstance(datetime_str, str):
|
|
2981
2971
|
raise ValueError("datetime_str must be a non-empty string")
|
|
2982
|
-
|
|
2983
|
-
|
|
2972
|
+
if not self._get_history_bar_is_convertible_datetime(datetime_str):
|
|
2973
|
+
raise ValueError("datetime_str must be in the format 'YYYY-MM-DD HH:MM:SS'")
|
|
2984
2974
|
|
|
2985
2975
|
# 验证合约代码
|
|
2986
2976
|
self.general_validate_field_str_or_list(instrument_id, "instrument_id")
|
|
@@ -3076,7 +3066,6 @@ class GJDataC:
|
|
|
3076
3066
|
"""
|
|
3077
3067
|
contract_type = self.filter_contract_type(instrument_id)
|
|
3078
3068
|
|
|
3079
|
-
|
|
3080
3069
|
if contract_type == "future":
|
|
3081
3070
|
return {
|
|
3082
3071
|
"1d": (history_future_day_db_table_name, history_future_day_db_path),
|
|
@@ -3105,8 +3094,7 @@ class GJDataC:
|
|
|
3105
3094
|
"""
|
|
3106
3095
|
|
|
3107
3096
|
# 将日期转换成 DolphinDB 识别的日期格式,用于筛选数据
|
|
3108
|
-
|
|
3109
|
-
dolphin_date = datetime_str
|
|
3097
|
+
dolphin_date = self._get_history_bar_datetime_to_dolphin_time(datetime_str)
|
|
3110
3098
|
|
|
3111
3099
|
# 使用 DolphinDB 的 where 子句筛选数据(这里因为实际需求的原因需要对每个instrument_id进行筛选,所以需要使用 contextby)
|
|
3112
3100
|
# 根据bar_count 分别对不同的instrument_id 进行筛选
|
|
@@ -3174,7 +3162,7 @@ class GJDataC:
|
|
|
3174
3162
|
|
|
3175
3163
|
""" get_history_bars 查询行情指定范围日期的行情数据"""
|
|
3176
3164
|
|
|
3177
|
-
def
|
|
3165
|
+
def get_history_bars(self, instrument_id, start_date, end_date, frequency, fields=None):
|
|
3178
3166
|
"""
|
|
3179
3167
|
Args:
|
|
3180
3168
|
instrument_id: str or List[str], 合约代码,可以是单个合约或合约列表
|
|
@@ -213,15 +213,15 @@ future_margin_ratio_return_fields = ["instrument_id", "trading_day", "product_id
|
|
|
213
213
|
# 期货保证金--返回结果字段重命名
|
|
214
214
|
# qc_nexttradeparam
|
|
215
215
|
future_margin_ratio_return_fields_rename = {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
216
|
+
"instrument_id": "order_book_id", "commodity": "commodity",
|
|
217
|
+
"trading_day": "date",
|
|
218
|
+
"product_id": "commodity",
|
|
219
|
+
"exchange_id": "exchange",
|
|
220
|
+
"s_long_mrg_rate": "s_buy_margin",
|
|
221
|
+
"s_short_mrg_rate": "s_sell_margin",
|
|
222
|
+
"h_long_mrg_rate": "h_buy_margin",
|
|
223
|
+
"h_short_mrg_rate": "h_sell_margin"
|
|
224
|
+
}
|
|
225
225
|
|
|
226
226
|
# qc_future_tradeparam
|
|
227
227
|
# future_margin_ratio_return_fields_rename = {
|
|
@@ -247,11 +247,11 @@ future_limit_position_return_fields = ["instrument_id", "trading_day", "product_
|
|
|
247
247
|
# 期货保证金--返回结果字段重命名
|
|
248
248
|
# qc_nexttradeparam
|
|
249
249
|
future_limit_position_return_fields_rename = {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
250
|
+
"instrument_id": "order_book_id", "product_id": "commodity",
|
|
251
|
+
"trading_day": "date",
|
|
252
|
+
"exchange_id": "exchange",
|
|
253
|
+
"pos_limit_vol": "limit_position"
|
|
254
|
+
}
|
|
255
255
|
|
|
256
256
|
# qc_future_tradeparam
|
|
257
257
|
# 缺失字段:交易所, 持仓限额
|
|
@@ -260,4 +260,127 @@ future_limit_position_return_fields_rename = {
|
|
|
260
260
|
# "trading_day": "date",
|
|
261
261
|
# # "交易所": "exchange",
|
|
262
262
|
# # "持仓限额": "limit_position"
|
|
263
|
-
# }
|
|
263
|
+
# }
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
# 主力合约
|
|
267
|
+
|
|
268
|
+
""" 主力合约 """
|
|
269
|
+
# 主力合约--返回结果字段--dayk、mink
|
|
270
|
+
main_contract_return_fields = ["trading_day", "trade_time", "exchange_id", "instrument_id", "open_price", "close_price",
|
|
271
|
+
"highest_price", "lowest_price", "upper_limit_price", "lower_limit_price",
|
|
272
|
+
"settlement_price",
|
|
273
|
+
"pre_settlement_price", "pre_close_price", "turnover", "volume",
|
|
274
|
+
"open_interest", "total_open_interest", "total_volume", "insert_time",
|
|
275
|
+
"prev_close_spread", "open_spread", "prev_close_ratio", "open_ratio"]
|
|
276
|
+
|
|
277
|
+
# 主力合约--返回结果字段重命名--dayk、mink
|
|
278
|
+
main_contract_return_fields_rename = {
|
|
279
|
+
"trading_day": "trading_day",
|
|
280
|
+
"trade_time": "datetime",
|
|
281
|
+
"exchange_id": "exchange_id",
|
|
282
|
+
"instrument_id": "order_book_ids",
|
|
283
|
+
"open_price": "open",
|
|
284
|
+
"close_price": "close",
|
|
285
|
+
"highest_price": "high",
|
|
286
|
+
"lowest_price": "low",
|
|
287
|
+
"upper_limit_price": "limit_up",
|
|
288
|
+
"lower_limit_price": "limit_down",
|
|
289
|
+
"settlement_price": "settlement",
|
|
290
|
+
"pre_settlement_price": "prev_settlement",
|
|
291
|
+
"pre_close_price": "prev_close",
|
|
292
|
+
"turnover": "total_turnover",
|
|
293
|
+
"volume": "volume",
|
|
294
|
+
"open_interest": "open_interest",
|
|
295
|
+
"total_open_interest": "total_open_interest",
|
|
296
|
+
"total_volume": "total_volume",
|
|
297
|
+
"insert_time": "insert_time",
|
|
298
|
+
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
# 主力合约--返回结果字段--gtja_mink
|
|
303
|
+
gtja_mink_main_contract_return_fields = ["trading_day", "trade_time", "trade_timestamp",
|
|
304
|
+
"exchange_id", "instrument_id", "open_price", "close_price",
|
|
305
|
+
"highest_price", "lowest_price", "upper_limit_price", "lower_limit_price",
|
|
306
|
+
"settlement_price",
|
|
307
|
+
"pre_settlement_price", "turnover", "volume",
|
|
308
|
+
"open_interest", "insert_time", "product_id"
|
|
309
|
+
]
|
|
310
|
+
# "prev_close_spread", "open_spread", "prev_close_ratio", "open_ratio", 'pre_close_price']
|
|
311
|
+
|
|
312
|
+
# 主力合约--返回结果字段重命名--gtja_mink
|
|
313
|
+
gtja_mink_main_contract_return_fields_rename = {
|
|
314
|
+
"trading_day": "trading_day",
|
|
315
|
+
"trade_time": "datetime",
|
|
316
|
+
"exchange_id": "exchange_id",
|
|
317
|
+
"instrument_id": "order_book_ids",
|
|
318
|
+
"open_price": "open",
|
|
319
|
+
"close_price": "close",
|
|
320
|
+
"highest_price": "high",
|
|
321
|
+
"lowest_price": "low",
|
|
322
|
+
"upper_limit_price": "limit_up",
|
|
323
|
+
"lower_limit_price": "limit_down",
|
|
324
|
+
"settlement_price": "settlement",
|
|
325
|
+
"pre_settlement_price": "prev_settlement",
|
|
326
|
+
# "pre_close_price": "prev_close",
|
|
327
|
+
"turnover": "total_turnover",
|
|
328
|
+
"volume": "volume",
|
|
329
|
+
"open_interest": "open_interest",
|
|
330
|
+
# "total_open_interest": "total_open_interest",
|
|
331
|
+
# "total_volume": "total_volume",
|
|
332
|
+
"insert_time": "insert_time",
|
|
333
|
+
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
tick_main_contract_return_fields = ["trading_day", "trade_time", "exchange_id", "instrument_id", "open_price",
|
|
339
|
+
"highest_price", "lowest_price", "last_price", "upper_limit_price", "lower_limit_price",
|
|
340
|
+
"pre_settlement_price", "pre_close_price", "volume",
|
|
341
|
+
"open_interest", "turnover",
|
|
342
|
+
"ask_price1", "ask_price2", "ask_price3", "ask_price4", "ask_price5",
|
|
343
|
+
"ask_volume1", "ask_volume2", "ask_volume3", "ask_volume4", "ask_volume5",
|
|
344
|
+
"bid_price1", "bid_price2", "bid_price3", "bid_price4", "bid_price5",
|
|
345
|
+
"bid_volume1", "bid_volume2", "bid_volume3", "bid_volume4", "bid_volume5",
|
|
346
|
+
"insert_time"]
|
|
347
|
+
|
|
348
|
+
# 主力合约--返回结果字段重命名
|
|
349
|
+
tick_main_contract_return_fields_rename = {
|
|
350
|
+
"trading_day": "trading_day",
|
|
351
|
+
"trade_time": "datetime",
|
|
352
|
+
"exchange_id": "exchange_id",
|
|
353
|
+
"instrument_id": "order_book_ids",
|
|
354
|
+
"open_price": "open",
|
|
355
|
+
"highest_price": "high",
|
|
356
|
+
"lowest_price": "low",
|
|
357
|
+
"last_price": "last",
|
|
358
|
+
"upper_limit_price": "limit_up",
|
|
359
|
+
"lower_limit_price": "limit_down",
|
|
360
|
+
"pre_settlement_price": "prev_settlement",
|
|
361
|
+
"pre_close_price": "prev_close",
|
|
362
|
+
"volume": "volume",
|
|
363
|
+
"open_interest": "open_interest",
|
|
364
|
+
'ask_price1': 'a1',
|
|
365
|
+
'ask_price2': 'a2',
|
|
366
|
+
'ask_price3': 'a3',
|
|
367
|
+
'ask_price4': 'a4',
|
|
368
|
+
'ask_price5': 'a5',
|
|
369
|
+
'ask_volume1': 'a1_v',
|
|
370
|
+
'ask_volume2': 'a2_v',
|
|
371
|
+
'ask_volume3': 'a3_v',
|
|
372
|
+
'ask_volume4': 'a4_v',
|
|
373
|
+
'ask_volume5': 'a5_v',
|
|
374
|
+
'bid_price1': 'b1',
|
|
375
|
+
'bid_price2': 'b2',
|
|
376
|
+
'bid_price3': 'b3',
|
|
377
|
+
'bid_price4': 'b4',
|
|
378
|
+
'bid_price5': 'b5',
|
|
379
|
+
'bid_volume1': 'b1_v',
|
|
380
|
+
'bid_volume2': 'b2_v',
|
|
381
|
+
'bid_volume3': 'b3_v',
|
|
382
|
+
'bid_volume4': 'b4_v',
|
|
383
|
+
'bid_volume5': 'b5_v',
|
|
384
|
+
"insert_time": "insert_time",
|
|
385
|
+
|
|
386
|
+
}
|
|
@@ -5,7 +5,7 @@ with open('description_info.md', 'r', encoding='utf-8') as f:
|
|
|
5
5
|
|
|
6
6
|
setup(
|
|
7
7
|
name='gjdatac_api', # 你的包名
|
|
8
|
-
version='0.
|
|
8
|
+
version='0.2.0', # 版本号
|
|
9
9
|
description='数据接口打包', # 包的简要描述
|
|
10
10
|
long_description=long_description, # 包的详细描述
|
|
11
11
|
long_description_content_type='text/markdown', # 描述文件的类型
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|