gjdatac-api 0.0.4__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.4 → gjdatac_api-0.0.5}/PKG-INFO +1 -1
- {gjdatac_api-0.0.4 → gjdatac_api-0.0.5}/gjdatac_api/data_api_class.py +44 -60
- {gjdatac_api-0.0.4 → gjdatac_api-0.0.5}/gjdatac_api.egg-info/PKG-INFO +1 -1
- {gjdatac_api-0.0.4 → gjdatac_api-0.0.5}/setup.py +1 -1
- {gjdatac_api-0.0.4 → gjdatac_api-0.0.5}/gjdatac_api/__init__.py +0 -0
- {gjdatac_api-0.0.4 → gjdatac_api-0.0.5}/gjdatac_api/dict_data.py +0 -0
- {gjdatac_api-0.0.4 → gjdatac_api-0.0.5}/gjdatac_api/dolphin_db_info.py +0 -0
- {gjdatac_api-0.0.4 → gjdatac_api-0.0.5}/gjdatac_api.egg-info/SOURCES.txt +0 -0
- {gjdatac_api-0.0.4 → gjdatac_api-0.0.5}/gjdatac_api.egg-info/dependency_links.txt +0 -0
- {gjdatac_api-0.0.4 → gjdatac_api-0.0.5}/gjdatac_api.egg-info/requires.txt +0 -0
- {gjdatac_api-0.0.4 → gjdatac_api-0.0.5}/gjdatac_api.egg-info/top_level.txt +0 -0
- {gjdatac_api-0.0.4 → 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,10 +31,9 @@ class GJDataC:
|
|
|
25
31
|
self.password = password
|
|
26
32
|
|
|
27
33
|
# 连接数据库
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
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:
|
|
32
37
|
raise Exception("please check your database connection information")
|
|
33
38
|
|
|
34
39
|
''' 关闭数据库连接 '''
|
|
@@ -169,7 +174,7 @@ class GJDataC:
|
|
|
169
174
|
if not isinstance(param_value, str):
|
|
170
175
|
raise ValueError(f"{param_name} type error, please input str type")
|
|
171
176
|
|
|
172
|
-
def
|
|
177
|
+
def general_validate_asset_type(self, asset_type):
|
|
173
178
|
"""
|
|
174
179
|
对asset_type进行校验
|
|
175
180
|
:param asset_type: str, 合约类型
|
|
@@ -281,35 +286,35 @@ class GJDataC:
|
|
|
281
286
|
|
|
282
287
|
''' 数据校验 (先对必填参数进行校验)'''
|
|
283
288
|
# 对order_book_ids进行校验
|
|
284
|
-
self.
|
|
289
|
+
self.get_price_validate_order_book_ids(order_book_ids)
|
|
285
290
|
|
|
286
291
|
# 对asset_type进行校验
|
|
287
|
-
self.
|
|
292
|
+
self.general_validate_asset_type(asset_type)
|
|
288
293
|
|
|
289
294
|
# 对frequency进行校验
|
|
290
|
-
self.
|
|
295
|
+
self.get_price_validate_frequency(frequency)
|
|
291
296
|
|
|
292
297
|
# 对 start_date 和 end_date 进行校验
|
|
293
|
-
self.
|
|
298
|
+
self.get_price_validate_start_end_date(start_date, end_date)
|
|
294
299
|
|
|
295
300
|
''' 参数校验完成后,开始根据参数从服务器获取数据 '''
|
|
296
301
|
# 此处获取数据时已经根据order_book_ids筛选过一次数据了,所以后续不需要再对该字段进行筛选
|
|
297
|
-
self.
|
|
302
|
+
self.get_price_data_get_data(order_book_ids, asset_type, frequency)
|
|
298
303
|
|
|
299
304
|
''' 数据处理 '''
|
|
300
305
|
# 根据frequency进行处理
|
|
301
|
-
self.
|
|
306
|
+
self.get_price_by_type_frequency(asset_type, frequency)
|
|
302
307
|
|
|
303
308
|
# 根据start_date和end_date筛选数据
|
|
304
|
-
self.
|
|
309
|
+
self.get_price_filter_by_date(start_date, end_date, order_book_ids)
|
|
305
310
|
|
|
306
311
|
# 对fields进行处理
|
|
307
|
-
self.
|
|
312
|
+
self.get_price_validate_fields(fields)
|
|
308
313
|
|
|
309
314
|
return self.get_price_data
|
|
310
315
|
|
|
311
316
|
# @staticmethod
|
|
312
|
-
def
|
|
317
|
+
def get_price_validate_order_book_ids(self, order_book_ids):
|
|
313
318
|
"""
|
|
314
319
|
对order_book_ids 类型 以及 是否必填 进行校验
|
|
315
320
|
:param order_book_ids: 合约类型
|
|
@@ -319,7 +324,7 @@ class GJDataC:
|
|
|
319
324
|
self.general_validate_params_required(order_book_ids, "order_book_ids") # 校验必填参数
|
|
320
325
|
self.general_validate_field_str_or_list(order_book_ids, "order_book_ids") # 校验参数类型
|
|
321
326
|
|
|
322
|
-
def
|
|
327
|
+
def get_price_validate_frequency(self, frequency):
|
|
323
328
|
"""
|
|
324
329
|
对frequency进行校验
|
|
325
330
|
|
|
@@ -331,7 +336,7 @@ class GJDataC:
|
|
|
331
336
|
if not isinstance(frequency, str):
|
|
332
337
|
raise ValueError("frequency should be a string")
|
|
333
338
|
|
|
334
|
-
def
|
|
339
|
+
def get_price_validate_start_end_date(self, start_date, end_date):
|
|
335
340
|
"""
|
|
336
341
|
对 start_date 和 end_date 进行校验
|
|
337
342
|
校验 start_date 和 end_date 是否同时提供,或者都不提供。
|
|
@@ -394,7 +399,7 @@ class GJDataC:
|
|
|
394
399
|
else:
|
|
395
400
|
return False
|
|
396
401
|
|
|
397
|
-
def
|
|
402
|
+
def get_price_filter_by_date(self, start_date, end_date, order_book_ids):
|
|
398
403
|
"""
|
|
399
404
|
根据start_date和end_date筛选数据
|
|
400
405
|
此处order_book_ids参数用于处理未传递start_date和end_date的情况(根据order_book_ids返回距离当前时间最近的一条数据)
|
|
@@ -431,7 +436,7 @@ class GJDataC:
|
|
|
431
436
|
# 使用 tail(1) 获取每个组的最后一条数据
|
|
432
437
|
self.get_price_data = nearest_data.apply(lambda x: x.tail(1)).reset_index(drop=True)
|
|
433
438
|
|
|
434
|
-
def
|
|
439
|
+
def get_price_validate_fields(self, fields):
|
|
435
440
|
"""
|
|
436
441
|
根据用户选择的字段返回数据
|
|
437
442
|
:param fields: 字段列表 -- 用户传入的需要返回的字段
|
|
@@ -441,7 +446,7 @@ class GJDataC:
|
|
|
441
446
|
"""
|
|
442
447
|
self.get_price_data = self.general_validate_fields(self.get_price_data, fields)
|
|
443
448
|
|
|
444
|
-
def
|
|
449
|
+
def get_price_by_type_frequency(self, asset_type, frequency):
|
|
445
450
|
"""
|
|
446
451
|
根据合约类型和frequency筛选数据
|
|
447
452
|
|
|
@@ -461,7 +466,7 @@ class GJDataC:
|
|
|
461
466
|
# frequency存在再根据频率对数据做进一步处理
|
|
462
467
|
else:
|
|
463
468
|
bar_or_tick = get_price_frequency_dict[asset_type][suffix] # 获取数据类型是bar还是tick,根据值处理字段
|
|
464
|
-
self.
|
|
469
|
+
self.get_price_data_rename_columns(bar_or_tick) # 重命名字段
|
|
465
470
|
|
|
466
471
|
@staticmethod
|
|
467
472
|
def _ends_with(variable, suffixes):
|
|
@@ -475,7 +480,7 @@ class GJDataC:
|
|
|
475
480
|
return True, suffix
|
|
476
481
|
return False, ""
|
|
477
482
|
|
|
478
|
-
def
|
|
483
|
+
def get_price_data_rename_columns(self, bar_or_tick):
|
|
479
484
|
"""
|
|
480
485
|
将从数据库中获取的数据列名重命名
|
|
481
486
|
|
|
@@ -575,7 +580,7 @@ class GJDataC:
|
|
|
575
580
|
# return result_df
|
|
576
581
|
# return data.toDF()
|
|
577
582
|
|
|
578
|
-
def
|
|
583
|
+
def get_price_data_get_data(self, order_book_ids, asset_type, frequency):
|
|
579
584
|
"""
|
|
580
585
|
根据参数获取数据库和表名,调用接口获取数据
|
|
581
586
|
|
|
@@ -623,29 +628,29 @@ class GJDataC:
|
|
|
623
628
|
|
|
624
629
|
''' 数据校验 '''
|
|
625
630
|
# 对order_book_ids和commodity是否必填进行校验
|
|
626
|
-
self.
|
|
631
|
+
self.get_instruments_validate_order_book_ids_commodity(order_book_ids, commodity)
|
|
627
632
|
|
|
628
633
|
# 对asset_type进行校验
|
|
629
|
-
self.
|
|
634
|
+
self.general_validate_asset_type(asset_type)
|
|
630
635
|
|
|
631
636
|
''' 根据传入的asset_type以及order_book_ids获取数据 '''
|
|
632
|
-
self.
|
|
637
|
+
self.get_instruments_data_get_data(asset_type=asset_type, order_book_ids=order_book_ids, commodity=commodity)
|
|
633
638
|
|
|
634
639
|
# 重命名字段
|
|
635
|
-
self.
|
|
640
|
+
self.get_instruments_data_rename_columns(asset_type)
|
|
636
641
|
|
|
637
642
|
# 从交易参数中填充commodity和trading_hour的值
|
|
638
643
|
# self.get_instruments_deal_commodity_trading_hour()
|
|
639
644
|
|
|
640
645
|
''' 按照文档筛选需要返回的字段 '''
|
|
641
|
-
self.
|
|
646
|
+
self.get_instruments_data_filter_return_fileds(asset_type)
|
|
642
647
|
|
|
643
648
|
# 对fields进行校验并根据fields返回对应的字段
|
|
644
|
-
self.
|
|
649
|
+
self.get_instruments_validate_fields(fields)
|
|
645
650
|
|
|
646
651
|
return self.get_instruments_data
|
|
647
652
|
|
|
648
|
-
def
|
|
653
|
+
def get_instruments_validate_order_book_ids_commodity(self, order_book_ids, commodity):
|
|
649
654
|
"""
|
|
650
655
|
对order_book_ids和commodity_type进行校验
|
|
651
656
|
order_book_ids和commodity_type二选一,且只能二选一
|
|
@@ -687,7 +692,7 @@ class GJDataC:
|
|
|
687
692
|
commodity, list) else self.get_instruments_data[
|
|
688
693
|
self.get_instruments_data["commodity"] == commodity]
|
|
689
694
|
|
|
690
|
-
def
|
|
695
|
+
def get_instruments_data_filter_return_fileds(self, asset_type):
|
|
691
696
|
"""
|
|
692
697
|
根据asset_type返回对应的字段(不同合约类型字段不同)
|
|
693
698
|
:param asset_type: 合约类型,"future" or "option"
|
|
@@ -699,7 +704,7 @@ class GJDataC:
|
|
|
699
704
|
elif asset_type == "option":
|
|
700
705
|
self.get_instruments_data = self.get_instruments_data[get_instruments_type_dict.get("option_return_fields")]
|
|
701
706
|
|
|
702
|
-
def
|
|
707
|
+
def get_instruments_validate_fields(self, fields):
|
|
703
708
|
"""
|
|
704
709
|
根据用户选择的字段返回数据
|
|
705
710
|
:param fields: str or list, 字段列表
|
|
@@ -731,7 +736,7 @@ class GJDataC:
|
|
|
731
736
|
|
|
732
737
|
return filtered_data
|
|
733
738
|
|
|
734
|
-
def
|
|
739
|
+
def get_instruments_data_get_data(self, asset_type=None, order_book_ids=None, commodity=None):
|
|
735
740
|
"""
|
|
736
741
|
根据参数获取数据库和表名,调用接口获取数据
|
|
737
742
|
|
|
@@ -776,7 +781,7 @@ class GJDataC:
|
|
|
776
781
|
self.get_instruments_data["commodity"] = ""
|
|
777
782
|
self.get_instruments_data["trading_hour"] = ""
|
|
778
783
|
|
|
779
|
-
def
|
|
784
|
+
def get_instruments_data_rename_columns(self, asset_type):
|
|
780
785
|
"""
|
|
781
786
|
将从数据库中获取的数据列名重命名为文档要求的名字
|
|
782
787
|
|
|
@@ -820,11 +825,11 @@ class GJDataC:
|
|
|
820
825
|
"""
|
|
821
826
|
|
|
822
827
|
""" 校验参数 """
|
|
823
|
-
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)
|
|
824
829
|
|
|
825
830
|
return self.get_trading_dates_data
|
|
826
831
|
|
|
827
|
-
def
|
|
832
|
+
def get_trading_dates_validate_date_n_start_end(self, date, n, start_date, end_date):
|
|
828
833
|
"""
|
|
829
834
|
校验date、n和start_date、end_date有效性
|
|
830
835
|
|
|
@@ -840,13 +845,13 @@ class GJDataC:
|
|
|
840
845
|
if n and (start_date or end_date):
|
|
841
846
|
raise ValueError("parameter error: cannot pass date、n and start_date、end_date at the same time")
|
|
842
847
|
elif date and n: # 根据date和n获取交易日历
|
|
843
|
-
return self.
|
|
848
|
+
return self.get_trading_dates_by_date_n(date, n)
|
|
844
849
|
elif start_date and end_date: # 根据start_date和end_date获取交易日历
|
|
845
|
-
return self.
|
|
850
|
+
return self.get_trading_dates_by_start_end(start_date, end_date)
|
|
846
851
|
else:
|
|
847
852
|
raise ValueError("parameter error: please pass date、n or start_date、end_date")
|
|
848
853
|
|
|
849
|
-
def
|
|
854
|
+
def get_trading_dates_by_date_n(self, date, n):
|
|
850
855
|
"""
|
|
851
856
|
校验 date 和 n
|
|
852
857
|
:param date: str--选填, 日期
|
|
@@ -866,7 +871,7 @@ class GJDataC:
|
|
|
866
871
|
|
|
867
872
|
return self.get_dates_in_n(date, n)
|
|
868
873
|
|
|
869
|
-
def
|
|
874
|
+
def get_trading_dates_by_start_end(self, start_date, end_date):
|
|
870
875
|
"""
|
|
871
876
|
根据start_date和end_date获取交易日历
|
|
872
877
|
:param start_date: str(datetime.date, datetime.datetime)--选填, 开始日期
|
|
@@ -1011,27 +1016,6 @@ class GJDataC:
|
|
|
1011
1016
|
|
|
1012
1017
|
return time_period_mapping_dict[_n]
|
|
1013
1018
|
|
|
1014
|
-
# @staticmethod
|
|
1015
|
-
# def get_current_week(date_data):
|
|
1016
|
-
# """
|
|
1017
|
-
# 获取选定日期的当周。
|
|
1018
|
-
|
|
1019
|
-
# Args:
|
|
1020
|
-
# date_data: 选定的日期,可以是 datetime.date 或 datetime.datetime 对象。
|
|
1021
|
-
|
|
1022
|
-
# Returns:
|
|
1023
|
-
# 一个元组,包含当前周的开始日期和结束日期,类型为 datetime.date。
|
|
1024
|
-
# """
|
|
1025
|
-
|
|
1026
|
-
# # 获取星期几 (0-6, 0代表星期一)
|
|
1027
|
-
# weekday = date_data.weekday()
|
|
1028
|
-
|
|
1029
|
-
# # 计算当周的开始日期和结束日期
|
|
1030
|
-
# start_date = date_data - datetime.timedelta(days=weekday)
|
|
1031
|
-
# end_date = start_date + datetime.timedelta(days=6)
|
|
1032
|
-
|
|
1033
|
-
# return start_date, end_date
|
|
1034
|
-
|
|
1035
1019
|
""" get_margin_ratio 期货保证金 """
|
|
1036
1020
|
|
|
1037
1021
|
def get_margin_ratio(self, order_book_id=None, commodity=None, date=datetime.datetime.now(), exchange=None):
|
|
@@ -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
|
|
File without changes
|