forked from hackingthemarkets/alpaca-bracket-order
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder.py
38 lines (26 loc) · 930 Bytes
/
order.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
import requests, json
from config import *
BASE_URL = "https://paper-api.alpaca.markets"
ACCOUNT_URL = "{}/v2/account".format(BASE_URL)
ORDERS_URL = "{}/v2/orders".format(BASE_URL)
HEADERS = {'APCA-API-KEY-ID': API_KEY, 'APCA-API-SECRET-KEY': SECRET_KEY}
def get_account():
r = requests.get(ACCOUNT_URL, headers=HEADERS)
return json.loads(r.content)
def create_order(symbol, qty, side, type, time_in_force):
data = {
"symbol": symbol,
"qty": qty,
"side": side,
"type": type,
"time_in_force": time_in_force
}
r = requests.post(ORDERS_URL, json=data, headers=HEADERS)
return json.loads(r.content)
def get_orders():
r = requests.get(ORDERS_URL, headers=HEADERS)
return json.loads(r.content)
response = create_order("AAPL", 100, "buy", "market", "gtc")
response = create_order("MSFT", 1000, "buy", "market", "gtc")
orders = get_orders()
print(orders)