forked from aritroCoder/EtherEyes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.py
63 lines (45 loc) · 1.16 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import requests
import numpy as np
from statsforecast.models import AutoARIMA
import json
def get_timeseries():
with open('key.json') as f:
data = json.load(f)
print(data)
key = data['key']
history_data = requests.get(
'https://api.owlracle.info/v3/eth/history?apikey={}&candles=100&txfee=true'
.format(key))
history_data = history_data.json()
low = []
for obj in history_data:
low.append(obj['gasPrice']['low'])
low.reverse()
return np.array(low)
def get_prediction():
values = get_timeseries()
model = AutoARIMA()
predictions = model.forecast(values, 2)
print("Pred: ", predictions)
prediction_json = {
'low_30_minutes': predictions['mean'][0],
'low_60_minutes': predictions['mean'][1]
}
return prediction_json
app = FastAPI()
origins = [
"*",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
async def root():
pred = get_prediction()
return pred