Nicholas Tan Yi Da

How to get historical data (crypto algo competition)

Programming


Hi, I tried to use the getHistoricalBar to retrieve past price data based on the tech docs, but it doesnt work, got some missing evt or mevt error.

Below is the one I tried based on the tech docs
"""
class AlgoEvent:
    def __init__(self,mEvt):
        pass
        
    def start(self):
        self.evt = AlgoAPI_Backtest.AlgoEvtHandler(self, mEvt)
        self.evt.start()


    def retrieve_data(self):
        mkt_data = pd.DataFrame(columns = ['close_time', 'close_bid', 'close_ask','close_mid','open_mid','open_high','open_low','close_mid','volume'])
        contract = {"instrument": 'BTCUSD'}
        numOfBar = 105216
        interval ='M15'
        timestamp = datetime(2020,1,1,0,0,0)
        res = self.evt.getHistoricalBar(contract, numOfBar, interval, timestamp)
        for t in res:
            mkt_data.append([res[t],res[t]['b'],res[t]['a'],res[t]['m'],res[t]['o'],res[t]['h'],res[t]['l'],res[t]['c'],res[t]['v']])
        
        return mkt_data
"""



Tried to do another way but it also didnt work. Can someone help me with this?

Another way i tried:
"""
def retrieve_data():
        mkt_data = pd.DataFrame(columns = ['close_time', 'close_bid', 'close_ask','close_mid','open_mid','open_high','open_low','close_mid','volume'])
        contract = {"instrument": 'BTCUSD'}
        numOfBar = 105216
        interval ='M15'
        timestamp = datetime(2020,1,1,0,0,0)
        
        res = AlgoAPI_Backtest.AlgoEvtHandler().start(mEvt).getHistoricalBar(contract, numOfBar, interval, timestamp)
        for t in res:
            mkt_data.append([res[t],res[t]['b'],res[t]['a'],res[t]['m'],res[t]['o'],res[t]['h'],res[t]['l'],res[t]['c'],res[t]['v']])
        
        return mkt_data
"""
 
Nicholas Tan Yi Da
tried to do it within jupyter notebook, wanted to do some data analysis
 
Bumblebee
Do you run these codes in [Backtest] or in Jupyter Notebook? 
I tested for 1 minute bar in [Backtest] and it works well.