Hello,

I am trying to feed the custom consolidated data from Bitfinex API to QC. I posted my original question here.

Basically, the consolidated candle data from Bitfinex API provided is not exactly what I am looking for. I was wondering if there is any way to provide a custom live data feed to QC?

In particular,  I would like to feed the data using the below function when doing live trading in stead of the data from calling Bitfinex API that I provided in my sample algorithm.

import requests
import pandas as pd
from datetime import datetime, timedelta

# EVERY 5 Mins, go to bitfinex collect all trades in the past 5 minutes and aggregate the data
def get_5mins_Bitfinex():
end_time = datetime.now() # past 5 minutes time
start_5mins = end_time - timedelta(minutes=5) # convert current time to timestamp
end_tstamp = round(datetime.timestamp(end_time)*1000,0) # convert past 5 minutes to timestamp
start_5mins_tstamp = round(datetime.timestamp(start_5mins)*1000,0)
url = 'https://api-pub.bitfinex.com/v2/trades/tBTCUSD/hist?limit=5000&start={}&end={}&sort=-1'.format(start_5mins_tstamp, end_tstamp)
response = requests.request('GET', url)
data = response.json()
data_df = pd.DataFrame(data, columns = ['id','date','volume','price'])

# aggregate the data
volume = data_df.volume.abs().sum()
volume_pos = data_df.volume.apply(lambda x: x if x >0 else 0).sum() # only take trade volume resulted from a taker buy order
open_price = data_df.price.values[0]
close_price = data_df.price.values[-1]
high_price = data_df.price.max()
low_price = data_df.price.min()
agg_data = [open_price, high_price, low_price, close_price, volume, volume_pos]

return agg_data

 

Best,

Hiep