gjdatac-api 0.3.7__tar.gz → 0.3.8__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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gjdatac_api
3
- Version: 0.3.7
3
+ Version: 0.3.8
4
4
  Summary: 数据接口打包
5
5
  Author: fml
6
6
  Author-email: 13306510996@163.com
@@ -1078,7 +1078,7 @@ class GJDataC:
1078
1078
  option_contract_db_table_name,
1079
1079
  option_contract_db_path)
1080
1080
  data["type"] = "option"
1081
- data["exercise_type"] = data["optionstype"]
1081
+ data["exercise_type"] = data["option_stype"]
1082
1082
  else:
1083
1083
  raise Exception("asset_type is not valid")
1084
1084
  data["commodity"] = ""
@@ -1123,24 +1123,64 @@ class GJDataC:
1123
1123
 
1124
1124
  def get_instruments_deal_commodity_trading_hour(self, data):
1125
1125
  """
1126
- qc_nexttradeparam
1127
- 用于处理commodity和trading_hour
1126
+ 从合约基础信息表获取 commodity,从 qc_product 表获取 trading_hour
1127
+ 期货查 qc_futinstrument,期权查 qc_optinstrument
1128
1128
  :param data: 数据
1129
1129
  :return: data: 处理后的数据
1130
1130
  """
1131
1131
 
1132
1132
  try:
1133
- # 获取交易参数
1134
- trading_param_data, db_session = self.connect_db(trading_params_db_table_name, trading_params_db_path)
1135
- for index, row in data.iterrows():
1136
- match = trading_param_data.toDF()[trading_param_data.toDF()['instrument_id'] == row['order_book_id']]
1137
- # match = trading_param_data.toDF()[trading_param_data.toDF()['contractcode'] == row['order_book_id']]
1138
-
1139
- if not match.empty:
1140
- # data.loc[index, 'commodity'] = match['productcode'].iloc[0]
1141
- # data.loc[index, 'trading_hour'] = match['tradesection'].iloc[0]
1142
- data.loc[index, 'commodity'] = match['product_id'].iloc[0]
1143
- data.loc[index, 'trading_hour'] = match['trade_section'].iloc[0]
1133
+ unique_ids = data['order_book_id'].unique().tolist()
1134
+
1135
+ # 根据合约类型选择基础信息表
1136
+ if 'type' in data.columns and data['type'].iloc[0] == 'option':
1137
+ table_name = option_contract_db_table_name
1138
+ else:
1139
+ table_name = future_contract_db_table_name
1140
+ contract_data, db_session = self.connect_db(table_name, future_contract_db_path)
1141
+
1142
+ filtered = contract_data.select("*").where(
1143
+ "instrument_id in {}".format(unique_ids)
1144
+ ).toDF()
1145
+
1146
+ if not filtered.empty:
1147
+ # 从基础信息表取 product_id 作为 commodity
1148
+ lookup = filtered[['instrument_id', 'product_id']].rename(
1149
+ columns={'product_id': '_commodity'}
1150
+ )
1151
+ lookup = lookup.drop_duplicates(subset=['instrument_id'], keep='first')
1152
+
1153
+ data = data.merge(
1154
+ lookup,
1155
+ left_on='order_book_id',
1156
+ right_on='instrument_id',
1157
+ how='left'
1158
+ )
1159
+ data['commodity'] = data['_commodity']
1160
+ data.drop(columns=['instrument_id', '_commodity'], inplace=True, errors='ignore')
1161
+
1162
+ # 用 product_id 关联 qc_product 表获取 trade_section 作为 trading_hour
1163
+ unique_products = data['commodity'].dropna().unique().tolist()
1164
+ if unique_products:
1165
+ product_data, product_session = self.connect_db(product_db_table_name, product_db_path)
1166
+ product_filtered = product_data.select("*").where(
1167
+ "product_id in {}".format(unique_products)
1168
+ ).toDF()
1169
+ if not product_filtered.empty:
1170
+ product_lookup = product_filtered[['product_id', 'trade_section']].rename(
1171
+ columns={'trade_section': '_trading_hour'}
1172
+ )
1173
+ product_lookup = product_lookup.drop_duplicates(subset=['product_id'], keep='first')
1174
+ data = data.merge(
1175
+ product_lookup,
1176
+ left_on='commodity',
1177
+ right_on='product_id',
1178
+ how='left'
1179
+ )
1180
+ data['trading_hour'] = data['_trading_hour']
1181
+ data.drop(columns=['product_id', '_trading_hour'], inplace=True, errors='ignore')
1182
+ product_session.close()
1183
+
1144
1184
  db_session.close()
1145
1185
  except ValueError as e:
1146
1186
  print(e)
@@ -145,7 +145,7 @@ get_instruments_type_dict = {
145
145
  # "": "commodity",
146
146
  "open_date": "listed_date", "expire_date": "maturity_date", "delivery_month": "delivery_month",
147
147
  "start_deliv_date": "start_delivery", "end_deliv_date": "end_delivery", "delisting_date": "de_listed_date",
148
- "option_stype": "option_type", "strike_price": "strike_price",
148
+ "option_type": "option_type", "strike_price": "strike_price",
149
149
  "underlying_instrument_id": "underlying_order_book_id",
150
150
  "volume_multiple": "contract_multiplier",
151
151
  # "trading_hour": "trading_hour"
@@ -146,5 +146,10 @@ inventory_db_table_name = "qc_product_inventory" # 表名
146
146
  subscribe_min_db_table_name = "QcMinKlineTable" # 表名
147
147
 
148
148
 
149
+ # 品种信息(含交易时间段)
150
+ product_db_path = "dfs://basicinfo" # 数据库路径
151
+ product_db_table_name = "qc_product" # 表名
152
+
153
+
149
154
 
150
155
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gjdatac_api
3
- Version: 0.3.7
3
+ Version: 0.3.8
4
4
  Summary: 数据接口打包
5
5
  Author: fml
6
6
  Author-email: 13306510996@163.com
@@ -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.3.7', # 版本号
8
+ version='0.3.8', # 版本号
9
9
  description='数据接口打包', # 包的简要描述
10
10
  long_description=long_description, # 包的详细描述
11
11
  long_description_content_type='text/markdown', # 描述文件的类型
File without changes