gjdatac-api 0.0.7__tar.gz → 0.0.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.
- {gjdatac_api-0.0.7 → gjdatac_api-0.0.9}/PKG-INFO +1 -1
- {gjdatac_api-0.0.7 → gjdatac_api-0.0.9}/gjdatac_api/data_api_class.py +86 -69
- {gjdatac_api-0.0.7 → gjdatac_api-0.0.9}/gjdatac_api/dolphin_db_info.py +4 -0
- {gjdatac_api-0.0.7 → gjdatac_api-0.0.9}/gjdatac_api.egg-info/PKG-INFO +1 -1
- {gjdatac_api-0.0.7 → gjdatac_api-0.0.9}/setup.py +1 -1
- {gjdatac_api-0.0.7 → gjdatac_api-0.0.9}/gjdatac_api/__init__.py +0 -0
- {gjdatac_api-0.0.7 → gjdatac_api-0.0.9}/gjdatac_api/dict_data.py +0 -0
- {gjdatac_api-0.0.7 → gjdatac_api-0.0.9}/gjdatac_api.egg-info/SOURCES.txt +0 -0
- {gjdatac_api-0.0.7 → gjdatac_api-0.0.9}/gjdatac_api.egg-info/dependency_links.txt +0 -0
- {gjdatac_api-0.0.7 → gjdatac_api-0.0.9}/gjdatac_api.egg-info/requires.txt +0 -0
- {gjdatac_api-0.0.7 → gjdatac_api-0.0.9}/gjdatac_api.egg-info/top_level.txt +0 -0
- {gjdatac_api-0.0.7 → gjdatac_api-0.0.9}/setup.cfg +0 -0
|
@@ -33,13 +33,13 @@ class GJDataC:
|
|
|
33
33
|
self.password = password
|
|
34
34
|
|
|
35
35
|
# 连接数据库
|
|
36
|
-
self.db_session = ddb.session()
|
|
37
|
-
success = self.db_session.connect(self.host, self.port, self.user_id, self.password)
|
|
38
|
-
if not success:
|
|
39
|
-
|
|
36
|
+
# self.db_session = ddb.session()
|
|
37
|
+
# success = self.db_session.connect(self.host, self.port, self.user_id, self.password)
|
|
38
|
+
# if not success:
|
|
39
|
+
# raise Exception("please check your database connection information")
|
|
40
40
|
|
|
41
|
-
''' 关闭数据库连接 '''
|
|
42
|
-
self.db_session.close()
|
|
41
|
+
# ''' 关闭数据库连接 '''
|
|
42
|
+
# self.db_session.close()
|
|
43
43
|
|
|
44
44
|
''' get_price 接口相关属性 '''
|
|
45
45
|
# self.get_price_data = None # 用于存放get_price接口数据
|
|
@@ -85,7 +85,9 @@ class GJDataC:
|
|
|
85
85
|
|
|
86
86
|
# 连接数据库
|
|
87
87
|
db_session = ddb.session()
|
|
88
|
-
db_session.connect(self.host, self.port, self.user_id, self.password)
|
|
88
|
+
success = db_session.connect(self.host, self.port, self.user_id, self.password)
|
|
89
|
+
if not success:
|
|
90
|
+
raise Exception("please check your database connection information")
|
|
89
91
|
|
|
90
92
|
# 从数据库中获取数据
|
|
91
93
|
data = db_session.loadTable(tableName=table_name, dbPath=db_path)
|
|
@@ -601,7 +603,7 @@ class GJDataC:
|
|
|
601
603
|
"tick_l1": (history_future_tick_db_table_name, history_future_tick_db_path),
|
|
602
604
|
"1d": (history_future_day_db_table_name, history_future_day_db_path),
|
|
603
605
|
"1min": (history_future_min_db_table_name, history_future_min_db_path),
|
|
604
|
-
|
|
606
|
+
"1min_gtja": (history_future_1min_gtja_db_table_name, history_future_1min_gtja_db_path),
|
|
605
607
|
# "tick_l2": (history_future_tick_l2_db_table_name, history_future_tick_l2_db_path),
|
|
606
608
|
}.get(frequency)
|
|
607
609
|
elif asset_type == "option":
|
|
@@ -629,7 +631,7 @@ class GJDataC:
|
|
|
629
631
|
:param commodity: str or list, 合约品种 和 commodity_type 必填 二选一 若填写品种参数,则返回该品种所有合约基础信息
|
|
630
632
|
:param asset_type: str, 合约类型--必填
|
|
631
633
|
:param fields: str or list, 字段列表--选填,默认为全部字段
|
|
632
|
-
:return:
|
|
634
|
+
:return: data:合约基础信息
|
|
633
635
|
"""
|
|
634
636
|
|
|
635
637
|
''' 数据校验 '''
|
|
@@ -640,21 +642,22 @@ class GJDataC:
|
|
|
640
642
|
self.general_validate_asset_type(asset_type)
|
|
641
643
|
|
|
642
644
|
''' 根据传入的asset_type以及order_book_ids获取数据 '''
|
|
643
|
-
self.get_instruments_data_get_data(asset_type=asset_type, order_book_ids=order_book_ids,
|
|
645
|
+
data = self.get_instruments_data_get_data(asset_type=asset_type, order_book_ids=order_book_ids,
|
|
646
|
+
commodity=commodity)
|
|
644
647
|
|
|
645
648
|
# 重命名字段
|
|
646
|
-
self.get_instruments_data_rename_columns(asset_type)
|
|
649
|
+
data = self.get_instruments_data_rename_columns(asset_type, data)
|
|
647
650
|
|
|
648
651
|
# 从交易参数中填充commodity和trading_hour的值
|
|
649
|
-
self.get_instruments_deal_commodity_trading_hour()
|
|
652
|
+
data = self.get_instruments_deal_commodity_trading_hour(data)
|
|
650
653
|
|
|
651
654
|
''' 按照文档筛选需要返回的字段 '''
|
|
652
|
-
self.get_instruments_data_filter_return_fileds(asset_type)
|
|
655
|
+
data = self.get_instruments_data_filter_return_fileds(asset_type, data)
|
|
653
656
|
|
|
654
657
|
# 对fields进行校验并根据fields返回对应的字段
|
|
655
|
-
self.get_instruments_validate_fields(fields)
|
|
658
|
+
data = self.get_instruments_validate_fields(fields, data)
|
|
656
659
|
|
|
657
|
-
return
|
|
660
|
+
return data
|
|
658
661
|
|
|
659
662
|
def get_instruments_validate_order_book_ids_commodity(self, order_book_ids, commodity):
|
|
660
663
|
"""
|
|
@@ -673,51 +676,57 @@ class GJDataC:
|
|
|
673
676
|
if commodity:
|
|
674
677
|
self.general_validate_field_str_or_list(commodity, "commodity")
|
|
675
678
|
|
|
676
|
-
def get_instruments_filter_order_book_ids(self, order_book_ids):
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
679
|
+
# def get_instruments_filter_order_book_ids(self, order_book_ids):
|
|
680
|
+
# """
|
|
681
|
+
# 根据order_book_ids筛选数据
|
|
682
|
+
# :param order_book_ids: str or list,合约代码
|
|
683
|
+
# :return: None
|
|
684
|
+
# """
|
|
682
685
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
686
|
+
# self.get_instruments_data = self.get_instruments_data[
|
|
687
|
+
# self.get_instruments_data["order_book_id"].isin(order_book_ids)] if isinstance(
|
|
688
|
+
# order_book_ids, list) else self.get_instruments_data[
|
|
689
|
+
# self.get_instruments_data["order_book_id"] == order_book_ids]
|
|
687
690
|
|
|
688
|
-
def get_instruments_filter_commodity(self, commodity):
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
691
|
+
# def get_instruments_filter_commodity(self, commodity):
|
|
692
|
+
# """
|
|
693
|
+
# 根据commodity筛选数据
|
|
694
|
+
# :param commodity: str or list, 合约品种
|
|
695
|
+
# :return: None
|
|
693
696
|
|
|
694
|
-
|
|
697
|
+
# """
|
|
695
698
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
699
|
+
# self.get_instruments_data = self.get_instruments_data[
|
|
700
|
+
# self.get_instruments_data["commodity"].isin(commodity)] if isinstance(
|
|
701
|
+
# commodity, list) else self.get_instruments_data[
|
|
702
|
+
# self.get_instruments_data["commodity"] == commodity]
|
|
700
703
|
|
|
701
|
-
def get_instruments_data_filter_return_fileds(self, asset_type):
|
|
704
|
+
def get_instruments_data_filter_return_fileds(self, asset_type, data):
|
|
702
705
|
"""
|
|
703
706
|
根据asset_type返回对应的字段(不同合约类型字段不同)
|
|
704
707
|
:param asset_type: 合约类型,"future" or "option"
|
|
705
|
-
:
|
|
708
|
+
:param data: 数据
|
|
709
|
+
:return: data: 返回筛选后的数据
|
|
706
710
|
"""
|
|
707
711
|
|
|
708
712
|
if asset_type == "future":
|
|
709
|
-
|
|
713
|
+
data = data[get_instruments_type_dict.get("future_return_fields")]
|
|
710
714
|
elif asset_type == "option":
|
|
711
|
-
|
|
715
|
+
data = data[get_instruments_type_dict.get("option_return_fields")]
|
|
712
716
|
|
|
713
|
-
|
|
717
|
+
return data
|
|
718
|
+
|
|
719
|
+
def get_instruments_validate_fields(self, fields, data):
|
|
714
720
|
"""
|
|
715
721
|
根据用户选择的字段返回数据
|
|
716
722
|
:param fields: str or list, 字段列表
|
|
717
|
-
:
|
|
723
|
+
:param data: 数据
|
|
724
|
+
:return: data: 返回筛选后的数据
|
|
718
725
|
"""
|
|
719
726
|
|
|
720
|
-
|
|
727
|
+
data = self.general_validate_fields(data, fields)
|
|
728
|
+
|
|
729
|
+
return data
|
|
721
730
|
|
|
722
731
|
def _get_instruments_data_get_data(self, order_book_ids, table_name, db_path):
|
|
723
732
|
"""
|
|
@@ -749,7 +758,7 @@ class GJDataC:
|
|
|
749
758
|
:param asset_type: 合约类型
|
|
750
759
|
:param order_book_ids: 合约代码
|
|
751
760
|
:param commodity: 合约品种
|
|
752
|
-
:return:
|
|
761
|
+
:return: data: 获取的数据
|
|
753
762
|
"""
|
|
754
763
|
|
|
755
764
|
# 如果传入的是commodity,需要获取参数品种下所有合约代码
|
|
@@ -772,51 +781,60 @@ class GJDataC:
|
|
|
772
781
|
|
|
773
782
|
''' 期货行情数据 '''
|
|
774
783
|
if asset_type == "future":
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
784
|
+
data = self._get_instruments_data_get_data(order_book_ids,
|
|
785
|
+
future_contract_db_table_name,
|
|
786
|
+
future_contract_db_path)
|
|
787
|
+
data["type"] = "future"
|
|
779
788
|
elif asset_type == "option":
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
789
|
+
data = self._get_instruments_data_get_data(order_book_ids,
|
|
790
|
+
option_contract_db_table_name,
|
|
791
|
+
option_contract_db_path)
|
|
792
|
+
data["type"] = "option"
|
|
793
|
+
data["exercise_type"] = data["optionstype"]
|
|
785
794
|
else:
|
|
786
795
|
raise Exception("asset_type is not valid")
|
|
787
|
-
|
|
788
|
-
|
|
796
|
+
data["commodity"] = ""
|
|
797
|
+
data["trading_hour"] = ""
|
|
789
798
|
|
|
790
|
-
|
|
799
|
+
return data
|
|
800
|
+
|
|
801
|
+
def get_instruments_data_rename_columns(self, asset_type, data):
|
|
791
802
|
"""
|
|
792
803
|
将从数据库中获取的数据列名重命名为文档要求的名字
|
|
793
804
|
|
|
794
805
|
:param asset_type: 合约类型
|
|
795
|
-
:
|
|
806
|
+
:param data: 数据
|
|
807
|
+
:return: data
|
|
796
808
|
"""
|
|
797
809
|
|
|
798
810
|
new_columns = get_instruments_type_dict.get(asset_type)
|
|
799
|
-
|
|
811
|
+
data = data.rename(columns=new_columns)
|
|
800
812
|
|
|
801
|
-
|
|
813
|
+
return data
|
|
814
|
+
|
|
815
|
+
def get_instruments_deal_commodity_trading_hour(self, data):
|
|
802
816
|
"""
|
|
803
817
|
用于处理commodity和trading_hour
|
|
818
|
+
:param data: 数据
|
|
819
|
+
:return: data: 处理后的数据
|
|
804
820
|
"""
|
|
805
821
|
|
|
806
822
|
try:
|
|
807
823
|
# 获取交易参数
|
|
808
824
|
trading_param_data, db_session = self.connect_db(trading_params_db_table_name, trading_params_db_path)
|
|
809
825
|
|
|
810
|
-
for index, row in
|
|
826
|
+
for index, row in data.iterrows():
|
|
811
827
|
match = trading_param_data.toDF()[trading_param_data.toDF()['contractcode'] == row['order_book_id']]
|
|
812
828
|
if not match.empty:
|
|
813
|
-
|
|
814
|
-
|
|
829
|
+
data.loc[index, 'commodity'] = match['productcode'].iloc[0]
|
|
830
|
+
data.loc[index, 'trading_hour'] = match['tradesection'].iloc[0]
|
|
815
831
|
db_session.close()
|
|
816
832
|
except ValueError as e:
|
|
817
833
|
print(e)
|
|
818
834
|
pass
|
|
819
835
|
|
|
836
|
+
return data
|
|
837
|
+
|
|
820
838
|
""" get_trading_dates(交易日历) """
|
|
821
839
|
|
|
822
840
|
def get_trading_dates(self, date=datetime.date.today(), n=None, start_date=None, end_date=None):
|
|
@@ -827,13 +845,13 @@ class GJDataC:
|
|
|
827
845
|
:param start_date: str(datetime.date, datetime.datetime)--选填, 开始日期
|
|
828
846
|
:param end_date: str(datetime.date, datetime.datetime)--选填, 结束日期
|
|
829
847
|
若填写【date、n】为入参,则无法填写【start_date、end_date】,反之依然
|
|
830
|
-
:return:
|
|
848
|
+
:return: data:交易日历
|
|
831
849
|
"""
|
|
832
850
|
|
|
833
851
|
""" 校验参数 """
|
|
834
|
-
|
|
852
|
+
data = self.get_trading_dates_validate_date_n_start_end(date, n, start_date, end_date)
|
|
835
853
|
|
|
836
|
-
return
|
|
854
|
+
return data
|
|
837
855
|
|
|
838
856
|
def get_trading_dates_validate_date_n_start_end(self, date, n, start_date, end_date):
|
|
839
857
|
"""
|
|
@@ -843,7 +861,7 @@ class GJDataC:
|
|
|
843
861
|
:param n: str--根据不同值获取对应的交易日历
|
|
844
862
|
:param start_date: str(datetime.date, datetime.datetime)--开始日期
|
|
845
863
|
:param end_date: str(datetime.date, datetime.datetime)--结束日期
|
|
846
|
-
:return:
|
|
864
|
+
:return: 如果校验通过,就返回对应的数据,否则抛出异常
|
|
847
865
|
"""
|
|
848
866
|
|
|
849
867
|
if (date and n) and (start_date and end_date):
|
|
@@ -883,7 +901,7 @@ class GJDataC:
|
|
|
883
901
|
:param start_date: str(datetime.date, datetime.datetime)--选填, 开始日期
|
|
884
902
|
:param end_date: str(datetime.date, datetime.datetime)--选填, 结束日期
|
|
885
903
|
|
|
886
|
-
:return:
|
|
904
|
+
:return: data:根据start_date和end_date筛选后的数据
|
|
887
905
|
"""
|
|
888
906
|
|
|
889
907
|
trading_params_data = self.get_trading_dates_get_data()
|
|
@@ -901,13 +919,12 @@ class GJDataC:
|
|
|
901
919
|
|
|
902
920
|
# 筛选 tradeflag 列等于 T 的数据(是交易日的数据)
|
|
903
921
|
final_df = filtered_df.loc[filtered_df['tradeflag'] == 'T']
|
|
904
|
-
|
|
922
|
+
data = sorted(final_df["tradingday"].tolist())
|
|
923
|
+
return data
|
|
905
924
|
else:
|
|
906
925
|
raise ValueError(
|
|
907
926
|
"start_date or end_date type error, please input str, datetime.date or datetime.datetime type")
|
|
908
927
|
|
|
909
|
-
return self.get_trading_dates_data
|
|
910
|
-
|
|
911
928
|
@staticmethod
|
|
912
929
|
def _get_trading_dates_by_start_end(time_data):
|
|
913
930
|
"""
|
|
@@ -15,6 +15,10 @@ history_future_min_db_table_name = "ctp_future_mink" # 表名
|
|
|
15
15
|
history_future_day_db_path = "dfs://dayk" # 数据库路径
|
|
16
16
|
history_future_day_db_table_name = "ctp_future_dayk" # 表名
|
|
17
17
|
|
|
18
|
+
# 历史期货实时分钟k线合成数据
|
|
19
|
+
history_future_1min_gtja_db_path = "dfs://minutek" # 数据库路径
|
|
20
|
+
history_future_1min_gtja_db_table_name = "t_trade_future_mink" # 表名
|
|
21
|
+
|
|
18
22
|
''' 期权 '''
|
|
19
23
|
# 历史期权行情数据 tick数据
|
|
20
24
|
history_option_tick_db_path = "dfs://tick" # 数据库路径
|
|
@@ -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.
|
|
8
|
+
version='0.0.9', # 版本号
|
|
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
|