Skip to content

Instantly share code, notes, and snippets.

@Zettt
Created March 22, 2024 17:22
Show Gist options
  • Save Zettt/66ddbfdac404140e1b5f31f70eadf700 to your computer and use it in GitHub Desktop.
Save Zettt/66ddbfdac404140e1b5f31f70eadf700 to your computer and use it in GitHub Desktop.
# 1. Download the top 100 from CoinMarketCap.
# 2. Download all USDT-based pairs from Binance.
# 3. Print out a list of the top 100 coins tradeable on Binance.
#
# The theory is that the top coins are going to perform best
# in a bull market. With this information we can build a momentum
# strategy based on the top coins only.
# Suggestion usually is to check the top 100 coins monthly,
# then rebalance the portfolio.
import requests
import json
def get_coinmarketcap_top100():
# Register for an API key on the CoinMarketCap website
api_key = "your api key"
endpoint = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest'
parameters = {
'sort': 'market_cap',
'sort_dir': 'desc',
'cryptocurrency_type': 'all',
'limit': 100
}
headers = {'X-CMC_PRO_API_KEY': api_key}
response = requests.get(endpoint, headers=headers, params=parameters)
data = json.loads(response.text)
coins = data['data']
top100_symbols = [coin['symbol'] + "USDT" for coin in data['data']]
# print(f'Top 100 Symbols: {top100_symbols}\n')
return top100_symbols
def get_binance_usdt_pairs():
url = 'https://api.binance.com/api/v3/exchangeInfo'
response = requests.get(url)
data = response.json()
usdt_pairs = [pair['symbol'] for pair in data['symbols'] if pair['quoteAsset'] == 'USDT' and pair['status'] == 'TRADING']
# print(f'USDT Pairs: {usdt_pairs}\n')
return usdt_pairs
def find_common_pairs(top100_symbols, usdt_pairs):
common_pairs = set(top100_symbols) & set(usdt_pairs)
return common_pairs
if __name__ == '__main__':
top100_symbols = get_coinmarketcap_top100()
usdt_pairs = get_binance_usdt_pairs()
common_pairs = find_common_pairs(top100_symbols, usdt_pairs)
print("Cryptocurrencies in the top 100 on CoinMarketCap which are tradeable on Binance (USDT pairs):")
print(common_pairs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment