【发布时间】:2019-11-02 16:49:34
【问题描述】:
我每秒都会收到以下格式的股票数据
'ohlc': {'close': 75.95, 'high': 83.5, 'low': 64.6, 'open':75.95},last_price': 75.0,timestamp': datetime.datetime(2019, 11, 2 , 11, 20, 15)
由于我的交易时间从上午 9:30 开始,我喜欢只保存前五分钟的股票高低,因此股票的高低应该在 9:30 到 9 之间:上午 35 点。以下是我正在使用的代码,但我无法得到结果。 请帮我解决这个问题。基本上我需要保存 5 分钟的数据,但我不明白该怎么做。
start_time = datetime.time(9, 30)
end_time = datetime.time(9, 35)
current_time = datetime.datetime.now().time()
candle_start_time = current_time >= start_time and current_time <= end_time
breakout_time_start = current_time >= start_time
while candle_start_time is True:
print('time started')
while current_time > end_time:
print('time extended')
while current_time < end_time:
print('time extended 1')
【问题讨论】:
-
嘿@tanjiro,在您的问题中您提到您需要在特定时间范围内存储一些值。在代码中,您只提供了一些时间。“5 分钟的数据”如何发挥作用?
-
我不明白你的代码。当您从服务器获取新数据时,您只需检查
start_time <= time_from_timestamp <= end_time。 -
你的
while循环没用。您总是在while中检查相同的值。在while内部,您必须从服务器获取新值并从 tis 数据中获取时间,并将其用于您在while中使用的变量中 -
@stupidwolf 请把代码放在一边,我需要的是从上午 9:30 到上午 9:35 的传入数据,应该保存,即股票的高值和低值,以及数据的任何变化9:35 之后的高低不应该在保存的变量中考虑。
-
@furas 请把代码放在一边,我需要的是从上午 9:30 到上午 9:35 的传入数据,应该保存,即股票的高值和低值,以及数据的任何变化9:35 之后的高低不应该在保存的变量中考虑
标签: python time timedelta stock