@@ -114,7 +114,8 @@ def main():
114
114
early_hour_first_iteration = False
115
115
post_hour_first_iteration = True
116
116
account = trading_client .get_account ()
117
-
117
+ qqq_latest = get_latest_price ('QQQ' )
118
+ spy_latest = get_latest_price ('SPY' )
118
119
buy_heap = []
119
120
for ticker in ndaq_tickers :
120
121
decisions_and_quantities = []
@@ -134,13 +135,15 @@ def main():
134
135
we update instead of insert
135
136
"""
136
137
portfolio_collection .update_one ({"name" : "portfolio_percentage" }, {"$set" : {"portfolio_percentage" : (portfolio_value - 50000 )/ 50000 }})
137
- portfolio_collection .update_one ({"name" : "ndaq_percentage" }, {"$set" : {"portfolio_percentage" : (get_latest_price ('QQQ' )- 503.17 )/ 503.17 }})
138
- portfolio_collection .update_one ({"name" : "spy_percentage" }, {"$set" : {"portfolio_percentage" : (get_latest_price ('SPY' )- 590.50 )/ 590.50 }})
138
+ portfolio_collection .update_one ({"name" : "ndaq_percentage" }, {"$set" : {"portfolio_percentage" : (qqq_latest - 503.17 )/ 503.17 }})
139
+ portfolio_collection .update_one ({"name" : "spy_percentage" }, {"$set" : {"portfolio_percentage" : (spy_latest - 590.50 )/ 590.50 }})
140
+
139
141
historical_data = None
140
142
while historical_data is None :
141
143
try :
142
- period = dynamic_period_selector (ticker )
143
- historical_data = get_data (ticker , period )
144
+
145
+
146
+ historical_data = get_data (ticker )
144
147
except :
145
148
print (f"Error fetching data for { ticker } . Retrying..." )
146
149
@@ -151,6 +154,7 @@ def main():
151
154
current_price = get_latest_price (ticker )
152
155
except :
153
156
print (f"Error fetching price for { ticker } . Retrying..." )
157
+ time .sleep (10 )
154
158
print (f"Current price of { ticker } : { current_price } " )
155
159
156
160
asset_info = asset_collection .find_one ({'symbol' : ticker })
@@ -199,6 +203,7 @@ def main():
199
203
print (f"buy_coeff: { buy_coeff } , quantity: { quantity } , ticker: { ticker } " )
200
204
201
205
order = place_order (trading_client , ticker , OrderSide .BUY , qty = quantity , mongo_url = mongo_url ) # Place order using helper
206
+
202
207
logging .info (f"Executed BUY order for { ticker } : { order } " )
203
208
204
209
trading_client = TradingClient (API_KEY , API_SECRET )
0 commit comments