开发人员你好,
我想要实现隔夜不留仓,代码如下,
if api.is_changing(klines.iloc[-1], “close”):
now = datetime.strptime(klines.iloc[-1].datetime, “%Y-%m-%d %H:%M:%S.%f”)
if now.hour == CLOSE_HOUR and now.minute >= CLOSE_MINUTE: # 到达平仓时间: 平仓
print(“临近本交易日收盘: 平仓”)
报错信息提示类型不对:TypeError: strptime() argument 1 must be str, not numpy.float64
修改为:
if api.is_changing(klines.iloc[-1], “close”):
now = datetime.strptime(str(klines.iloc[-1].datetime), “%Y-%m-%d %H:%M:%S.%f”)
if now.hour == CLOSE_HOUR and now.minute >= CLOSE_MINUTE: # 到达平仓时间: 平仓
print(“临近本交易日收盘: 平仓”)
错误信息如下:
Traceback (most recent call last):
File “E:/PycharmProjects/untitled/main.py”, line 28, in <module>
now = datetime.strptime(str(klines.iloc[-1].datetime), “%Y-%m-%d %H:%M:%S.%f”)
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\_strptime.py”, line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\_strptime.py”, line 349, in _strptime
raise ValueError(“time data %r does not match format %r” %
ValueError: time data ‘1.5752484e+18’ does not match format ‘%Y-%m-%d %H:%M:%S.%f’
请问应该如何实现这个功能呢?
谢谢!