def get_volume_from_history(history, candle_size):
"""
Returns volume for given candle_size
:param history: history data
:param candle_size: in minutes
:return: Calculated volume for given candle_size
"""
volume = 0.0
epoch_now = int(time.time())
epoch_candle_start = epoch_now - candle_size * 60
pattern = '%Y-%m-%dT%H:%M:%S'
for item in history:
time_string = item['TimeStamp'].split('.', 1)[0]
dt = datetime.datetime.strptime(time_string, pattern)
item_epoch = dt.replace(tzinfo=timezone.utc).timestamp()
if item_epoch >= epoch_candle_start:
quantity = item['Quantity']
volume += quantity
return volume
评论列表
文章目录