import alpaca_trade_api as tradeapi
# API credentials
API_KEY = 'key entered'
API_SECRET = 'secret key entered '
APCA_API_BASE_URL = 'https://paper-api.alpaca.markets'
# Alpaca API client
api = tradeapi.REST(API_KEY, API_SECRET, APCA_API_BASE_URL, api_version='v2')
# Alpaca streaming client
conn = tradeapi.stream.Stream(
key_id=API_KEY,
secret_key=API_SECRET,
base_url=APCA_API_BASE_URL,
data_feed='iex'
)
# stock
stock_symbol = 'AAPL'
# trade amount
trade_amount = 1000
#current market price
last_trade = api.get_last_trade(stock_symbol)
stock_price = last_trade.price
```
```
type here
```
```
# number of shares to buy
shares_to_buy = int(trade_amount / stock_price)
# order for the stock
api.submit_order(
symbol=stock_symbol,
qty=shares_to_buy,
side='buy',
type='market',
time_in_force='gtc'
)
# order fill
time.sleep(10)
#current market price of the stock
last_trade = api.get_last_trade(stock_symbol)
stock_price = last_trade.price
# sell and stop prices based on the purchase price
sell_price = stock_price * 1.1
stop_price = stock_price
# monitor
while True:
last_trade = api.get_last_trade(stock_symbol)
stock_price = last_trade.price
if stock_price >= sell_price:
api.submit_order(
symbol=stock_symbol,
qty=shares_to_buy,
side='sell',
type='market',
time_in_force='gtc'
)
break
if stock_price <= stop_price:
api.submit_order(
symbol=stock_symbol,
qty=shares_to_buy,
side='sell',
type='market',
time_in_force='gtc'
)
break
time.sleep(60)
I tried entering my api key and secret key and still its giving error checked all the files are installed multiple times and tried deleting and re installing all the files required Error: AttributeError Traceback (most recent call last) /var/folders/9g/ck01_wh50fq_gbs2yfwf5k980000gn/T/ipykernel_52978/1806072820.py in 24 25 # Get the current market price of the stock ---> 26 last_trade = api.get_last_trade(stock_symbol) 27 stock_price = last_trade.price 28
AttributeError: 'REST' object has no attribute 'get_last_trade'
Try "get_latest_trade" instead of get_last_trade.