Skip to content

Instantly share code, notes, and snippets.

@veridelisi
Created April 4, 2024 09:31
Show Gist options
  • Save veridelisi/87782ec55cc947e7ea3613874ee32282 to your computer and use it in GitHub Desktop.
Save veridelisi/87782ec55cc947e7ea3613874ee32282 to your computer and use it in GitHub Desktop.
Volume and Price of ASRUSDT Pair.py
import requests
import json
from datetime import datetime, timedelta
# Calculate the start and end timestamps for the last two weeks
end_time = datetime.now()
start_time = end_time - timedelta(days=90)
# Convert to Unix timestamp in seconds
start_timestamp = int(start_time.timestamp())
end_timestamp = int(end_time.timestamp())
# Construct the request URL
base = "https://graph-api.btcturk.com"
method = f"/v1/ohlcs?pair=ASRUSDT&from={start_timestamp}&to={end_timestamp}"
uri = base + method
# Fetch the data
response = requests.get(url=uri)
data = response.json()
# Print the result
print(json.dumps(data, indent=2))
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from datetime import datetime
# Assuming 'dates', 'volumes', and 'averages' are already defined
# Sample extraction (replace 'data' with your actual JSON response)
dates = [datetime.utcfromtimestamp(item['time']) for item in data]
volumes = [item['volume'] for item in data]
averages = [item['average'] for item in data]
fig, ax1 = plt.subplots()
fig, ax1 = plt.subplots(figsize=(15, 8))
color = 'tab:red'
ax1.set_xlabel('Date')
ax1.set_ylabel('Volume of ASR', color=color)
ax1.plot(dates, volumes, color=color, alpha=0.5)
ax1.fill_between(dates, 0, volumes, color='tab:red', alpha=0.3)
ax1.tick_params(axis='y', labelcolor=color)
ax2 = ax1.twinx()
color = 'tab:blue'
ax2.set_ylabel('Average Price of ASR', color=color)
ax2.scatter(dates, averages, color='tab:blue', alpha=0.5)
ax2.tick_params(axis='y', labelcolor=color)
# Format the x-axis to show dates clearly
ax1.xaxis.set_major_locator(mdates.WeekdayLocator())
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment