Skip to content

Instantly share code, notes, and snippets.

function cosineDistanceBetweenPoints(lat1, lon1, lat2, lon2) {
const R = 6371e3;
const p1 = lat1 * Math.PI/180;
const p2 = lat2 * Math.PI/180;
const deltaP = p2 - p1;
const deltaLon = lon2 - lon1;
const deltaLambda = (deltaLon * Math.PI) / 180;
const a = Math.sin(deltaP/2) * Math.sin(deltaP/2) +
Math.cos(p1) * Math.cos(p2) *
Math.sin(deltaLambda/2) * Math.sin(deltaLambda/2);
function pythagoreanDistanceBetweenPoints(lat1, lon1, lat2, lon2) {
const R = 6371e3;
const x = (lon2-lon1) * Math.cos((lat1+lat2)/2);
const y = (lat2-lat1);
const d = Math.sqrt(x*x + y*y) * R;
return d;
}
function haversineDistanceBetweenPoints(lat1, lon1, lat2, lon2) {
const R = 6371e3;
const p1 = lat1 * Math.PI/180;
const p2 = lat2 * Math.PI/180;
const deltaLon = lon2 - lon1;
const deltaLambda = (deltaLon * Math.PI) / 180;
const d = Math.acos(
Math.sin(p1) * Math.sin(p2) + Math.cos(p1) * Math.cos(p2) * Math.cos(deltaLambda),
) * R;
return d;
import sys
import time
from fairlay_public_api import FairlayPythonPublic
fairlay = FairlayPythonPublic()
# Dictionary to store up-to-date market asks and bids
order_dict = {}
while True:
markets = fairlay.get_markets_and_odds({
import numpy as np
def moving_average(a, n=3) :
ret = np.cumsum(a, dtype=float)
ret[n:] = ret[n:] - ret[:-n]
return ret[n - 1:] / n
n = 12
plt.plot(moving_average(btc_data, n=n))
plt.plot(btc_data[n - 1:])
plt.title('Daily Low Bitcoin Prices - 1 Year')
import matplotlib.pyplot as plt
plt.plot(btc_data)
plt.title('Daily Low Bitcoin Prices - 1 Year')
plt.ylabel('Daily Low - USD')
plt.show()
# Fetch a dict of a year of BTC prices
btc_data = getYearHistoricals('BTC')['data_points']
# Tranform price dict to list of low prices
btc_data = [float(point['low_price']) for point in btc_data]
def getYearHistoricals(symbol):
symbol_dict = {
'BTC': '3d961844-d360-45fc-989b-f6fca761d511',
'ETH': '76637d50-c702-4ed1-bcb5-5b0732a81f48',
'LTC': '383280b1-ff53-43fc-9c84-f01afd0989cd',
'BCH': '2f2b77c4-e426-4271-ae49-18d5cb296d3a',
'DOGE': '1ef78e1b-049b-4f12-90e5-555dcf2fe204',
'ETC': '7b577ce3-489d-4269-9408-796a0d1abb3a',
'BSV': '086a8f9f-6c39-43fa-ac9f-57952f4a1ba6'
}
import robin_stocks as r
username = ''
password = ''
r.login(username, password)
def getHistoricals(symbol, span='year'):
symbol_dict = {
'BTC': '3d961844-d360-45fc-989b-f6fca761d511',
'ETH': '76637d50-c702-4ed1-bcb5-5b0732a81f48',
'LTC': '383280b1-ff53-43fc-9c84-f01afd0989cd',
'BCH': '2f2b77c4-e426-4271-ae49-18d5cb296d3a',
'DOGE': '1ef78e1b-049b-4f12-90e5-555dcf2fe204',
'ETC': '7b577ce3-489d-4269-9408-796a0d1abb3a',
'BSV': '086a8f9f-6c39-43fa-ac9f-57952f4a1ba6'
}