gjdatac-api 0.1.7__tar.gz → 0.1.9__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.

@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gjdatac_api
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: 数据接口打包
5
5
  Author: yin
6
6
  Author-email: 2018209921@qq.com
7
7
  Requires-Python: >3.6
8
8
  Description-Content-Type: text/markdown
9
9
 
10
- ### 新增主力合约接口
10
+ ### 合并接口、修改日期入参格式
@@ -15,7 +15,8 @@ from utils.dict_data import (get_price_frequency_dict, get_price_data_type_dict,
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,
17
17
  main_contract_return_fields, main_contract_return_fields_rename,
18
- tick_main_contract_return_fields, tick_main_contract_return_fields_rename
18
+ tick_main_contract_return_fields, tick_main_contract_return_fields_rename,
19
+ gtja_mink_main_contract_return_fields, gtja_mink_main_contract_return_fields_rename
19
20
  )
20
21
  from utils.dolphindb_info import *
21
22
  from utils.instrument_class import Instrument
@@ -44,7 +45,6 @@ class GJDataC:
44
45
  # 创建向量,包含所有可用节点的地址和端口
45
46
  self.sites = dolphindb_service
46
47
 
47
-
48
48
  def connect_db(self, table_name, db_path):
49
49
  """
50
50
  此方法用于根据不同的数据表及数据库获取数据,只返回Table对象,对应的数据处理在对应的数据接口处理
@@ -60,7 +60,7 @@ class GJDataC:
60
60
 
61
61
  # 创建连接;开启高可用,并指定sites为所有可用节点的ip:port
62
62
  success = db_session.connect(self.host, self.port, self.user_id, self.password, highAvailability=True,
63
- highAvailabilitySites=self.sites)
63
+ highAvailabilitySites=self.sites)
64
64
  if not success:
65
65
  raise Exception("please check your database connection information")
66
66
 
@@ -1767,7 +1767,7 @@ class GJDataC:
1767
1767
  return {
1768
1768
  '1d': (qc_future_maincontract_dayk, dayk_future_maincontract_db),
1769
1769
  '1min': (qc_future_maincontract_minutek, minutek_future_maincontract_db),
1770
- '1min_gtja': (qc_future_maincontract_minutek, minutek_future_maincontract_db)
1770
+ '1min_gtja': (qc_future_maincontract_gtja_minutek, minutek_future_maincontract_gtja_db)
1771
1771
  }.get(frequency, (None, None))
1772
1772
 
1773
1773
  @staticmethod
@@ -1938,9 +1938,12 @@ class GJDataC:
1938
1938
  """
1939
1939
  new_df = data.copy()
1940
1940
 
1941
- if frequency in ['1min', '1d', '1min_gtja']:
1941
+ if frequency in ['1min', '1d']:
1942
1942
  return_fields = main_contract_return_fields
1943
1943
  return_fields_rename = main_contract_return_fields_rename
1944
+ elif frequency in ['1min_gtja']:
1945
+ return_fields = gtja_mink_main_contract_return_fields
1946
+ return_fields_rename = gtja_mink_main_contract_return_fields_rename
1944
1947
  else:
1945
1948
  return_fields = tick_main_contract_return_fields
1946
1949
  return_fields_rename = tick_main_contract_return_fields_rename
@@ -1951,10 +1954,12 @@ class GJDataC:
1951
1954
  # 将实际数据字段转换成需求文档中指定的字段
1952
1955
  new_df.rename(columns=return_fields_rename, inplace=True)
1953
1956
 
1954
- if frequency in ['1min', '1d', '1min_gtja']:
1957
+ if frequency in ['1min', '1d']:
1955
1958
  new_df['none_close'] = new_df['close']
1956
1959
  new_df['none_prev_close'] = new_df['prev_close']
1957
1960
  new_df['ex_factor'] = ex_factor
1961
+ elif frequency in ['1min_gtja']:
1962
+ new_df['ex_factor'] = ex_factor
1958
1963
  else:
1959
1964
  new_df['total_turnover'] = new_df.groupby(['order_book_ids', 'trading_day'])['turnover'].transform('sum')
1960
1965
 
@@ -1971,7 +1976,7 @@ class GJDataC:
1971
1976
  :return: 计算后的数据
1972
1977
  """
1973
1978
 
1974
- if not adjust_type or frequency in ['tick_l1', 'tick_l2']:
1979
+ if not adjust_type or frequency in ['tick_l1', 'tick_l2', '1min_gtja']:
1975
1980
  return data
1976
1981
 
1977
1982
  adjust_fields = ['open', 'close', 'high', 'low', 'limit_up', 'limit_down', 'settlement', 'prev_settlement',
@@ -2911,20 +2916,26 @@ class GJDataC:
2911
2916
  except Exception as e:
2912
2917
  raise e
2913
2918
 
2914
- """ get_history_bar 查询合约指定日期前的行情数据(2024-12-24提出) """
2919
+ """
2920
+ get_history_bars 此接口和下面的接口合并为一个,根据传入的参数进行判断,调用不同的方法
2921
+ 查询合约指定日期前的行情数据(2024-12-24提出)
2922
+ """
2915
2923
 
2916
- def get_history_bar(self, datetime_str=None, instrument_id=None, bar_count=None,
2917
- 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):
2918
2926
  """
2927
+ (此接口根据接收的参数调用不同的功能函数)
2919
2928
  查询合约指定日期时间前的行情数据
2920
2929
  需要程序自行判断合约代码是期货还是期权(根据期货/期权合约信息表中的 mk_instrument_id 和 instrument_id 进行筛选)
2921
2930
  mk_instrument_id: 米筐合约代码, instrument_id: CTP合约代码
2922
2931
  Args:
2923
- datetime_str: str, 查询的日期时间,格式为'YYYY-MM-DD HH:MM:SS'
2932
+ datetime_str: str, 查询的日期时间,格式为'YYYY.MM.DD'
2924
2933
  instrument_id: str or List[str], 合约代码,可以是单个合约或合约列表
2925
2934
  bar_count: int, 获取的历史K线数量
2926
2935
  frequency: str, 历史行情频率,可选值:'1d'或'1m'
2927
2936
  fields: str, 返回的数据字段,如'close_price'表示收盘价
2937
+ start_date: str, 开始日期,格式为'YYYY.MM.DD' (此接口根据接收的参数调用不同的功能函数)
2938
+ end_date: str, 结束日期,格式为'YYYY.MM.DD' (此接口根据接收的参数调用不同的功能函数)
2928
2939
  Returns:
2929
2940
  如果instrument_id是字符串,返回一个浮点数列表 [619.70, 620.20, 618.40, 622.00, 610.10]
2930
2941
  如果instrument_id是列表,返回一个浮点数列表的列表 [[619.70, 620.20], [618.40, 622.00]]
@@ -2932,21 +2943,25 @@ class GJDataC:
2932
2943
  ValueError: 参数验证失败时抛出
2933
2944
  """
2934
2945
 
2935
- # 参数验证
2936
- self._get_history_bar_validate_params(datetime_str, instrument_id, bar_count, frequency, fields)
2946
+ ''' 根据参数的不同,调用不同的函数 '''
2947
+ if datetime_str and bar_count:
2948
+ # 参数验证
2949
+ self._get_history_bar_validate_params(datetime_str, instrument_id, bar_count, frequency, fields)
2937
2950
 
2938
- # 转换日期格式
2939
- query_time = self._get_history_bar_parse_datetime(datetime_str)
2951
+ # 转换日期格式
2952
+ # query_time = self._get_history_bar_parse_datetime(datetime_str)
2940
2953
 
2941
- # 执行查询并筛选数据
2942
- result, bar_db_session = self._get_history_bar_execute_query(frequency, instrument_id, query_time,
2943
- bar_count)
2944
- # 此处在所有的查询筛选都在数据库层面进行完后,再关闭连接
2945
- # 如果将dolphindb的Table对象转换成DataFrame时,如果数据量较大,那么需要耗费的时间较长,所以尽可能将所有的筛选在数据库层面完成
2946
- bar_db_session.close()
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()
2947
2960
 
2948
- # 处理结果
2949
- return self._get_history_bar_process_result(result, instrument_id, fields, bar_count)
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)
2950
2965
 
2951
2966
  def _get_history_bar_validate_params(self, datetime_str, instrument_id, bar_count,
2952
2967
  frequency, fields):
@@ -2964,8 +2979,8 @@ class GJDataC:
2964
2979
  # 验证时间格式
2965
2980
  if not datetime_str or not isinstance(datetime_str, str):
2966
2981
  raise ValueError("datetime_str must be a non-empty string")
2967
- if not self._get_history_bar_is_convertible_datetime(datetime_str):
2968
- raise ValueError("datetime_str must be in the format 'YYYY-MM-DD HH:MM:SS'")
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'")
2969
2984
 
2970
2985
  # 验证合约代码
2971
2986
  self.general_validate_field_str_or_list(instrument_id, "instrument_id")
@@ -3061,6 +3076,7 @@ class GJDataC:
3061
3076
  """
