Skip to content

Instantly share code, notes, and snippets.

@KolevDarko
Created May 25, 2020 08:14
Show Gist options
  • Save KolevDarko/7e25a5c83c036e726c89fc52f4088cda to your computer and use it in GitHub Desktop.
Save KolevDarko/7e25a5c83c036e726c89fc52f4088cda to your computer and use it in GitHub Desktop.
Calculate biggest crypto movers based on price, volume or market cap
def calc_relative_diff(history_price, latest_price):
price_diff = latest_price - history_price
return round(price_diff / history_price, 2)
def calc_volume_diff(history_volume, latest_volume):
return latest_volume - history_volume
def calc_market_cap_diff(market_cap, history_price, latest_price):
return (latest_price - history_price) * market_cap
def calculate_crypto_winners(days_back):
latest_data = get_tickers()
history_data = get_history_at(days_back)
coin_supply = get_coin_supplies()
scores = []
for coin in coins:
base_coin = coin[:3]
latest = latest_data[coin]
history = history_data[coin]
price_diff = latest['last'] - history['average']
rel_price_diff = calc_relative_diff(history['average'], latest['last'])
volume_diff = calc_volume_diff(history['volume'], latest['volume'])
mcap_diff = calc_market_cap_diff(coin_supply[base_coin]['circulating_supply'], history['average'], latest['last'])
scores.append((coin, price_diff, rel_price_diff, volume_diff, mcap_diff))
# by specifying key=operator.itemgetter(1) we are sorting by the second field in scores, the price difference
# to sort by the other fields, rel_price_diff, volume_diff or mcap_diff pass in the fields index to the itemgetter function
scores.sort(reverse=True, key=operator.itemgetter(1))
i = 1
print("#. Coin, Price change, Price perc change, Volume change, Marketcap change")
for coin, price_diff, rel_price_diff, volume_diff, mcap_diff in scores:
print(f"{i}. {coin}, {price_diff}, {rel_price_diff}%, {volume_diff}, {mcap_diff} ")
i += 1
if __name__ == '__main__':
calculate_crypto_winners(7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment