-
Notifications
You must be signed in to change notification settings - Fork 20
/
connection.py
30 lines (25 loc) · 937 Bytes
/
connection.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
"""
This script creates various object to connect with different components of Trade API"
"""
import configparser as ConfigParser
import alpaca_trade_api as tradeapi
class Client:
"""
A class to establish the connection with the brokers API.
"""
def __init__(self):
"""
Establish the API connection
"""
configParser = ConfigParser.RawConfigParser()
configFile = 'config.cfg'
configParser.read(configFile)
self.api_key = configParser.get('alpaca', 'api_key')
self.api_secret = configParser.get('alpaca', 'api_secret')
self.base_url = configParser.get('alpaca', 'base_url')
def connect(self):
return tradeapi.StreamConn(str(self.api_key), str(
self.api_secret), str(self.base_url))
def api(self):
return tradeapi.REST(str(self.api_key), str(
self.api_secret), str(self.base_url), api_version='v2')