-
Go to: https://alpaca.markets to create an account
-
Go into your terminal and type: "pip install alpaca-trade-api"
-
Copy and paste the code into your text editor, notepad, etc.
-
Log into you account on Alpaca, and click on the View button next to the text that says: "Your API keys"
-
Take the key and paste it into the quotes in the code that says "my_key", do the same for your secret key with "my_sec_key".
-
Change the "symbol" variable in the code from "AAPL" to whatever stock you would like to trade with.
-
Change the "qty" variable in the code to how much you would like to buy and sell of your stock.
-
Create a .txt file named "updates" in the same directory of file you saved your code in.
-
In the "position" variable change "AAPL" to your stock name.
-
In the line that says
if percent_change >= 0.5 and int(position.qty) == 501:
change0.5
to the percent you would like to buy and sell at, and501
to your qty + 1. In the line that sayselif percent_change <= -0.5 and int(position.qty) == 1:
change-0.5
to what you changed0.5
above but negative. -
In this snippet of code:
update1.write("\n" + time1 + f": Sherman bought 500 shares of " + symbol + " for {minute_open} each.")
update1.close()
print(f"Sherman bought 500 shares of " + symbol + " for {minute_open} each.")
Change 500
to the qty you are buying and selling, you need to do this twice since there is an if statement with this, and an elif statement as well.
- And you should be all set just run the script.
Basically the same thing as above just change the stockname variables to your stocks, the stockqty to the qty of your stocks, and the percent to the eprcent you want.