I am starting a new project. My project idea is straight forward. I want to buy and sell stocks using Arduino. I want to see what can microcontrollers really do and what are their boundaries.
In my last project, I built a bluetooth controlled drone using an android app that built. This time I don't want to control any motors nor turn off the TV using Arduino; It's really simple and boring. I want to see if this Arduino is capable of doing more complicated stuff like trading stocks.
I have searched many websites and looked for many books for guidance, but failed to find any hints on how to start this project.
If this is possible to do, what do I need to learn and what to search for?
So far I have learnt how to use the ESP8226 wifi chip. I had fun connecting to my wifi and controlling relays using my phone. But what if I can control websites using this chip? Is this possible.
If this is possible to do, what do I need to learn and what to search for?
First thing you will need is an API description how to communicate with the backend of your broker.
If your broker doesn't offer an open API - you have to search for another broker.
noiasca:
First thing you will need is an API description how to communicate with the backend of your broker.
If your broker doesn't offer an open API - you have to search for another broker.
I have an account with TD Ameritrade. They have an open API. How to use those API's and make them communicate with Arduino.
Understand how the API works, and what will be needed for it. Most likely they need HTTPS requests (dear god, I hope they do!), so that rules out some low end microcontrollers, for example.
Figure out a "test" api request that won't actually result in any shares being bought or sold, but will verify that you're making the request correctly. Ideally, you would be able to make this request from your computer and see that you get the expected response (there's a chrome addon called Advanced REST Client that's really handy for making requests to test APIs). Make sure this works, and look at all the data being sent to and received from their server. Then use it to make a request that will actually make a trade - make sure you understand how it works with a real computer making the request.
Using an appropriate arduino (determined in 1.), first verify that you can make a simple request over https - not to their API, just in general. How you do this will depend on what board you end up using, and how it's connecting to the internet, but there should be examples of making simple requests all over the place.
Make the arduino do your test api request and just print out the response it gets to serial - make sure you can get the same result as you got on the computer.
Before you make any request that could actually buy or sell stock, have the sketch just print out the requests it would be making, instead of just making them, so you can verify that it's going to do what you expect.
Once that's working, you can... start making your arduino buy and sell stocks for you!
Be mighty careful that you've got measures in place to limit the amount of financial damage that a bug could do to you. It wouldn't do to end up in the poor house on account of a bug in your code....
Overall, though, this sounds fun, if sort of silly...
DrAzzy:
Be mighty careful that you've got measures in place to limit the amount of financial damage that a bug could do to you. It wouldn't do to end up in the poor house on account of a bug in your code....
Overall, though, this sounds fun, if sort of silly...
Thanks for the amazing reply. I will work on what you wrote and hopefully get some good results.
To be honest, having an arduino to handle streaming quotes, apply your strategies to stocks, generate and tracking orders, and handle errors, would be a little difficult. Plus Arduino doesn't have much built-in storage, so reviewing logs could be difficult if anything goes wrong and crashes.
I'm using TD Ameritrade as well (mostly trading futures and options). I built a simple tool showing quotes only of some futures, using TD Ameritrade streaming API, but it does not have any trading logic.
noiasca:
First thing you will need is an API description how to communicate with the backend of your broker.
If your broker doesn't offer an open API - you have to search for another broker.
Where can I find a good broker? I've started to trade some months ago and I know that a very important detail in trading is to find a good broker. I'm looking also for a good platform for trading because now in the net there are a lot of scammers that are waiting for you to do some transactions and to still the money. I'm not trading the bitcoin or sth else, no. I decided to start trading the oil. I read from The buoyant oil traders that it is very profitable today if to be a good analytic and to know the time when to take a right decision.
I did a quick Google search for: stock trading API. The first result was an ad for a website called Alpaca.markets. Someone has written a C++ client for their API and provided a bunch of examples. You could sign up for a free account and see if you can get the C++ library and examples to run on your Arduino.
Here are the examples for the third-party C++ client library for Alpaca.markets.
WARNING: There will be a lot of editing to make the library work in the Arduino environment. And then you might find there is not enough memory on the Arduino to get the library to work.