Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
change prices to coinbase api
Browse files Browse the repository at this point in the history
make prices not be reversed
  • Loading branch information
CelestialCrafter committed Nov 18, 2023
1 parent 5c9f71b commit aa5a0a1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"pair": "ETH/USD"
"pair": "ETH-USD",
"interval": 21600
}
15 changes: 9 additions & 6 deletions price.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import numpy as np
from requests import get

def get_prices(pair, interval=15):
ohlc = get(f'https://api.kraken.com/0/public/OHLC?pair={pair}&interval={interval}').json()
ticker = get(f'https://api.kraken.com/0/public/Ticker?pair={pair}').json()
# {60 300 900 3600 21600 86400}
# 1m 5m 15m 1h 6h 1d
# 5h 25h 3d3h 12d12h 2mo15d 10mo
def get_prices(pair, interval=21600):
ohlc = get(f'https://api.exchange.coinbase.com/products/{pair}/candles?granularity={interval}').json()
ticker = get(f'https://api.exchange.coinbase.com/products/{pair}/ticker').json()

current = float(list(ticker['result'].values())[0]['c'][0])
prices = [float(point[4]) for point in list(ohlc['result'].values())[0]]
current = float(ticker['price'])
prices = [point[4] for point in ohlc]

return np.array([*prices, current])
return np.flip([current, *prices])
2 changes: 1 addition & 1 deletion views/internal_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def internal_checker():
return 'Unauthorized', 401

config = json.load(open('config.json', 'r'))
prices = get_prices(config['pair'], interval=1440)
prices = get_prices(config['pair'], interval=config['interval'])

# Convert list of algorithms into {name: signal}
algorithms = get_algorithms()
Expand Down
2 changes: 1 addition & 1 deletion views/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def plot(algorithm):
config = json.load(open('config.json', 'r'))
prices = get_prices(config['pair'], interval=1440)
prices = get_prices(config['pair'], interval=config['interval'])

if algorithm not in ['price', *get_algorithms()]:
return 'Invalid Algorithm', 404
Expand Down

0 comments on commit aa5a0a1

Please sign in to comment.