Last active
May 23, 2024 15:20
-
-
Save mr-easy/5185b1dcdd5f9f908ff196446f092e9b to your computer and use it in GitHub Desktop.
Find listing date of any cryptocurrency pair on any exchange using ccxt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Here is a sample output for binance exchange. These are the start time stamp on which the currency pair got listed om binance exchange. | |
1INCH/BTC 1608872340001 2020-12-25T04:59:00.001Z | |
1INCH/BUSD 1614081540001 2021-02-23T11:59:00.001Z | |
1INCH/USDT 1608872340001 2020-12-25T04:59:00.001Z | |
1INCHDOWN/USDT 1618471140001 2021-04-15T07:19:00.001Z | |
1INCHUP/USDT 1618471140001 2021-04-15T07:19:00.001Z | |
AAVE/BKRW 1602730740001 2020-10-15T02:59:00.001Z | |
AAVE/BNB 1602730740001 2020-10-15T02:59:00.001Z | |
AAVE/BRL 1627034340001 2021-07-23T09:59:00.001Z | |
AAVE/BTC 1602730740001 2020-10-15T02:59:00.001Z | |
AAVE/BUSD 1602730740001 2020-10-15T02:59:00.001Z | |
AAVE/ETH 1602730740001 2020-10-15T02:59:00.001Z | |
AAVE/USDT 1602730740001 2020-10-15T02:59:00.001Z | |
AAVEDOWN/USDT 1606373940001 2020-11-26T06:59:00.001Z | |
AAVEUP/USDT 1606373940001 2020-11-26T06:59:00.001Z | |
ACM/BTC 1614164340001 2021-02-24T10:59:00.001Z | |
ACM/BUSD 1614164340001 2021-02-24T10:59:00.001Z | |
ACM/USDT 1614164340001 2021-02-24T10:59:00.001Z | |
ADA/AUD 1614938340001 2021-03-05T09:59:00.001Z | |
ADA/BIDR 1624010340001 2021-06-18T09:59:00.001Z | |
ADA/BKRW 1596085140001 2020-07-30T04:59:00.001Z | |
ADA/BNB 1523937660001 2018-04-17T04:01:00.001Z | |
ADA/BRL 1614333540001 2021-02-26T09:59:00.001Z | |
ADA/BTC 1512044880001 2017-11-30T12:28:00.001Z | |
ADA/BUSD 1574308740001 2019-11-21T03:59:00.001Z | |
ADA/ETH 1512044940001 2017-11-30T12:29:00.001Z | |
ADA/EUR 1605261540001 2020-11-13T09:59:00.001Z | |
ADA/GBP 1614333540001 2021-02-26T09:59:00.001Z | |
ADA/PAX 1553659140001 2019-03-27T03:59:00.001Z | |
ADA/RUB 1616140740001 2021-03-19T07:59:00.001Z | |
ADA/TRY 1614333540001 2021-02-26T09:59:00.001Z | |
ADA/TUSD 1545192060001 2018-12-19T04:01:00.001Z | |
ADA/USDC 1553659140001 2019-03-27T03:59:00.001Z | |
ADA/USDT 1523937660001 2018-04-17T04:01:00.001Z | |
ADADOWN/USDT 1594887420001 2020-07-16T08:17:00.001Z | |
ADAUP/USDT 1594887420001 2020-07-16T08:17:00.001Z | |
ADX/BNB 1511925120001 2017-11-29T03:12:00.001Z | |
ADX/BTC 1511924940001 2017-11-29T03:09:00.001Z | |
ADX/BUSD 1627034340001 2021-07-23T09:59:00.001Z | |
ADX/ETH 1511925000001 2017-11-29T03:10:00.001Z | |
ADX/USDT 1635501540001 2021-10-29T09:59:00.001Z | |
AE/BNB 1518170357616 2018-02-09T09:59:17.616Z | |
AE/BTC 1518170297593 2018-02-09T09:58:17.593Z | |
AE/ETH 1518170297604 2018-02-09T09:58:17.604Z | |
AERGO/BTC 1603274340001 2020-10-21T09:59:00.001Z | |
AERGO/BUSD 1603274340001 2020-10-21T09:59:00.001Z | |
AGI/BNB 1528192740001 2018-06-05T09:59:00.001Z | |
AGI/BTC 1528192740001 2018-06-05T09:59:00.001Z | |
AGI/ETH 1528192740001 2018-06-05T09:59:00.001Z | |
AGIX/BTC 1622620740001 2021-06-02T07:59:00.001Z | |
AGLD/BNB 1633417140001 2021-10-05T06:59:00.001Z | |
AGLD/BTC 1633417140001 2021-10-05T06:59:00.001Z | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################################################# | |
## Author: mr-easy ## | |
## Webpage: mr-easy.github.io ## | |
################################################################################################################# | |
## While collecting cryptocurrency data using ccxt library, I found that it's difficult to know the start date ## | |
## of a currency pair, i.e. the timestamp at which that symbol(currency pair) was listed on that exchange. ## | |
## This code snippet will help in finding that for any speicific exchange. ## | |
## It uses binary search and returns the timestamp at which ccxt's fetch_ohlcv return non-empty result. ## | |
################################################################################################################# | |
import ccxt | |
import datetime as dt | |
def find_start_time(exchange, symbol, start_time, end_time, timeframe): | |
mid_time = (start_time + end_time)//2 | |
#print(start_time, mid_time, end_time, end_time-start_time) | |
if(mid_time == start_time): return mid_time+1 | |
ohlcv = exchange.fetch_ohlcv(symbol, timeframe, mid_time, limit=1) | |
if(len(ohlcv) == 0): | |
return find_start_time(exchange, symbol, mid_time, end_time, timeframe) | |
else: | |
return find_start_time(exchange, symbol, start_time, mid_time, timeframe) | |
if __name__ == '__main__': | |
exchange = ccxt.binance({ 'enableRateLimit': True }) | |
exchange.load_markets() | |
for symbol in exchange.symbols: | |
start_time = int(dt.datetime(2015,1,1).timestamp() * 1000) | |
end_time = int(dt.datetime(2021,11,1).timestamp() * 1000) | |
timeframe = '1m' | |
symbol_start_time = find_start_time(exchange, symbol, start_time, end_time, timeframe) | |
print(symbol, "\t", symbol_start_time, "\t", exchange.iso8601 (symbol_start_time)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @MarkWClements I checked it, it is working perfectly fine for me. I got this output for the first coin-pair:
1INCH/BTC 1608872340001 2020-12-25T04:59:00.001Z