-
Notifications
You must be signed in to change notification settings - Fork 0
/
alpaca.py
32 lines (25 loc) · 1002 Bytes
/
alpaca.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
from typing import *
from secret import API_KEY, SECRET_KEY
from alpaca_trade_api import TimeFrame
import alpaca_trade_api as tradeapi
class AlpacaClient:
def __init__(self):
self._key_id = API_KEY
self._secret_key = SECRET_KEY
self._base_url_ = 'https://paper-api.alpaca.markets'
self._data_url_ = 'https://data.alpaca.markets'
self.authenticate_bot()
def authenticate_bot(self):
try:
self._api = tradeapi.REST(
self._key_id,
self._secret_key,
self._base_url_
)
print('connection made')
except Exception as e:
print('connection not made error: \n')
print(e)
def get_historical_data(self, symbol: str, start_time: Optional[int] = None, end_time: Optional[int] = None):
raw_candles = self._api.get_crypto_bars(symbol,TimeFrame.Minute,limit=1500, start = '2021-06-08').df
print(raw_candles)