forked from arshyasharifian/replicateETF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
31 lines (28 loc) · 1.15 KB
/
test.py
File metadata and controls
31 lines (28 loc) · 1.15 KB
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
from replicateETF.scrapeETF import ETFHandler,AlpacaClient
from alpaca_trade_api.rest import REST
# it is optional to add api key and secret here or export the keys
myObj = ETFHandler()
client = AlpacaClient("VOO")
etfAssetDict = myObj.getETFTable(symbol)
# identify the mimimum amount of purchasing power to build ETF
minimumDollars = myObj.getMinimumDollars(symbol)
# determine whether available cash enough to build ETF
if client.getAvailableCash() < minimumDollars:
print ("Insufficient fund to build ETF")
else:
investmentAmount = -1
while investmentAmount < minimumDollars:
investmentAmount = float(input(f"Based on the ETF, please enter a value greater than {minimumDollars} to invest: "))
#build Alpaca client
api = REST()
for key in etfAssetDict.keys():
equity = etfAssetDict[key]
percent = equity['percent']/100
try:
orderResponse=api.submit_order(symbol=key,
notional=investmentAmount*percent,
side="buy",
type="market")
print(orderResponse)
except Exception as e:
print(e)