Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save veridelisi/07e8ba0ba0b5b046cdf8ffaaf7f617c8 to your computer and use it in GitHub Desktop.
Save veridelisi/07e8ba0ba0b5b046cdf8ffaaf7f617c8 to your computer and use it in GitHub Desktop.
Ranked Trading Volume (Volume*Price) of BtcTurk TRY Pairs.py
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 TRY pairs only, excluding USDT pairs
pairs_data = [
(item['pair'], float(item['last']), float(item['volume']), float(item['last']) * float(item['volume']))
for item in data['data']
if 'TRY' in item['pair'] and 'USDT' not in item['pair']
]
# Sort the pairs by the product of volume and price in descending order
pairs_data.sort(key=lambda x: x[3], reverse=True)
# Unpack the sorted data
pair_names, prices, volumes, volume_price_product = zip(*pairs_data)
# Visualization with a Bar Chart
indices = range(len(prices))
fig, ax1 = plt.subplots(figsize=(20, 10))
color = 'tab:blue'
ax1.set_xlabel('Pair')
ax1.set_ylabel('Volume*Price', color=color)
ax1.bar(indices, volume_price_product, color=color, alpha=0.6, label='Volume*Price')
ax1.tick_params(axis='y', labelcolor=color)
ax1.set_xticks(indices)
ax1.set_xticklabels(pair_names, rotation=90, ha="center")
plt.title('Ranked Trading Volume (Volume*Price) of BtcTurk TRY Pairs')
plt.show()
@veridelisi
Copy link
Author

#top10

Consider only the top 10 entries for visualization

top_10_pairs_data = pairs_data[:10]

Unpack the sorted data

pair_names, prices, volumes, volume_price_product = zip(*top_10_pairs_data)

Visualization with a Bar Chart

indices = range(len(prices))

fig, ax1 = plt.subplots(figsize=(20, 10))

color = 'tab:blue'
ax1.set_xlabel('Pair')
ax1.set_ylabel('VolumePrice', color=color)
ax1.bar(indices, volume_price_product, color=color, alpha=0.6, label='Volume
Price')
ax1.tick_params(axis='y', labelcolor=color)
ax1.set_xticks(indices)
ax1.set_xticklabels(pair_names, rotation=90, ha="center")

plt.title('Ranked Trading Volume (Volume*Price) of BtcTurk TRY Pairs')
plt.show()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment