Skip to content

Instantly share code, notes, and snippets.

@pLabarta
Created July 8, 2020 00:00
Show Gist options
  • Save pLabarta/a07e1ff4b7429de4b79c6ccfecefb81e to your computer and use it in GitHub Desktop.
Save pLabarta/a07e1ff4b7429de4b79c6ccfecefb81e to your computer and use it in GitHub Desktop.
import requests
from datetime import datetime, timedelta
# Historical series by days
ticket_data = requests.get("https://explorer.dcrdata.org/api/chart/ticket-price?axis=time&bin=window").json()
# Current Stake/Ticket Info
current_ticket_data = requests.get("https://explorer.dcrdata.org/api/stake/diff").json()
print(current_ticket_data)
current_price = current_ticket_data['current']
next_price = current_ticket_data['estimates']['expected']
# Period trimming for last 142 and 28 days
def trim_price_series(date_delta, ticket_data):
price_series = ticket_data['price']
date_series = [ datetime.fromtimestamp(t) for t in ticket_data['t'] ]
count_series = ticket_data['count']
# find past date
date_x_before = datetime.today() - timedelta(days=date_delta)
# trim date series
trimmed_date = [ date for date in date_series if date > date_x_before ]
# trim price series
trimmed_price = price_series[-len(trimmed_date):]
return trimmed_price
last_28_price = trim_price_series(date_delta=28, ticket_data=ticket_data)
last_28_max = max(last_28_price) / 100000000 # to readable DCR amount
last_28_min = min(last_28_price) / 100000000 # to readable DCR amount
last_28_avg = ( sum(last_28_price) / len(last_28_price) ) / 100000000 # to readable DCR amount
# print("max last 28=",last_28_max)
# print("min last 28=",last_28_min)
# print("avg last 28=",last_28_avg)
# SIMPLE INDICATORS NOW
# IS TICKET CHEAP
is_ticket_cheap_28 = current_price < last_28_avg
print("Is ticket price cheap? (28 days) ",is_ticket_cheap_28)
# IS TICKET PRICE INCREASING
is_ticket_price_increasing = current_price < next_price
# print(current_price)
# print(next_price)
print("Is ticket increasing? ",is_ticket_price_increasing)
# TICKET PRICE LAST 28 DAYS INDICATOR
def get_current_price_thermometer(current,_min,_max):
if current > _max:
return 1
else:
normalized = (current - _min) / (_max - _min)
return normalized
ticket_price_thermometer = get_current_price_thermometer(current_price, last_28_min, last_28_max)
print("Ticket price thermometer (0 to 1, 28 days) = ",ticket_price_thermometer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment