-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprova.py
More file actions
38 lines (34 loc) · 871 Bytes
/
prova.py
File metadata and controls
38 lines (34 loc) · 871 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
from io import StringIO # python3 (or BytesIO for python2)
from alpaca_trade_api.rest import REST, TimeFrame, TimeFrameUnit
api = REST("PKF2QMR530IM4SKCFZ68", "4BGfZRQbMFZ67U0x5M8bayTUgUcP1qpK6lfdq1Zd")
data = api.get_bars(
[
"AAPL",
"AMZN",
"GOOG",
"MSFT",
"TSLA",
"NFLX",
"META",
"BABA",
"TWTR",
"KO",
"NKE",
"PYPL",
"PEP",
"UBER",
"WMT",
],
TimeFrame(1, TimeFrameUnit.Day),
"2021-01-01",
adjustment="raw",
).df
bucket = "cloudcasa" # already created on S3
csv_buffer = StringIO()
data.to_csv(csv_buffer)
print(csv_buffer.getvalue())
print(type(data))
print(data.head())
# s3_resource = boto3.resource("s3")
# s3_resource.Object(bucket, "df.json").put(Body=csv_buffer.getvalue())
# return {"statusCode": 200, "body": "OK"}