gjdatac-api 0.0.3__tar.gz → 0.0.5__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.3 → gjdatac_api-0.0.5}/PKG-INFO +1 -1
- {gjdatac_api-0.0.3 → gjdatac_api-0.0.5}/gjdatac_api/data_api_class.py +50 -64
- {gjdatac_api-0.0.3 → gjdatac_api-0.0.5}/gjdatac_api/dolphin_db_info.py +1 -53
- {gjdatac_api-0.0.3 → gjdatac_api-0.0.5}/gjdatac_api.egg-info/PKG-INFO +1 -1
- {gjdatac_api-0.0.3 → gjdatac_api-0.0.5}/setup.py +1 -1
- {gjdatac_api-0.0.3 → gjdatac_api-0.0.5}/gjdatac_api/__init__.py +0 -0
- {gjdatac_api-0.0.3 → gjdatac_api-0.0.5}/gjdatac_api/dict_data.py +0 -0
- {gjdatac_api-0.0.3 → gjdatac_api-0.0.5}/gjdatac_api.egg-info/SOURCES.txt +0 -0
- {gjdatac_api-0.0.3 → gjdatac_api-0.0.5}/gjdatac_api.egg-info/dependency_links.txt +0 -0
- {gjdatac_api-0.0.3 → gjdatac_api-0.0.5}/gjdatac_api.egg-info/requires.txt +0 -0
- {gjdatac_api-0.0.3 → gjdatac_api-0.0.5}/gjdatac_api.egg-info/top_level.txt +0 -0
- {gjdatac_api-0.0.3 → gjdatac_api-0.0.5}/setup.cfg +0 -0
|
@@ -15,6 +15,12 @@ class GJDataC:
|
|
|
15
15
|
def __init__(self, host, port, user_id, password):
|
|
16
16
|
"""
|
|
17
17
|
用于定义一些不同接口所需的变量以及一些初始化操作
|
|
18
|
+
:param host: 数据库地址
|
|
19
|
+
:param port: 数据库端口
|
|
20
|
+
:param user_id: 数据库用户名
|
|
21
|
+
:param password: 数据库密码
|
|
22
|
+
|
|
23
|
+
用户调用api时,需要提供dolphindb相关的用户信息,包括host、port、user_id、password,用于连接数据库
|
|
18
24
|
"""
|
|
19
25
|
|
|
20
26
|
''' 初始化校验 '''
|
|
@@ -25,13 +31,14 @@ class GJDataC:
|
|
|
25
31
|
self.password = password
|
|
26
32
|
|
|
27
33
|
# 连接数据库
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
self.db_session.close()
|
|
32
|
-
except Exception as e:
|
|
34
|
+
self.db_session = ddb.session()
|
|
35
|
+
success = self.db_session.connect(self.host, self.port, self.user_id, self.password)
|
|
36
|
+
if not success:
|
|
33
37
|
raise Exception("please check your database connection information")
|
|
34
38
|
|
|
39
|
+
''' 关闭数据库连接 '''
|
|
40
|
+
self.db_session.close()
|
|
41
|
+
|
|
35
42
|
''' get_price 接口相关属性 '''
|
|
36
43
|
self.get_price_data = None # 用于存放get_price接口数据
|
|
37
44
|
|
|
@@ -53,8 +60,8 @@ class GJDataC:
|
|
|
53
60
|
''' get_activate_contract 接口相关属性 '''
|
|
54
61
|
self.get_active_contract_data = None # 用于存放get_activate_contract接口数据
|
|
55
62
|
|
|
56
|
-
@staticmethod
|
|
57
|
-
def connect_db(table_name, db_path):
|
|
63
|
+
# @staticmethod
|
|
64
|
+
def connect_db(self, table_name, db_path):
|
|
58
65
|
"""
|
|
59
66
|
此方法用于根据不同的数据表及数据库获取数据,只返回Table对象,对应的数据处理在对应的数据接口处理
|
|
60
67
|
:param table_name: 数据表路径
|
|
@@ -64,7 +71,7 @@ class GJDataC:
|
|
|
64
71
|
|
|
65
72
|
# 连接数据库
|
|
66
73
|
db_session = ddb.session()
|
|
67
|
-
db_session.connect(
|
|
74
|
+
db_session.connect(self.host, self.port, self.user_id, self.password)
|
|
68
75
|
|
|
69
76
|
# 从数据库中获取数据
|
|
70
77
|
data = db_session.loadTable(tableName=table_name, dbPath=db_path)
|
|
@@ -167,7 +174,7 @@ class GJDataC:
|
|
|
167
174
|
if not isinstance(param_value, str):
|
|
168
175
|
raise ValueError(f"{param_name} type error, please input str type")
|
|
169
176
|
|
|
170
|
-
def
|
|
177
|
+
def general_validate_asset_type(self, asset_type):
|
|
171
178
|
"""
|
|
172
179
|
对asset_type进行校验
|
|
173
180
|
:param asset_type: str, 合约类型
|
|
@@ -279,35 +286,35 @@ class GJDataC:
|
|
|
279
286
|
|
|
280
287
|
''' 数据校验 (先对必填参数进行校验)'''
|
|
281
288
|
# 对order_book_ids进行校验
|
|
282
|
-
self.
|
|
289
|
+
self.get_price_validate_order_book_ids(order_book_ids)
|
|
283
290
|
|
|
284
291
|
# 对asset_type进行校验
|
|
285
|
-
self.
|
|
292
|
+
self.general_validate_asset_type(asset_type)
|
|
286
293
|
|
|
287
294
|
# 对frequency进行校验
|
|
288
|
-
self.
|
|
295
|
+
self.get_price_validate_frequency(frequency)
|
|
289
296
|
|
|
290
297
|
# 对 start_date 和 end_date 进行校验
|
|
291
|
-
self.
|
|
298
|
+
self.get_price_validate_start_end_date(start_date, end_date)
|
|
292
299
|
|
|
293
300
|
''' 参数校验完成后,开始根据参数从服务器获取数据 '''
|
|
294
301
|
# 此处获取数据时已经根据order_book_ids筛选过一次数据了,所以后续不需要再对该字段进行筛选
|
|
295
|
-
self.
|
|
302
|
+
self.get_price_data_get_data(order_book_ids, asset_type, frequency)
|
|
296
303
|
|
|
297
304
|
''' 数据处理 '''
|
|
298
305
|
# 根据frequency进行处理
|
|
299
|
-
self.
|
|
306
|
+
self.get_price_by_type_frequency(asset_type, frequency)
|
|
300
307
|
|
|
301
308
|
# 根据start_date和end_date筛选数据
|
|
302
|
-
self.
|
|
309
|
+
self.get_price_filter_by_date(start_date, end_date, order_book_ids)
|
|
303
310
|
|
|
304
311
|
# 对fields进行处理
|
|
305
|
-
self.
|
|
312
|
+
self.get_price_validate_fields(fields)
|
|
306
313
|
|
|
307
314
|
return self.get_price_data
|
|
308
315
|
|
|
309
316
|
# @staticmethod
|
|
310
|
-
def
|
|
317
|
+
def get_price_validate_order_book_ids(self, order_book_ids):
|
|
311
318
|
"""
|
|
312
319
|
对order_book_ids 类型 以及 是否必填 进行校验
|
|
313
320
|
:param order_book_ids: 合约类型
|
|
@@ -317,7 +324,7 @@ class GJDataC:
|
|
|
317
324
|
self.general_validate_params_required(order_book_ids, "order_book_ids") # 校验必填参数
|
|
318
325
|
self.general_validate_field_str_or_list(order_book_ids, "order_book_ids") # 校验参数类型
|
|
319
326
|
|
|
320
|
-
def
|
|
327
|
+
def get_price_validate_frequency(self, frequency):
|
|
321
328
|
"""
|
|
322
329
|
对frequency进行校验
|
|
323
330
|
|
|
@@ -329,7 +336,7 @@ class GJDataC:
|
|
|
329
336
|
if not isinstance(frequency, str):
|
|
330
337
|
raise ValueError("frequency should be a string")
|
|
331
338
|
|
|
332
|
-
def
|
|
339
|
+
def get_price_validate_start_end_date(self, start_date, end_date):
|
|
333
340
|
"""
|
|
334
341
|
对 start_date 和 end_date 进行校验
|
|
335
342
|
校验 start_date 和 end_date 是否同时提供,或者都不提供。
|
|
@@ -392,7 +399,7 @@ class GJDataC:
|
|
|
392
399
|
else:
|
|
393
400
|
return False
|
|
394
401
|
|
|
395
|
-
def
|
|
402
|
+
def get_price_filter_by_date(self, start_date, end_date, order_book_ids):
|
|
396
403
|
"""
|
|
397
404
|
根据start_date和end_date筛选数据
|
|
398
405
|
此处order_book_ids参数用于处理未传递start_date和end_date的情况(根据order_book_ids返回距离当前时间最近的一条数据)
|
|
@@ -429,7 +436,7 @@ class GJDataC:
|
|
|
429
436
|
# 使用 tail(1) 获取每个组的最后一条数据
|
|
430
437
|
self.get_price_data = nearest_data.apply(lambda x: x.tail(1)).reset_index(drop=True)
|
|
431
438
|
|
|
432
|
-
def
|
|
439
|
+
def get_price_validate_fields(self, fields):
|
|
433
440
|
"""
|
|
434
441
|
根据用户选择的字段返回数据
|
|
435
442
|
:param fields: 字段列表 -- 用户传入的需要返回的字段
|
|
@@ -439,7 +446,7 @@ class GJDataC:
|
|
|
439
446
|
"""
|
|
440
447
|
self.get_price_data = self.general_validate_fields(self.get_price_data, fields)
|
|
441
448
|
|
|
442
|
-
def
|
|
449
|
+
def get_price_by_type_frequency(self, asset_type, frequency):
|
|
443
450
|
"""
|
|
444
451
|
根据合约类型和frequency筛选数据
|
|
445
452
|
|
|
@@ -459,7 +466,7 @@ class GJDataC:
|
|
|
459
466
|
# frequency存在再根据频率对数据做进一步处理
|
|
460
467
|
else:
|
|
461
468
|
bar_or_tick = get_price_frequency_dict[asset_type][suffix] # 获取数据类型是bar还是tick,根据值处理字段
|
|
462
|
-
self.
|
|
469
|
+
self.get_price_data_rename_columns(bar_or_tick) # 重命名字段
|
|
463
470
|
|
|
464
471
|
@staticmethod
|
|
465
472
|
def _ends_with(variable, suffixes):
|
|
@@ -473,7 +480,7 @@ class GJDataC:
|
|
|
473
480
|
return True, suffix
|
|
474
481
|
return False, ""
|
|
475
482
|
|
|
476
|
-
def
|
|
483
|
+
def get_price_data_rename_columns(self, bar_or_tick):
|
|
477
484
|
"""
|
|
478
485
|
将从数据库中获取的数据列名重命名
|
|
479
486
|
|
|
@@ -573,7 +580,7 @@ class GJDataC:
|
|
|
573
580
|
# return result_df
|
|
574
581
|
# return data.toDF()
|
|
575
582
|
|
|
576
|
-
def
|
|
583
|
+
def get_price_data_get_data(self, order_book_ids, asset_type, frequency):
|
|
577
584
|
"""
|
|
578
585
|
根据参数获取数据库和表名,调用接口获取数据
|
|
579
586
|
|
|
@@ -621,29 +628,29 @@ class GJDataC:
|
|
|
621
628
|
|
|
622
629
|
''' 数据校验 '''
|
|
623
630
|
# 对order_book_ids和commodity是否必填进行校验
|
|
624
|
-
self.
|
|
631
|
+
self.get_instruments_validate_order_book_ids_commodity(order_book_ids, commodity)
|
|
625
632
|
|
|
626
633
|
# 对asset_type进行校验
|
|
627
|
-
self.
|
|
634
|
+
self.general_validate_asset_type(asset_type)
|
|
628
635
|
|
|
629
636
|
''' 根据传入的asset_type以及order_book_ids获取数据 '''
|
|
630
|
-
self.
|
|
637
|
+
self.get_instruments_data_get_data(asset_type=asset_type, order_book_ids=order_book_ids, commodity=commodity)
|
|
631
638
|
|
|
632
639
|
# 重命名字段
|
|
633
|
-
self.
|
|
640
|
+
self.get_instruments_data_rename_columns(asset_type)
|
|
634
641
|
|
|
635
642
|
# 从交易参数中填充commodity和trading_hour的值
|
|
636
643
|
# self.get_instruments_deal_commodity_trading_hour()
|
|
637
644
|
|
|
638
645
|
''' 按照文档筛选需要返回的字段 '''
|
|
639
|
-
self.
|
|
646
|
+
self.get_instruments_data_filter_return_fileds(asset_type)
|
|
640
647
|
|
|
641
648
|
# 对fields进行校验并根据fields返回对应的字段
|
|
642
|
-
self.
|
|
649
|
+
self.get_instruments_validate_fields(fields)
|
|
643
650
|
|
|
644
651
|
return self.get_instruments_data
|
|
645
652
|
|
|
646
|
-
def
|
|
653
|
+
def get_instruments_validate_order_book_ids_commodity(self, order_book_ids, commodity):
|
|
647
654
|
"""
|
|
648
655
|
对order_book_ids和commodity_type进行校验
|
|
649
656
|
order_book_ids和commodity_type二选一,且只能二选一
|
|
@@ -685,7 +692,7 @@ class GJDataC:
|
|
|
685
692
|
commodity, list) else self.get_instruments_data[
|
|
686
693
|
self.get_instruments_data["commodity"] == commodity]
|
|
687
694
|
|
|
688
|
-
def
|
|
695
|
+
def get_instruments_data_filter_return_fileds(self, asset_type):
|
|
689
696
|
"""
|
|
690
697
|
根据asset_type返回对应的字段(不同合约类型字段不同)
|
|
691
698
|
:param asset_type: 合约类型,"future" or "option"
|
|
@@ -697,7 +704,7 @@ class GJDataC:
|
|
|
697
704
|
elif asset_type == "option":
|
|
698
705
|
self.get_instruments_data = self.get_instruments_data[get_instruments_type_dict.get("option_return_fields")]
|
|
699
706
|
|
|
700
|
-
def
|
|
707
|
+
def get_instruments_validate_fields(self, fields):
|
|
701
708
|
"""
|
|
702
709
|
根据用户选择的字段返回数据
|
|
703
710
|
:param fields: str or list, 字段列表
|
|
@@ -729,7 +736,7 @@ class GJDataC:
|
|
|
729
736
|
|
|
730
737
|
return filtered_data
|
|
731
738
|
|
|
732
|
-
def
|
|
739
|
+
def get_instruments_data_get_data(self, asset_type=None, order_book_ids=None, commodity=None):
|
|
733
740
|
"""
|
|
734
741
|
根据参数获取数据库和表名,调用接口获取数据
|
|
735
742
|
|
|
@@ -774,7 +781,7 @@ class GJDataC:
|
|
|
774
781
|
self.get_instruments_data["commodity"] = ""
|
|
775
782
|
self.get_instruments_data["trading_hour"] = ""
|
|
776
783
|
|
|
777
|
-
def
|
|
784
|
+
def get_instruments_data_rename_columns(self, asset_type):
|
|
778
785
|
"""
|
|
779
786
|
将从数据库中获取的数据列名重命名为文档要求的名字
|
|
780
787
|
|
|
@@ -818,11 +825,11 @@ class GJDataC:
|
|
|
818
825
|
"""
|
|
819
826
|
|
|
820
827
|
""" 校验参数 """
|
|
821
|
-
self.get_trading_dates_data = self.
|
|
828
|
+
self.get_trading_dates_data = self.get_trading_dates_validate_date_n_start_end(date, n, start_date, end_date)
|
|
822
829
|
|
|
823
830
|
return self.get_trading_dates_data
|
|
824
831
|
|
|
825
|
-
def
|
|
832
|
+
def get_trading_dates_validate_date_n_start_end(self, date, n, start_date, end_date):
|
|
826
833
|
"""
|
|
827
834
|
校验date、n和start_date、end_date有效性
|
|
828
835
|
|
|
@@ -838,13 +845,13 @@ class GJDataC:
|
|
|
838
845
|
if n and (start_date or end_date):
|
|
839
846
|
raise ValueError("parameter error: cannot pass date、n and start_date、end_date at the same time")
|
|
840
847
|
elif date and n: # 根据date和n获取交易日历
|
|
841
|
-
return self.
|
|
848
|
+
return self.get_trading_dates_by_date_n(date, n)
|
|
842
849
|
elif start_date and end_date: # 根据start_date和end_date获取交易日历
|
|
843
|
-
return self.
|
|
850
|
+
return self.get_trading_dates_by_start_end(start_date, end_date)
|
|
844
851
|
else:
|
|
845
852
|
raise ValueError("parameter error: please pass date、n or start_date、end_date")
|
|
846
853
|
|
|
847
|
-
def
|
|
854
|
+
def get_trading_dates_by_date_n(self, date, n):
|
|
848
855
|
"""
|
|
849
856
|
校验 date 和 n
|
|
850
857
|
:param date: str--选填, 日期
|
|
@@ -864,7 +871,7 @@ class GJDataC:
|
|
|
864
871
|
|
|
865
872
|
return self.get_dates_in_n(date, n)
|
|
866
873
|
|
|
867
|
-
def
|
|
874
|
+
def get_trading_dates_by_start_end(self, start_date, end_date):
|
|
868
875
|
"""
|
|
869
876
|
根据start_date和end_date获取交易日历
|
|
870
877
|
:param start_date: str(datetime.date, datetime.datetime)--选填, 开始日期
|
|
@@ -1009,27 +1016,6 @@ class GJDataC:
|
|
|
1009
1016
|
|
|
1010
1017
|
return time_period_mapping_dict[_n]
|
|
1011
1018
|
|
|
1012
|
-
# @staticmethod
|
|
1013
|
-
# def get_current_week(date_data):
|
|
1014
|
-
# """
|
|
1015
|
-
# 获取选定日期的当周。
|
|
1016
|
-
|
|
1017
|
-
# Args:
|
|
1018
|
-
# date_data: 选定的日期,可以是 datetime.date 或 datetime.datetime 对象。
|
|
1019
|
-
|
|
1020
|
-
# Returns:
|
|
1021
|
-
# 一个元组,包含当前周的开始日期和结束日期,类型为 datetime.date。
|
|
1022
|
-
# """
|
|
1023
|
-
|
|
1024
|
-
# # 获取星期几 (0-6, 0代表星期一)
|
|
1025
|
-
# weekday = date_data.weekday()
|
|
1026
|
-
|
|
1027
|
-
# # 计算当周的开始日期和结束日期
|
|
1028
|
-
# start_date = date_data - datetime.timedelta(days=weekday)
|
|
1029
|
-
# end_date = start_date + datetime.timedelta(days=6)
|
|
1030
|
-
|
|
1031
|
-
# return start_date, end_date
|
|
1032
|
-
|
|
1033
1019
|
""" get_margin_ratio 期货保证金 """
|
|
1034
1020
|
|
|
1035
1021
|
def get_margin_ratio(self, order_book_id=None, commodity=None, date=datetime.datetime.now(), exchange=None):
|
|
@@ -1,52 +1,5 @@
|
|
|
1
1
|
# 此文件用于存放dolphinDB的相关信息,包括登录信息、数据库和表信息等。
|
|
2
2
|
|
|
3
|
-
""" 本地dolphindb数据库相关信息 """
|
|
4
|
-
|
|
5
|
-
# 登录信息
|
|
6
|
-
# HOST = "localhost" # 主机名或IP地址
|
|
7
|
-
HOST = "10.100.96.125" # 主机名或IP地址
|
|
8
|
-
PORT = 8848 # 端口号
|
|
9
|
-
USER_ID = "admin" # 用户名
|
|
10
|
-
PASSWORD = "123456" # 密码
|
|
11
|
-
|
|
12
|
-
# 数据库、表信息
|
|
13
|
-
''' get_price 行情数据接口所在的数据库和表 '''
|
|
14
|
-
get_price_db_path = "dfs://firstdb" # 数据库路径
|
|
15
|
-
get_price_db_table_name = "get_price_tb" # 表名
|
|
16
|
-
|
|
17
|
-
''' get_instruments 合约基础信息接口所在的数据库和表 '''
|
|
18
|
-
get_instruments_db_path = "dfs://firstdb" # 数据库路径
|
|
19
|
-
get_instruments_db_table_name = "get_instruments_tb" # 表名
|
|
20
|
-
|
|
21
|
-
''' get_trading_dates 交易日历接口所在的数据库和表 '''
|
|
22
|
-
get_trading_dates_db_path = "dfs://firstdb" # 数据库路径
|
|
23
|
-
get_trading_dates_db_table_name = "get_trading_dates_tb" # 表名
|
|
24
|
-
|
|
25
|
-
''' get_margin_ratio 期货保证金接口所在的数据库和表 '''
|
|
26
|
-
get_margin_ratio_db_path = "dfs://firstdb" # 数据库路径
|
|
27
|
-
get_margin_ratio_db_table_name = "get_margin_ratio_tb" # 表名
|
|
28
|
-
|
|
29
|
-
''' get_fee 期货交割手续费接口所在的数据库和表 '''
|
|
30
|
-
get_fee_db_path = "dfs://firstdb" # 数据库路径
|
|
31
|
-
get_fee_db_table_name = "get_fee_tb" # 表名
|
|
32
|
-
|
|
33
|
-
''' get_limit_position 期货限仓数据接口所在的数据库和表 '''
|
|
34
|
-
get_limit_position_db_path = "dfs://firstdb" # 数据库路径
|
|
35
|
-
get_limit_position_db_table_name = "get_limit_position_tb" # 表名
|
|
36
|
-
|
|
37
|
-
''' get_active_contract 主力/次主力合约接口所在的数据库和表 '''
|
|
38
|
-
get_active_contract_db_path = "dfs://firstdb" # 数据库路径
|
|
39
|
-
get_active_contract_db_table_name = "get_active_contract_tb" # 表名
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
""" 公司dolphindb数据库相关信息 """
|
|
43
|
-
|
|
44
|
-
# 登录信息
|
|
45
|
-
COMPANY_HOST = "10.74.56.101" # 主机名或IP地址
|
|
46
|
-
COMPANY_PORT = 8902 # 端口号
|
|
47
|
-
COMPANY_USER_ID = "sys_asset_zdgl" # 用户名
|
|
48
|
-
COMPANY_PASSWORD = "zdgl@1qaz2wsx" # 密码
|
|
49
|
-
|
|
50
3
|
""" 行情数据所在数据库和表 """
|
|
51
4
|
|
|
52
5
|
''' 期货 '''
|
|
@@ -68,7 +21,7 @@ history_option_tick_db_path = "dfs://tick" # 数据库路径
|
|
|
68
21
|
history_option_tick_db_table_name = "ctp_option_tick" # 表名
|
|
69
22
|
|
|
70
23
|
# 历史期权行情数据 分钟k线
|
|
71
|
-
history_option_min_db_path = "dfs://minutek"
|
|
24
|
+
history_option_min_db_path = "dfs://minutek" # 数据库路径
|
|
72
25
|
history_option_min_db_table_name = "ctp_option_mink" # 表名
|
|
73
26
|
|
|
74
27
|
# 历史期权行情数据 5分钟k线
|
|
@@ -101,8 +54,3 @@ option_contract_db_table_name = "t_optinstrument" # 表名
|
|
|
101
54
|
# 交易日历
|
|
102
55
|
trading_dates_db_path = "dfs://basicinfo" # 数据库路径
|
|
103
56
|
trading_dates_db_table_name = "b_calendar" # 表名
|
|
104
|
-
|
|
105
|
-
{
|
|
106
|
-
"name": "sfs",
|
|
107
|
-
"sfs": "sfs"
|
|
108
|
-
}
|
|
@@ -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.5', # 版本号
|
|
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
|