Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save veridelisi/5478759a6afb26b94adc62c027e3e149 to your computer and use it in GitHub Desktop.
Save veridelisi/5478759a6afb26b94adc62c027e3e149 to your computer and use it in GitHub Desktop.
Ranked Trading Volume (Volume*Price) of BtcTurk Pairs(TRY).py
import requests
import matplotlib.pyplot as plt
import pandas as pd # For displaying the table
# Fetch Data
response = requests.get("https://api.btcturk.com/api/v2/ticker")
data = response.json()
# Parse Data for TRY pairs, keeping them unchanged
try_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']
]
# Parse Data for USDT pairs, excluding USDTTRY, and multiplying by 33
#today 23.04.2024 and 1 dollar : 33 try
usdt_pairs_data = [
(item['pair'], float(item['last']), float(item['volume']), float(item['last']) * float(item['volume']) * 33)
for item in data['data']
if 'USDT' in item['pair'] and item['pair'] != 'USDTTRY'
]
# Combine the data
combined_data = try_pairs_data + usdt_pairs_data
# Sort the combined data by the product of volume and price in descending order
combined_data.sort(key=lambda x: x[3], reverse=True)
# Unpack the sorted data for the top ten
top_ten_data = combined_data[:10]
pair_names, prices, volumes, volume_price_product = zip(*top_ten_data)
# Visualization with a Bar Chart for Top Ten
fig, ax1 = plt.subplots(figsize=(12, 8))
color = 'tab:red'
ax1.set_xlabel('Pair')
ax1.set_ylabel('Adjusted Volume*Price', color=color)
ax1.bar(pair_names, volume_price_product, color=color, alpha=0.6, label='Adjusted Volume*Price')
ax1.tick_params(axis='y', labelcolor=color)
ax1.set_xticks(range(len(pair_names)))
ax1.set_xticklabels(pair_names, rotation=45, ha="center")
plt.title('Top Ten Ranked Trading Volume (Volume*Price) of BtcTurk Pairs')
plt.show()
# Displaying a table of the top ten pairs
df = pd.DataFrame({
'Pair': pair_names,
'Volume*Price (Adjusted)': volume_price_product
})
print(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment