gjdatac-api 0.0.1__tar.gz → 0.0.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gjdatac_api
3
- Version: 0.0.1
3
+ Version: 0.0.3
4
4
  Summary: 主动管理项目第一版(部分接口)
5
5
  Home-page: UNKNOWN
6
6
  Author: yin
@@ -1,3 +1,4 @@
1
1
  from .data_api_class import GJDataC
2
2
 
3
- __all__ = ['GJDataC']
3
+ __all__ = ['GJDataC']
4
+
@@ -12,20 +12,25 @@ from .dolphin_db_info import *
12
12
 
13
13
  class GJDataC:
14
14
 
15
- def __init__(self):
15
+ def __init__(self, host, port, user_id, password):
16
16
  """
17
17
  用于定义一些不同接口所需的变量以及一些初始化操作
18
18
  """
19
19
 
20
+ ''' 初始化校验 '''
20
21
  # 数据库参数
21
- # self.host = HOST
22
- # self.port = PORT
23
- # self.user_id = USER_ID
24
- # self.password = PASSWORD
22
+ self.host = host
23
+ self.port = port
24
+ self.user_id = user_id
25
+ self.password = password
25
26
 
26
27
  # 连接数据库
27
- # self.db_session = ddb.session()
28
- # self.db_session.connect(self.host, self.port, self.user_id, self.password)
28
+ try:
29
+ self.db_session = ddb.session()
30
+ self.db_session.connect(self.host, self.port, self.user_id, self.password)
31
+ self.db_session.close()
32
+ except Exception as e:
33
+ raise Exception("please check your database connection information")
29
34
 
30
35
  ''' get_price 接口相关属性 '''
31
36
  self.get_price_data = None # 用于存放get_price接口数据
@@ -312,16 +317,6 @@ class GJDataC:
312
317
  self.general_validate_params_required(order_book_ids, "order_book_ids") # 校验必填参数
313
318
  self.general_validate_field_str_or_list(order_book_ids, "order_book_ids") # 校验参数类型
314
319
 
315
- # def get_price_filter_by_order_book_ids(self, order_book_ids):
316
- # """
317
- # 根据order_book_ids筛选数据
318
- # """
319
- # if isinstance(order_book_ids, str):
320
- # self.get_price_data = self.get_price_data[self.get_price_data["order_book_ids"] == order_book_ids]
321
- # elif isinstance(order_book_ids, list):
322
- # self.get_price_data = self.get_price_data[self.get_price_data["order_book_ids"].isin(order_book_ids)]
323
- # return self.get_price_data
324
-
325
320
  def __get_price_validate_frequency(self, frequency):
326
321
  """
327
322
  对frequency进行校验
@@ -581,47 +576,36 @@ class GJDataC:
581
576
  def __get_price_data_get_data(self, order_book_ids, asset_type, frequency):
582
577
  """
583
578
  根据参数获取数据库和表名,调用接口获取数据
584
-
579
+
585
580
  :param order_book_ids: 合约代码列表
586
581
  :param asset_type: 合约类型
587
582
  :param frequency: 频率
588
583
  :return: None
589
584
  """
590
585
 
591
- ''' 期货行情数据 '''
592
- if asset_type == "future":
593
- if frequency == "tick_l1": # 期货l1级别tick行情数据
594
- self.get_price_data = self._get_price_get_data(order_book_ids, history_future_tick_db_table_name,
595
- history_future_tick_db_path)
596
- elif frequency == "1d": # 期货日bar行情数据
597
- self.get_price_data = self._get_price_get_data(order_book_ids, history_future_day_db_table_name,
598
- history_future_day_db_path)
599
- elif frequency == "1min": # 期货分钟bar行情数据
600
- self.get_price_data = self._get_price_get_data(order_book_ids, history_future_min_db_table_name,
601
- history_future_min_db_path)
602
- # 数据库暂无数据
603
- # elif frequency == "1min_gtja": # 公司合成的分钟bar行情数据
604
- # self.get_price_data = self._get_price_get_data(order_book_ids, history_future_min_gtja_db_table_name,
605
- # history_future_min_gtja_db_path)
606
- # elif frequency == "tick_l2": # 期货l2级别tick行情数据
607
- # self.get_price_data = self._get_price_get_data(order_book_ids, history_future_tick_l2_db_table_name,
608
- # history_future_tick_l2_db_path)
609
- # else:
610
- # raise Exception("frequency is not valid for future contract")
611
- elif asset_type == "option":
612
- if frequency == "1d": # 期权日bar行情数据
613
- self.get_price_data = self._get_price_get_data(order_book_ids, history_option_day_db_table_name,
614
- history_option_day_db_path)
615
- elif frequency == "1min": # 期权分钟bar行情数据
616
- self.get_price_data = self._get_price_get_data(order_book_ids, history_option_min_db_table_name,
617
- history_option_min_db_path)
618
- elif frequency == "tick": # 期权tick行情数据
619
- self.get_price_data = self._get_price_get_data(order_book_ids, history_option_tick_db_table_name,
620
- history_option_tick_db_path)
586
+ def get_db_table_name(asset_type, frequency):
587
+ if asset_type == "future":
588
+ return {
589
+ "tick_l1": (history_future_tick_db_table_name, history_future_tick_db_path),
590
+ "1d": (history_future_day_db_table_name, history_future_day_db_path),
591
+ "1min": (history_future_min_db_table_name, history_future_min_db_path),
592
+ # "1min_gtja": (history_future_min_gtja_db_table_name, history_future_min_gtja_db_path),
593
+ # "tick_l2": (history_future_tick_l2_db_table_name, history_future_tick_l2_db_path),
594
+ }.get(frequency)
595
+ elif asset_type == "option":
596
+ return {
597
+ "1d": (history_option_day_db_table_name, history_option_day_db_path),
598
+ "1min": (history_option_min_db_table_name, history_option_min_db_path),
599
+ "tick": (history_option_tick_db_table_name, history_option_tick_db_path),
600
+ }.get(frequency)
621
601
  else:
622
- raise Exception("frequency is not valid for option contract")
623
- else:
624
- raise Exception("asset_type is not valid")
602
+ raise Exception("asset_type is not valid")
603
+
604
+ db_table_name = get_db_table_name(asset_type, frequency)
605
+ if db_table_name is None:
606
+ raise Exception("frequency is not valid for this asset_type")
607
+
608
+ self.get_price_data = self._get_price_get_data(order_book_ids, *db_table_name)
625
609
 
626
610
  """ get_instruments(合约基础信息) """
627
611
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gjdatac-api
3
- Version: 0.0.1
3
+ Version: 0.0.3
4
4
  Summary: 主动管理项目第一版(部分接口)
5
5
  Home-page: UNKNOWN
6
6
  Author: yin
@@ -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.0.1', # 版本号
8
+ version='0.0.3', # 版本号
9
9
  description='主动管理项目第一版(部分接口)', # 包的简要描述
10
10
  long_description=long_description, # 包的详细描述
11
11
  long_description_content_type='text/markdown', # 描述文件的类型
File without changes