-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbetaAlpacaAPI.py
More file actions
35 lines (28 loc) · 918 Bytes
/
betaAlpacaAPI.py
File metadata and controls
35 lines (28 loc) · 918 Bytes
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
import alpaca_trade_api as TradingAPI
import requests
import config
ORDERS_URL = '{}/v2/orders'.format(config.APCA_API_BASE_URL)
def createMarketOrder():
ticker = 'AAPL'
qty = '2'
side = 'buy'
ordertype = 'market'
data = {
'symbol': ticker,
'qty': qty,
'side': side,
'type': ordertype,
'time_in_force': 'day'
}
r = requests.post(ORDERS_URL, json=data, headers=config.HEADERS)
return r.json()
def get_account_info():
ACCOUNT_URL = f"{config.APCA_API_BASE_URL}/v2/account"
response = requests.get(ACCOUNT_URL, headers=config.HEADERS)
if response.status_code == 200: # HTTP 200 means OK
account_info = response.json()
return account_info
else:
print(f"Failed to get account information. Error: {response.content}")
return None
print(createMarketOrder())