3062
3077
  contract_type = self.filter_contract_type(instrument_id)
3063
3078
 
3079
+
3064
3080
  if contract_type == "future":
3065
3081
  return {
3066
3082
  "1d": (history_future_day_db_table_name, history_future_day_db_path),
@@ -3089,7 +3105,8 @@ class GJDataC:
3089
3105
  """
3090
3106
 
3091
3107
  # 将日期转换成 DolphinDB 识别的日期格式,用于筛选数据
3092
- 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
3093
3110
 
3094
3111
  # 使用 DolphinDB 的 where 子句筛选数据(这里因为实际需求的原因需要对每个instrument_id进行筛选,所以需要使用 contextby)
3095
3112
  # 根据bar_count 分别对不同的instrument_id 进行筛选
@@ -3157,7 +3174,7 @@ class GJDataC:
3157
3174
 
3158
3175
  """ get_history_bars 查询行情指定范围日期的行情数据"""
3159
3176
 
3160
- def get_history_bars(self, instrument_id, start_date, end_date, frequency, fields=None):
3177
+ def get_history_bar(self, instrument_id, start_date, end_date, frequency, fields=None):
3161
3178
  """
3162
3179
  Args:
3163
3180
  instrument_id: str or List[str], 合约代码,可以是单个合约或合约列表
@@ -101,7 +101,21 @@ get_warehouse_stocks_future_db_table_name = "qc_warehouse_stocks" # 表名(
101
101
 
102
102
  # 主力合约
103
103
  main_contract_db_path = "dfs://dayk" # 数据库路径
104
- main_contract_db_table_name = "qc_future_maincontract" # 表名
104
+ main_contract_db_table_name = "qc_gtja_future_maincontract" # 表名
105
+
106
+ # 主/次力合约
107
+ dayk_future_maincontract_db = "dfs://dayk_future_maincontract"
108
+ minutek_future_maincontract_db = "dfs://minutek_future_maincontract"
109
+ minutek_future_maincontract_gtja_db = "dfs://minutek"
110
+
111
+ qc_future_maincontract_dayk = "qc_future_maincontract_dayk"
112
+ qc_future_maincontract_minutek = "qc_future_maincontract_mink"
113
+ qc_future_maincontract_gtja_minutek = "qc_gtja_future_mink"
114
+
115
+
116
+ tick_main_contract_db_path = "dfs://tick" # 数据库路径
117
+ tick_main_contract_db_table_name = "qc_future_tick" # 表名
118
+
105
119
 
106
120
  # 期货交割手续费(目前需求中所需的字段在交易参数表中都存在,所以直接使用交易参数表)
107
121
  delivery_fee_db_path = "dfs://basicinfo" # 数据库路径
@@ -132,5 +146,6 @@ inventory_db_table_name = "qc_product_inventory" # 表名
132
146
  subscribe_min_db_table_name = "QcMinKlineTable" # 表名
133
147
 
134
148
 
135
- ''' 仿真 '''
149
+
150
+ ''' 仿真服务器 '''
136
151
  dolphindb_service = ["10.74.56.101:8902", "10.74.56.102:8902", "10.74.56.103:8902"]
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gjdatac-api
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: 数据接口打包
5
5
  Author: yin
6
6
  Author-email: 2018209921@qq.com
7
7
  Requires-Python: >3.6
8
8
  Description-Content-Type: text/markdown
9
9
 
10
- ### 新增主力合约接口
10
+ ### 合并接口、修改日期入参格式
@@ -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.1.7', # 版本号
8
+ version='0.1.9', # 版本号
9
9
  description='数据接口打包', # 包的简要描述
10
10
  long_description=long_description, # 包的详细描述
11
11
  long_description_content_type='text/markdown', # 描述文件的类型
File without changes