The stock market from the point of view of the programmer is a set of data that must first be obtained and then analyzed.
The terms of the task: I am interested in the shares of American companies on the daytime timeframe so that every morning my robot sends me an automatic report on yesterday's market dynamics. If there are other markets with other timescales - good. I don't want to pay money for the data yet.
I note separately that I am not in any way affiliated with any of the organizations mentioned in the article. I just look for ways to solve problems, and share my experience.
How to get quotation data free of charge? I am aware of the following possibilities:
- Open REST API - register on the site, get the access key, and you can work
- REST API broker - you open a demo account with the broker, you get the API access key, you can work
- API of the trading terminal - opened a demo account, launched the terminal, upload data
- Exotic options
Open REST API
Alphavantage. Registration is simple - we enter your email, we get the key immediately. There are no checks, you can enter 20 different addresses in a row and get 20 valid keys. However, there is a limit on API cases: not more than 5 per minute, not more than 500 per day. At the same time, a simple trick with the substitution of different keys on the same IP (the limit was exhausted, the key changed) does not always work. Timeframes are available from 1 minute to 1 month here, but it will not be possible to use this for daily updates of a large number of tickers (due to the number of requests limit). But I use this service to get more information on tikers (company description is quite detailed here).
Twelvedata. The last time called their API a few months ago, since then they have had a huge change in the design of the pages, and perhaps together with the design of the functionality. After seeing that on some tikers the candles are given with oaks (several identical candles in the array), refused to use them. Getting the key was as simple as Alphavantage (and you could change the keys in the loop by running out of the limit of hits), and now you need to register.
There's also Finnhub, and I can't remember why I abandoned it in the early stages of the study. Something was wrong.
Broker REST API
Exante. I really like this broker. They have a fairly sane trading terminal, implemented in Java, and running on both Windows and Linux. In the terminal not only shares, but also ETF, options, cryptocurrency, futures, bonds and FOREX. REST API is available after registration of a demo account. Well-understood documentation and support that responds quickly. I say — it reacts, the questions themselves are sometimes solved at once, sometimes in a few days, and sometimes not at all. But I have a free demo account, I use their APIs, and they also help me solve questions! REST API gives access to a large number of exchanges around the world, including OTC. Time frames from 1 minute to 1 day (generating week-long candles from daylight is a small problem). If very asked, can even enable FIX API (it is provided for paid accounts, but support is very responsive, and usually meets, for example, I opened several demo accounts instead of one). I used this API for several months, but then I had problems—the server returned various errors for a few days in a row, support for anything that was supposed to answer, and I left them. There is also another inconvenience - API gives quotes not only for the main trading session, but for some instruments and pre/post-market, i.e. before or after the trading session, and on weekends (apparently, on weekends there is a pre-market at some exchanges). How to filter it by simple — it is not clear, and without filtering there are inadequate market reality of graphics.
Tinkoff API. Documentation is quite human, available sandbox with any balance on any assets, and instant execution of transactions at any price. The tools are the same as the Tinkoff investment. Time frames from 1 minute to month, in the description of tools are given both ISIN and FIGI (which is very convenient). I'm currently using this API for my analytics. Of the unpleasant, the API gives away some long-untraded tikers, and you have to clean them out manually (this is the issue in the githab). Besides, the history of candles on any instrument — not more than 1 year (if you want to build the schedule of MSFT over the last 10 years — it won't work). There are also other roughness, but the team of developers is available for direct dialog (which is pleasant).
Trade Terminal API
Trade terminals I divide into three parts — Metatrader, cTrader, and custom (the same Exante, or the very curious Galt and Taggart from the Bank of Georgia — interesting recommend to study). I don't see the point of dealing with custom terminals (because of the unscalability of the technical solution), so let's just consider Metatrader and cTrader.
Metatrader 5 is the most popular terminal for CFD contracts on Forex, but CFD contracts are for shares, oil, and cryptocurrency. The terminal has its own programming language MQL5 (actually a truncated C++ dialect). MQL5 provides many different functions, including the ability to browse all the symbols in a particular broker and download quotes from them, saving them to a database (or CSV). That is, everything depends on the broker - what kind of tickers he's going to have, whether he gives real-time or late quotes on the demo account, etc. There's also the Metatrader4, there's the MQL4 language, in fact C.
cTrader. I like this terminal more than any other convenient interface, but it is relatively young, it is used not so many brokers, and finding a broker with CFD on shares in cTrader is not an easy task. But the documentation for it is also available, the programming language is C#, the forum technical support answers usually during the day. The truth to most of my questions is the only answer - such a possibility in cTrader has not yet been realized.
Exotic options
For example, Tradingview falls into this category. It's my favorite financial service, and there's definitely everything I need under one roof. But he doesn't have an API at all. If it were possible to get data from this service in a direct and understandable way, I would definitely not consider anything else. But there is no direct way. Exotic options may be (in theory):
- Find on githab parser (they are there) and customize for yourself
- Run Tradingview inside Selenium and pull data
- Revert the mobile app, pull the API schema out of it, and use it
The minus of all these options is obvious - unofficial access can cause problems both technological (change APIs, make another layout) and legal properties.
I would appreciate a discussion of the material. If someone knows the unknown moves in getting interesting data - please read the comment!