Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

609
Visualizações
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

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

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

timestamp = int(datetime.datetime.strptime("2018-01-24 11:20:00", "%Y-%m-%d %H:%M:%S").timestamp() * 1000)

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

import ccxt
from pprint import pprint

print('CCXT Version:', ccxt.__version__)

exchange = ccxt.binance()
timestamp = int(datetime.datetime.strptime("2018-01-24 11:20:00+00:00", "%Y-%m-%d %H:%M:%S%z").timestamp() * 1000)
response = exchange.fetch_ohlcv('BTC/USDT', '1m', timestamp, 1)
pprint(response)

Which will return candlestick values for one candle

[ 
  1516792860000, // timestamp
  11110, // value at beginning of minute, so the value at exactly "2018-01-24 11:20:01"
  11110.29, // highest value between "2018-01-24 11:20:01" and "2018-01-24 11:20:02"
  11050.91, // lowest value between "2018-01-24 11:20:01" and "2018-01-24 11:20:02"
  11052.27, // value just before "2018-01-24 11:20:02"
  39.882601 // The volume traded during this minute
]
over 4 years ago · Santiago Trujillo Relatório

0

You can do that with CCXT's unified fetchOHLCV method:

  • https://docs.ccxt.com/en/latest/manual.html#ohlcv-candlestick-charts
  • https://docs.ccxt.com/en/latest/manual.html#ohlcv-structure

We highly recommend reading the entire CCXT Manual from top to bottom, it will really save your time:

  • https://docs.ccxt.com/
  • https://github.com/ccxt/ccxt/wiki
  • https://github.com/ccxt/ccxt/wiki/Manual

Also, check out the examples here:

  • https://github.com/ccxt/ccxt/tree/master/examples
  • https://github.com/ccxt/ccxt/tree/master/examples#see-also
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda