gjdatac-api 0.2.0__tar.gz → 0.2.1__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.2.0 → gjdatac_api-0.2.1}/PKG-INFO +1 -1
- {gjdatac_api-0.2.0 → gjdatac_api-0.2.1}/gjdatac_api/data_api_class.py +35 -23
- {gjdatac_api-0.2.0 → gjdatac_api-0.2.1}/gjdatac_api.egg-info/PKG-INFO +1 -1
- {gjdatac_api-0.2.0 → gjdatac_api-0.2.1}/setup.py +1 -1
- {gjdatac_api-0.2.0 → gjdatac_api-0.2.1}/gjdatac_api/__init__.py +0 -0
- {gjdatac_api-0.2.0 → gjdatac_api-0.2.1}/gjdatac_api/dict_data.py +0 -0
- {gjdatac_api-0.2.0 → gjdatac_api-0.2.1}/gjdatac_api/dolphindb_info.py +0 -0
- {gjdatac_api-0.2.0 → gjdatac_api-0.2.1}/gjdatac_api/instrument_class.py +0 -0
- {gjdatac_api-0.2.0 → gjdatac_api-0.2.1}/gjdatac_api.egg-info/SOURCES.txt +0 -0
- {gjdatac_api-0.2.0 → gjdatac_api-0.2.1}/gjdatac_api.egg-info/dependency_links.txt +0 -0
- {gjdatac_api-0.2.0 → gjdatac_api-0.2.1}/gjdatac_api.egg-info/requires.txt +0 -0
- {gjdatac_api-0.2.0 → gjdatac_api-0.2.1}/gjdatac_api.egg-info/top_level.txt +0 -0
- {gjdatac_api-0.2.0 → gjdatac_api-0.2.1}/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 .dict_data import (get_price_frequency_dict, get_price_data_type_dict, get_instruments_type_dict,
|
|
13
|
+
from utils.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 .dict_data import (get_price_frequency_dict, get_price_data_type_dict, get_
|
|
|
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 .dolphindb_info import *
|
|
22
|
-
from .instrument_class import Instrument
|
|
21
|
+
from utils.dolphindb_info import *
|
|
22
|
+
from utils.instrument_class import Instrument
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
class GJDataC:
|
|
@@ -2916,20 +2916,26 @@ class GJDataC:
|
|
|
2916
2916
|
except Exception as e:
|
|
2917
2917
|
raise e
|
|
2918
2918
|
|
|
2919
|
-
"""
|
|
2919
|
+
"""
|
|
2920
|
+
get_history_bars 此接口和下面的接口合并为一个,根据传入的参数进行判断,调用不同的方法
|
|
2921
|
+
查询合约指定日期前的行情数据(2024-12-24提出)
|
|
2922
|
+
"""
|
|
2920
2923
|
|
|
2921
|
-
def
|
|
2922
|
-
frequency=None, fields=None):
|
|
2924
|
+
def get_history_bars(self, datetime_str=None, instrument_id=None, bar_count=None,
|
|
2925
|
+
frequency=None, fields=None, start_date=None, end_date=None):
|
|
2923
2926
|
"""
|
|
2927
|
+
(此接口根据接收的参数调用不同的功能函数)
|
|
2924
2928
|
查询合约指定日期时间前的行情数据
|
|
2925
2929
|
需要程序自行判断合约代码是期货还是期权(根据期货/期权合约信息表中的 mk_instrument_id 和 instrument_id 进行筛选)
|
|
2926
2930
|
mk_instrument_id: 米筐合约代码, instrument_id: CTP合约代码
|
|
2927
2931
|
Args:
|
|
2928
|
-
datetime_str: str, 查询的日期时间,格式为'YYYY
|
|
2932
|
+
datetime_str: str, 查询的日期时间,格式为'YYYY.MM.DD'
|
|
2929
2933
|
instrument_id: str or List[str], 合约代码,可以是单个合约或合约列表
|
|
2930
2934
|
bar_count: int, 获取的历史K线数量
|
|
2931
2935
|
frequency: str, 历史行情频率,可选值:'1d'或'1m'
|
|
2932
2936
|
fields: str, 返回的数据字段,如'close_price'表示收盘价
|
|
2937
|
+
start_date: str, 开始日期,格式为'YYYY.MM.DD' (此接口根据接收的参数调用不同的功能函数)
|
|
2938
|
+
end_date: str, 结束日期,格式为'YYYY.MM.DD' (此接口根据接收的参数调用不同的功能函数)
|
|
2933
2939
|
Returns:
|
|
2934
2940
|
如果instrument_id是字符串,返回一个浮点数列表 [619.70, 620.20, 618.40, 622.00, 610.10]
|
|
2935
2941
|
如果instrument_id是列表,返回一个浮点数列表的列表 [[619.70, 620.20], [618.40, 622.00]]
|
|
@@ -2937,21 +2943,25 @@ class GJDataC:
|
|
|
2937
2943
|
ValueError: 参数验证失败时抛出
|
|
2938
2944
|
"""
|
|
2939
2945
|
|
|
2940
|
-
|
|
2941
|
-
|
|
2946
|
+
''' 根据参数的不同,调用不同的函数 '''
|
|
2947
|
+
if datetime_str and bar_count:
|
|
2948
|
+
# 参数验证
|
|
2949
|
+
self._get_history_bar_validate_params(datetime_str, instrument_id, bar_count, frequency, fields)
|
|
2942
2950
|
|
|
2943
|
-
|
|
2944
|
-
|
|
2951
|
+
# 转换日期格式
|
|
2952
|
+
# query_time = self._get_history_bar_parse_datetime(datetime_str)
|
|
2945
2953
|
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2954
|
+
# 执行查询并筛选数据
|
|
2955
|
+
result, bar_db_session = self._get_history_bar_execute_query(frequency, instrument_id, datetime_str,
|
|
2956
|
+
bar_count)
|
|
2957
|
+
# 此处在所有的查询筛选都在数据库层面进行完后,再关闭连接
|
|
2958
|
+
# 如果将dolphindb的Table对象转换成DataFrame时,如果数据量较大,那么需要耗费的时间较长,所以尽可能将所有的筛选在数据库层面完成
|
|
2959
|
+
bar_db_session.close()
|
|
2952
2960
|
|
|
2953
|
-
|
|
2954
|
-
|
|
2961
|
+
# 处理结果
|
|
2962
|
+
return self._get_history_bar_process_result(result, instrument_id, fields, bar_count)
|
|
2963
|
+
else:
|
|
2964
|
+
return self.get_history_bar(instrument_id, start_date, end_date, frequency, fields)
|
|
2955
2965
|
|
|
2956
2966
|
def _get_history_bar_validate_params(self, datetime_str, instrument_id, bar_count,
|
|
2957
2967
|
frequency, fields):
|
|
@@ -2969,8 +2979,8 @@ class GJDataC:
|
|
|
2969
2979
|
# 验证时间格式
|
|
2970
2980
|
if not datetime_str or not isinstance(datetime_str, str):
|
|
2971
2981
|
raise ValueError("datetime_str must be a non-empty string")
|
|
2972
|
-
if not self._get_history_bar_is_convertible_datetime(datetime_str):
|
|
2973
|
-
|
|
2982
|
+
# if not self._get_history_bar_is_convertible_datetime(datetime_str):
|
|
2983
|
+
# raise ValueError("datetime_str must be in the format 'YYYY-MM-DD HH:MM:SS'")
|
|
2974
2984
|
|
|
2975
2985
|
# 验证合约代码
|
|
2976
2986
|
self.general_validate_field_str_or_list(instrument_id, "instrument_id")
|
|
@@ -3066,6 +3076,7 @@ class GJDataC:
|
|
|
3066
3076
|
"""
|
|
3067
3077
|
contract_type = self.filter_contract_type(instrument_id)
|
|
3068
3078
|
|
|
3079
|
+
|
|
3069
3080
|
if contract_type == "future":
|
|
3070
3081
|
return {
|
|
3071
3082
|
"1d": (history_future_day_db_table_name, history_future_day_db_path),
|
|
@@ -3094,7 +3105,8 @@ class GJDataC:
|
|
|
3094
3105
|
"""
|
|
3095
3106
|
|
|
3096
3107
|
# 将日期转换成 DolphinDB 识别的日期格式,用于筛选数据
|
|
3097
|
-
dolphin_date = self._get_history_bar_datetime_to_dolphin_time(datetime_str)
|
|
3108
|
+
# dolphin_date = self._get_history_bar_datetime_to_dolphin_time(datetime_str)
|
|
3109
|
+
dolphin_date = datetime_str
|
|
3098
3110
|
|
|
3099
3111
|
# 使用 DolphinDB 的 where 子句筛选数据(这里因为实际需求的原因需要对每个instrument_id进行筛选,所以需要使用 contextby)
|
|
3100
3112
|
# 根据bar_count 分别对不同的instrument_id 进行筛选
|
|
@@ -3162,7 +3174,7 @@ class GJDataC:
|
|
|
3162
3174
|
|
|
3163
3175
|
""" get_history_bars 查询行情指定范围日期的行情数据"""
|
|
3164
3176
|
|
|
3165
|
-
def
|
|
3177
|
+
def get_history_bar(self, instrument_id, start_date, end_date, frequency, fields=None):
|
|
3166
3178
|
"""
|
|
3167
3179
|
Args:
|
|
3168
3180
|
instrument_id: str or List[str], 合约代码,可以是单个合约或合约列表
|
|
@@ -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.2.
|
|
8
|
+
version='0.2.1', # 版本号
|
|
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
|
|
File without changes
|