gjdatac-api 0.2.7__tar.gz → 0.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gjdatac_api
3
- Version: 0.2.7
3
+ Version: 0.2.9
4
4
  Summary: 数据接口打包
5
5
  Author: yin
6
6
  Author-email: 2018209921@qq.com
@@ -24,7 +24,7 @@ from .instrument_class import Instrument
24
24
 
25
25
  class GJDataC:
26
26
 
27
- def __init__(self, host, port, user_id, password, dolphindb_service):
27
+ def __init__(self, host, port, user_id, password, dolphindb_service=None):
28
28
  """
29
29
  用于定义一些不同接口所需的变量以及一些初始化操作
30
30
  :param host: 数据库地址
@@ -1135,7 +1135,7 @@ class GJDataC:
1135
1135
  return self.get_trading_dates_by_date_n(date, n)
1136
1136
  elif start_date and end_date: # 根据start_date和end_date获取交易日历
1137
1137
  return self.get_trading_dates_by_start_end(start_date, end_date, is_include_start, is_include_end)
1138
- elif trade_time and date_count and date_type: # 查询前/后 N个交易日/时间数据
1138
+ elif trade_time and date_count is not None and date_type: # 查询前/后 N个交易日/时间数据
1139
1139
  return self.get_trading_date(trade_time, date_count, date_type)
1140
1140
  else:
1141
1141
  raise ValueError("parameter error: please pass date、n or start_date、end_date")
@@ -3845,8 +3845,7 @@ class GJDataC:
3845
3845
 
3846
3846
  return trading_dates
3847
3847
 
3848
- @staticmethod
3849
- def get_trading_days(trading_dates, trade_time, date_count):
3848
+ def get_trading_days(self, trading_dates, trade_time, date_count):
3850
3849
  """
3851
3850
  查询前后 N 个交易日
3852
3851
  :param trading_dates: 交易日历数据
@@ -3862,14 +3861,17 @@ class GJDataC:
3862
3861
  # 向前查询
3863
3862
  filtered_dates = trading_dates[trading_dates['trading_day'] < trade_time]
3864
3863
  result = filtered_dates['trading_day'].sort_values(ascending=False).head(abs(date_count))
3865
- else:
3864
+ elif date_count > 0:
3866
3865
  # 向后查询
3867
3866
  filtered_dates = trading_dates[trading_dates['trading_day'] > trade_time]
3868
3867
  result = filtered_dates['trading_day'].sort_values().head(date_count)
3868
+ else:
3869
+ filtered_dates = trading_dates[trading_dates['trading_day'] == trade_time]
3870
+ result = filtered_dates['trading_day']
3869
3871
 
3870
3872
  # 将结果转换为指定格式的字符串列表
3871
3873
  fina_result = sorted(result.dt.strftime('%Y.%m.%d').tolist())
3872
- return fina_result[0] if len(fina_result) <= 1 else fina_result
3874
+ return fina_result if len(fina_result) <= 1 else fina_result
3873
3875
 
3874
3876
  @staticmethod
3875
3877
  def get_trading_minutes(trading_dates, trade_time, date_count):
@@ -3886,10 +3888,13 @@ class GJDataC:
3886
3888
  # 筛选 trade_flag 列等于 T 的数据(是交易日的数据)
3887
3889
  trading_dates = trading_dates[trading_dates['trade_flag'] == 'T']
3888
3890
 
3891
+ # 转换字符串为 datetime
3892
+ trade_time = datetime.datetime.strptime(trade_time, '%Y.%m.%d %H:%M:%S')
3893
+
3889
3894
  # 生成时间点列表
3890
3895
  time_points = pd.date_range(start=trade_time - datetime.timedelta(minutes=abs(date_count)),
3891
3896
  end=trade_time + datetime.timedelta(minutes=abs(date_count)),
3892
- freq='T') # 'T' 表示分钟频率
3897
+ freq='min') # 'T' 表示分钟频率
3893
3898
 
3894
3899
  # 将时间点转换为指定格式的字符串
3895
3900
  time_points_str = time_points.strftime('%Y.%m.%d %H:%M:%S')
@@ -3905,11 +3910,14 @@ class GJDataC:
3905
3910
  if date_count < 0:
3906
3911
  # 向前查询
3907
3912
  result = [p for p in valid_time_points if pd.to_datetime(p) < trade_time][-abs(date_count):]
3908
- else:
3913
+ elif date_count > 0:
3909
3914
  # 向后查询
3910
3915
  result = [p for p in valid_time_points if pd.to_datetime(p) > trade_time][:date_count]
3916
+ else:
3917
+ result = [p for p in valid_time_points if pd.to_datetime(p) == trade_time]
3911
3918
 
3912
- return sorted(result) if len(result) > 1 else result[0]
3919
+ # return sorted(result) if len(result) > 1 else result[0]
3920
+ return sorted(result) if len(result) > 1 else result
3913
3921
 
3914
3922
  """ 交易日判断 """
3915
3923
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gjdatac-api
3
- Version: 0.2.7
3
+ Version: 0.2.9
4
4
  Summary: 数据接口打包
5
5
  Author: yin
6
6
  Author-email: 2018209921@qq.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.2.7', # 版本号
8
+ version='0.2.9', # 版本号
9
9
  description='数据接口打包', # 包的简要描述
10
10
  long_description=long_description, # 包的详细描述
11
11
  long_description_content_type='text/markdown', # 描述文件的类型
File without changes