INNER CODE UNIT · Python
algo
tejaslinge/Alpaca-ROC-Trading-Bot · main.py:139
def algo(tickers):
# Calculates ROC
# Checks for stock with highest ROC and if ask_price > price
# Returns ticker to buy
if os.path.isfile('FirstTrade.csv'):
timeframe = 1
else:
timeframe = 30
stock = stock_to_buy(tickers, timeframe)
return stock
def buy(stock_to_buy: str):
cashBalance = api.get_account().cash
price_stock = api.get_latest_trade(str(stock_to_buy)).price
targetPositionSize = ((float(cashBalance)) / (price_stock)) # Calculates required position size