Skip to content
Advertisement

How to get the price of a crypto at a given time in the past?

Is there any way I can use ccxt to extract the price of a crypto currency at a given time in the past?

Example: get price of BTC on binance at time 2018-01-24 11:20:01

Advertisement

Answer

You can use the fetch_ohlcv method on the binance class in CCXT

def fetch_ohlcv(self, symbol, timeframe='1m', since=None, limit=None, params={}):


You’ll need the date as a timestamp in milliseconds, and you can only get it precise to the minute, so take away the seconds, or you’ll get the price for the minute after

JavaScript

You can only get the price of BTC in comparison to another currency, we’ll use USDT(closely matches USD) as our comparison currency, so we will look up the price of BTC in the BTC/USDT market

When we use the method, we will set since to your timestamp, but set the limit as one so that we only get one price

JavaScript

Which will return candlestick values for one candle

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement