DEV Community

Cover image for How to Build a Stock Trading Bot with Python

How to Build a Stock Trading Bot with Python

Simon Pfeiffer on July 09, 2021

Earlier this week, we explored how code has drastically changed financial markets through the use of autonomous trading algorithms. Surprisingly, b...
Collapse
 
metal3d profile image
Patrice Ferlet • Edited

One note: you don't need to use "pipenv shell" before to use "pipenv install".
Interesting article.

Collapse
 
simoncodephere profile image
Simon Pfeiffer

good to know, thanks!!

Collapse
 
thaneofcawddor profile image
Thane Richard

It looks like this needs to be updated with the latest API (e.g. "api.get_barset" is now "api.get_bars"). Trying to make my way through the errors I am getting. Anyone else have an updated version of this project?

Collapse
 
ahfnyc profile image
AHF

If I invert it to sell, will it sell it 'short' instead? Also, can someone help me understand how to change the moving average? Or where can I get that info on how to set a specific moving average

Thanks in advance.

Collapse
 
simoncodephere profile image
Simon Pfeiffer

Hi there,

Inverting it to sell will sell shares if you already own some. If you do not own any, the order will just fail to complete and you just should receive an error message!

Collapse
 
johntcorrea78 profile image
JohnT Correa

I was trying to create a digsnal distrbution bot that could cover set up all the way to reporting of the signals however it was very tricky to complete. I recently found a software that does provides and saves me heaps to time: signaldp.comtake a look if you are a signal provider on Telegram.

Collapse
 
mike8724 profile image
Michael

I must be missing something because i cant get the bot to deploy. Does anyone have a more detailed explination of how to make it run in command line?

Im completley new to this

Collapse
 
simoncodephere profile image
Simon Pfeiffer

Hi there, in your, terminal navigate to the folder with the python file in it, then run pipenv shell, followed by pipenv install alpaca_trade_api, and then finally run your python file with python INSERT_FILE_NAME

let me know if that helped :)

Collapse
 
mike8724 profile image
Michael

Hi Saji, After a few battles with Codesphere, i had worked out the steps you suggested managing to get the bot to communicate with the trading api. My next battle is to work out why the file structure in codesphere keeps disappearing(although the files are still active)

Thanks for the response

Collapse
 
xxsipro profile image
xxsipro

HELP! When I want to change the symbol to e.g. "BTCUSD" (BitCoin) and I run the Code, there is an error. But only at symbols with "USD" behind. Please help me

Collapse
 
paganicorv profile image
PaganiCorv

Is there a tutorial to all of this?