gjdatac-api 0.2.9__tar.gz → 0.3.0__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.9
3
+ Version: 0.3.0
4
4
  Summary: 数据接口打包
5
5
  Author: yin
6
6
  Author-email: 2018209921@qq.com
@@ -2004,13 +2004,8 @@ class GJDataC:
2004
2004
  # 先从数据库获取数据
2005
2005
  tick_data, db_session = self.connect_db(table_name, db_path)
2006
2006
 
2007
- # 使用 strftime 方法将 Timestamp 转换为所需格式
2008
- formatted_dates = [ts.strftime('%Y.%m.%d') for ts in data['trading_day'].tolist()]
2009
2007
 
2010
2008
  # 根据日期筛选数据
2011
- # 将日期转换成 DolphinDB 识别的日期格式,用于筛选数据
2012
- # start_dolphin_date = self.get_active_contract_datetime_to_dolphin_time(start_date)
2013
- # end_dolphin_date = self.get_active_contract_datetime_to_dolphin_time(end_date)
2014
2009
  start_dolphin_date = self.format_date(start_date)
2015
2010
  end_dolphin_date = self.format_date(end_date)
2016
2011
  date_data = tick_data.where(f"trading_day >= {start_dolphin_date} and trading_day <= {end_dolphin_date}")
@@ -2452,8 +2447,6 @@ class GJDataC:
2452
2447
  """
2453
2448
  校验参数类型是否为str
2454
2449
  :param commodity: str--必填,期货合约品种
2455
- :param start_date: str--必填,开始日期
2456
- :param end_date: str--必填,结束日期 (默认为策略当天日期的前一天)
2457
2450
  :return: None
2458
2451
  """
2459
2452
 
@@ -3845,7 +3838,8 @@ class GJDataC:
3845
3838
 
3846
3839
  return trading_dates
3847
3840
 
3848
- def get_trading_days(self, trading_dates, trade_time, date_count):
3841
+ @staticmethod
3842
+ def get_trading_days(trading_dates, trade_time, date_count):
3849
3843
  """
3850
3844
  查询前后 N 个交易日
3851
3845
  :param trading_dates: 交易日历数据
@@ -3895,6 +3889,19 @@ class GJDataC:
3895
3889
  time_points = pd.date_range(start=trade_time - datetime.timedelta(minutes=abs(date_count)),
3896
3890
  end=trade_time + datetime.timedelta(minutes=abs(date_count)),
3897
3891
  freq='min') # 'T' 表示分钟频率
3892
+ def _before_trading_day(_date):
3893
+ if _date in trading_dates['trading_day'].dt.date.values:
3894
+ return _date
3895
+ else:
3896
+ _previous_date = _date - datetime.timedelta(days=1)
3897
+ return _before_trading_day(_previous_date)
3898
+
3899
+ def _after_trading_day(_date):
3900
+ if _date in trading_dates['trading_day'].dt.date.values:
3901
+ return _date
3902
+ else:
3903
+ _previous_date = _date + datetime.timedelta(days=1)
3904
+ return _after_trading_day(_previous_date)
3898
3905
 
3899
3906
  # 将时间点转换为指定格式的字符串
3900
3907
  time_points_str = time_points.strftime('%Y.%m.%d %H:%M:%S')
@@ -3905,6 +3912,36 @@ class GJDataC:
3905
3912
  # 检查时间点是否在交易日历中
3906
3913
  if point.date() in trading_dates['trading_day'].dt.date.values:
3907
3914
  valid_time_points.append(point_str)
3915
+ else:
3916
+ if point.date() < trade_time.date():
3917
+ previous_date = point.date() - datetime.timedelta(days=1)
3918
+ trading_date = _before_trading_day(previous_date)
3919
+ elif point.date() > trade_time.date():
3920
+ previous_date = point.date() + datetime.timedelta(days=1)
3921
+ trading_date = _after_trading_day(previous_date)
3922
+ else:
3923
+ trading_date = point.date()
3924
+ datetime_obj = datetime.datetime.combine(trading_date, datetime.time.min)
3925
+
3926
+ # 获取当天的最后一秒(23:59:59)
3927
+ end_of_day = datetime.datetime.combine(datetime_obj.date(), datetime.time(23, 59, 59))
3928
+ if trading_date < trade_time.date():
3929
+ _time_points = \
3930
+ pd.date_range(start=end_of_day - datetime.timedelta(minutes=abs(date_count)),
3931
+ end=end_of_day,
3932
+ freq='min')
3933
+ elif trading_date > trade_time.date():
3934
+ _time_points = \
3935
+ pd.date_range(start=datetime_obj,
3936
+ end=datetime_obj + datetime.timedelta(minutes=abs(date_count)),
3937
+ freq='min')
3938
+ else:
3939
+ _time_points = \
3940
+ pd.date_range(start=datetime_obj,
3941
+ end=datetime_obj,
3942
+ freq='min')
3943
+ _time_points = _time_points.strftime('%Y.%m.%d %H:%M:%S')
3944
+ valid_time_points.extend(_time_points)
3908
3945
 
3909
3946
  # 根据 date_count 的正负决定查询方向
3910
3947
  if date_count < 0:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gjdatac-api
3
- Version: 0.2.9
3
+ Version: 0.3.0
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.9', # 版本号
8
+ version='0.3.0', # 版本号
9
9
  description='数据接口打包', # 包的简要描述
10
10
  long_description=long_description, # 包的详细描述
11
11
  long_description_content_type='text/markdown', # 描述文件的类型
File without changes