Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save veridelisi/b6385932b68e842d5ed45edce3b4d0fe to your computer and use it in GitHub Desktop.
Save veridelisi/b6385932b68e842d5ed45edce3b4d0fe to your computer and use it in GitHub Desktop.
Volume and Price of BtcTurk USDT Pairs (Log Scale)
import requests
import matplotlib.pyplot as plt
# Fetch Data
response = requests.get("https://api.btcturk.com/api/v2/ticker")
data = response.json()
#Gets snapshot information about the last trade (tick), best bid/ask and 24h volume.
# Parse Data for USDT pairs only, excluding USDTTRY
pairs_data = [
(item['pair'], float(item['last']), float(item['volume']))
for item in data['data']
if 'USDT' in item['pair'] and item['pair'] != 'USDTTRY'
]
# Sort the pairs by volume in descending order
pairs_data.sort(key=lambda x: x[2], reverse=True)
# Unpack the sorted data
pair_names, prices, volumes = zip(*pairs_data)
# Visualization with a Bar Chart and a log scale
indices = range(len(prices))
fig, ax1 = plt.subplots(figsize=(20, 10))
color = 'tab:red'
ax1.set_xlabel('Pair')
ax1.set_ylabel('Volume (log scale)', color=color)
ax1.bar(indices, volumes, color=color, alpha=0.6, label='Volume')
ax1.set_yscale('log') # Log scale for volume
ax1.tick_params(axis='y', labelcolor=color)
ax1.set_xticks(indices)
ax1.set_xticklabels(pair_names, rotation=90, ha="center")
ax1.tick_params(axis='x', which='major', labelsize=9)
# Twin axes for price
ax2 = ax1.twinx()
color = 'tab:blue'
ax2.set_ylabel('Price (log scale)', color=color)
ax2.plot(indices, prices, color=color, marker='o', linestyle='None')
ax2.set_yscale('log') # Log scale for price
ax2.tick_params(axis='y', labelcolor=color)
fig.tight_layout()
plt.title('Volume and Price of BtcTurk USDT Pairs (Log Scale, ordered by Volume)')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment