INNER CODE UNIT · Python

stock_to_buy

tejaslinge/Alpaca-ROC-Trading-Bot · main.py:257

                        elif stock_to_buy == -1:
                            print('All Ask < LTP')
                            time.sleep(2)
                            continue
                        
                        # checks if stock_to_buy exists in positions
                        # doesn't buy if LTP for stock_to_buy > avg_entry_price
                        else:
                            num_stocks = len(api.list_positions())
                            curr_stocks = []

                            if num_stocks != 0:
                                for i in range(num_stocks):
                                    curr_stocks.append(api.list_positions()[i])
                                    
                                if stock_to_buy in curr_stocks:
                                    if api.get_latest_trade(stock_to_buy).price > float(api.get_position(stock_to_buy).avg_entry_price):
                                        print('LTP for {} > Average Entry Price'.format(stock_to_buy))

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…