-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
poloniex fetch ohlcv with pagination
github-actions[bot] edited this page Jun 11, 2026
·
2 revisions
# -*- coding: utf-8 -*-
import os
import sys
import ccxt # noqa: E402
exchange = ccxt.poloniex()
exchange.load_markets()
symbol = 'BTC/USDT'
timeframe = '5m'
since = exchange.parse8601('2024-01-01T00:00:00Z')
previous_length = 0
all_candles = []
limit = 500
duration = exchange.parse_timeframe(timeframe) * 1000
now = exchange.milliseconds()
while since < now:
try:
print('---------------------------------------------------------------')
print('Fetching ohlcvs since', exchange.iso8601(since))
endTime = since + duration * limit
candles = exchange.fetch_ohlcv(symbol, timeframe, since, limit, {
'until': endTime
})
print('Fetched', len(candles), 'candles')
print('From', exchange.iso8601(candles[0][0]), 'to', exchange.iso8601(candles[-1][0]))
since = candles[-1][0] + duration
all_candles += candles
total_length = len(all_candles)
print('Fetched', total_length, 'candles in total')
except ccxt.NetworkError as e:
print(e) # retry on next iteration
except ccxt.ExchangeError as e:
print(e)
break
print('Fetched', len(all_candles), 'candles since', exchange.iso8601(all_candles[0][0]), 'till', exchange.iso8601(all_candles[-1][0]))(If the page is not being rendered for you, you can refer to the mirror at https://docs.ccxt.com/)
- Install
- Examples
- Manual
- CCXT Pro
- Contributing
- Supported Exchanges
- Exchanges By Country
- API Spec By Method
- FAQ
- Changelog
- Awesome
- API Spec by Exchange
- fetchCurrencies
- alpaca
- apex
- ascendex
- aster
- backpack
- bigone
- binance
- bingx
- bit2c
- bitbank
- bitbns
- bitfinex
- bitflyer
- bitget
- bithumb
- bitmart
- bitmex
- bitopro
- bitrue
- bitso
- bitstamp
- bitteam
- bittrade
- bitvavo
- blockchaincom
- blofin
- btcbox
- btcmarkets
- btcturk
- bullish
- bybit
- bydfi
- cex
- coinbase
- coinbaseexchange
- coinbaseinternational
- coincheck
- coinex
- coinmate
- coinmetro
- coinone
- coinsph
- coinspot
- cryptocom
- cryptomus
- deepcoin
- delta
- deribit
- derive
- digifinex
- dydx
- exmo
- extended
- foxbit
- gate
- gemini
- grvt
- hashkey
- hibachi
- hitbtc
- hollaex
- htx
- hyperliquid
- independentreserve
- indodax
- kraken
- krakenfutures
- kucoin
- fetchBidsAsks
- latoken
- lbank
- lighter
- luno
- mercado
- mexc
- modetrade
- ndax
- novadax
- okx
- onetrading
- p2b
- pacifica
- paradex
- paymium
- phemex
- poloniex
- tokocrypto
- toobit
- upbit
- weex
- whitebit
- woo
- woofipro
- xt
- zaif
- fetchStatus