-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTest.py
More file actions
51 lines (19 loc) · 640 Bytes
/
Test.py
File metadata and controls
51 lines (19 loc) · 640 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
36
37
38
39
40
41
42
43
44
45
import alpaca_trade_api as tradeapi
api = tradeapi.REST('PKVBXZRT0VWL3U5RQG3Y', 'Mnm9xzhzrFh2K7b3FoD2z6gIxLtth0u64XlPrNl9', base_url='https://paper-api.alpaca.markets')
api.list_positions()
barset = api.get_barset('AAPL', 'day', limit=5)
print(barset)
aapl_bars=barset['AAPL']
print(aapl_bars)
week_open = aapl_bars[0].o
week_close = aapl_bars[-1].c
percent_change = (week_close - week_open) / week_open * 100
print('AAPL moved {}% over the last 5 days'.format(percent_change))
api.submit_order(
symbol='AAPL',
qty=1,
side='buy',
type='market',
time_in_force='gtc'
)
api.list_positions()