-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathIdatahandler.py
75 lines (53 loc) · 1.69 KB
/
Idatahandler.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
64
65
66
from abc import ABC, abstractmethod
import json
import datetime
import os.path
import pandas as pd
import finnhub_api
import constants
import config
import api
import utility
import exceptions
class Idata_handler(ABC):
def __init__(self):
self.API = api.API()
self.utility = utility.utility()
def ohlcv_load_from_dict(self, ticker):
ticker = pd.DataFrame(ticker)
if(ticker.columns[4] == 's'):
ticker.drop(ticker.columns[4], axis=1, inplace=True)
ticker.columns = ['close', 'high', 'low', 'open', 'date', 'volume']
# ticker.columns = ['close', 'high', 'low', 'open', 'date']
else:
ticker.columns = ['close', 'high', 'low', 'open', 'date', 'volume']
# ticker.columns = ['close', 'high', 'low', 'open', 'date']
ticker.sort_values('date', inplace=True)
return ticker
def fetch_ticker(self, ticker_name, from_date=0, to_date=0):
timeframe = config.TIMEFRAME
if to_date==0:
to_time = datetime.datetime.now()
to_time = int(to_time.replace(tzinfo=datetime.timezone.utc).timestamp())
else:
to_time = to_date
if from_date==0:
from_time = datetime.datetime.now() - datetime.timedelta(30)
from_time = int(from_time.replace(tzinfo=datetime.timezone.utc).timestamp())
else:
from_time = from_date
ticker = self.API.get_candles(ticker_name, timeframe, from_time, to_time)
if(ticker['s']=="no_data"):
raise exceptions.FinnhubRequestException("No Data!")
ticker = self.ohlcv_load_from_dict(ticker)
return ticker
def ohlcv_save(self, ticker, ticker_name):
pass
def ohlcv_load(self, ticker_name):
pass
def refresh_tickers(self):
pass
def update_live_tickers(self, tickers):
pass
def fetch_backtest_tickers(self, start_date, end_date):
pass