Automating Broker Trades Without an Official Trading API
Summary
The document considers whether a trader can automate orders when a broker offers no trading API. It distinguishes a broker-maintained API, which provides a direct programmatic route for orders, from browser automation that operates the broker’s website as a person would. Selenium is given as an example of a tool for controlling a browser and submitting trades through the interface.
The answers warn that this workaround can be slow and fragile: website changes may break the automation or cause unintended orders, and frequent trading can incur spread and commission costs. The discussion offers anecdotal experience maintaining a script for one broker, but gives no performance tests or implementation details. It recommends trying a broker with an official API and manually monitoring a strategy’s initial trades. Browser automation’s reliability, security, and suitability depend on the broker and the trading frequency; the document does not explain broker terms or safeguards in detail.
Key ideas
- Browser automation can submit orders through a broker’s website when no official API is available.
- A broker’s official API sends orders directly from code and is maintained by the broker.
- Website changes can break browser scripts or lead to unintended trades.
- Browser driven order entry may be too slow for frequent trading.
- Spreads and brokerage fees can reduce returns, especially when trading often.
Tags
Full text
# Is it possible to create an API for trading completely from scratch # Is it possible to create an API for trading completely from scratch I am trying to learn trading and I have searched everywhere but I just don't find an answer to this question. So: Is it possible to create a trading bot and API for it completely from scratch, because my internet broker does not provide any kind of API for trading. Basically, if I wanted to trade right now, I would have to place every purchase and selling transaction manually. I have coding experience but not with APIs. By googling "what is API" I get this answer: > An application programming interface (API) is a way for two or more computer programs or components to communicate with each other. From this definition I would assume that I could just create an API myself. So basically I would write a program that interacts with my internet broker's website and places transactions automatically based on an algorithm. Is it possible to do this? If yes, please provide some learning sources. ## Answer by Jonah Pandarinath (score 7, accepted) https://quant.stackexchange.com/a/78480 It is possible to do what you are suggesting, however execution will likely be unstable. Specifically, you would likely use selenium (a python library) to interact with your chrome browser to place the trade in a similar manner that you would if you manually entered a trade. There are risks associated with this, in which if anything changes on your broker's website, and your quasi-API is not built robustly, it could submit a rogue trade. It is also slow if you are looking to submit trades on a relative high frequency. Further, if you trade too often your profits will likely be diminished due to the cost of trading. Every trade has a bid-ask spread if you submit market orders, and most brokerages have a fee per buy and sell. An API, specifically with a broker is maintained by the broker, and trades are executed directly from code instead of calling selenium to open a new chrome browser and log into your brokerage account to submit the trade. Additionally, I would recommend manually trading the first several trades of a new trading strategy so you can monitor if there are any errors in the code for execution. I would highly suggest finding a broker with an API. Interactive Brokers has relatively low fees and a Python Trading API I believe. In summary, you cannot create an API, however you can write a script to interact with a browser tab and submit trades manually the same way you currently are doing. Writing this script has several risks including speed, maintenance of the script, and security. ## Answer by Pierre-André (score 0) https://quant.stackexchange.com/a/80419 I've done it in the past (Coded through BNCD.ca from python). from 2016 to 2019. It was difficult to maintain since Borkers' website constantly changes. A change in an object in the page can lead to unstable exe. I want to look at it again, but maybe through interactive broker. good luck ## Answer by Satoshi Ido (score 0) https://quant.stackexchange.com/a/81907 You can also use Alpaca if you use either Python, Go, Node, or C# (https://alpaca.markets/) I often write my own python scripts to run my strategies. It goes well with TradingView as well.
Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.