📜 ⬆️ ⬇️

Speed: terminal acceleration for stock trading with undocumented features

The main means of working in the stock market for most traders is a special trading terminal - even algorithmic traders who run special trading robots use it to control the account balance. At the junction of HFT and “ordinary” trading, problems sometimes arise - often the terminal cannot “digest” information from tens of thousands and millions of applications and transactions of trading software and starts to work slower.

In conditions when each millisecond can cost real and very big money, this is unacceptable. Today we will talk about a small life hack, which allows you to dramatically increase the performance of the SmartX trading terminal (our development) in five minutes.

Several million applications: what to do?


When developing your project for the SmartX trading terminal (you can read more about the project in a separate topic ), special attention was paid to performance. In particular, it took a lot of effort to make fast-working graphics (the terminal was developed on the basis of the M4 platform on COM +) —for this, we had to connect third-party developments and switch to .NET.
')
Attention was also paid to the creation of a special DataManager module, which is responsible for the interaction of the terminal with the brokerage trading system . In the previous version of the terminal, it was single-threaded, which created performance problems in the case of large volumes of “pumped” data. The new module has become multi-threaded and asynchronous, which allows the terminal to display 2 million applications. In addition, according to test data, the terminal is faster and sends applications - during a comparative test with another popular terminal on the market, SmartX sent 100 applications in 0.0099 seconds, and its rival - in 0.018 seconds (this is before callback registration of applications) .

However, as mentioned above, sometimes these opportunities are not enough for demanding traders - some robots can quite easily make over 2 million requests per day. There are not so many such users of the program, but they are there, and they needed to be given some opportunities to increase their productivity.

image

As a result, it was decided to give them the ability to disable certain parameters affecting performance using a special configuration file — technically advanced HFT merchants are familiar with this method, while other users did not need to make additional menus in the settings that could confuse them .

Performance Improvement and Configuration File


In the folder that is created after installing the trading terminal, there is a file (smartx_exe.config) - it contains a small XML-code with options. Changing them allows you to configure the terminal more flexibly and get rid of possible performance problems.

The content of the file looks like:

<setting name="DoNotMergeOrdersWithQuotes" serializeAs="String"> <value>True</value> </setting> <setting name="DoNotCacheCanceledOrders" serializeAs="String"> <value>True</value> </setting> <setting name="DoNotRequestOrdersHistory" serializeAs="String"> <value>True</value> </setting> 

Changing the value of three fields from True to False helps to significantly improve the performance of the program. Let us dwell on each of the three points.

DoNotMergeOrdersWithQuotes

The flow containing the order data and the flow of information about the change of quotations in the terminal “merge” - in the “application” field in the program, the user sees not only the information directly about it, but also some information about the bidding - purchase and sale prices (bid, ask, ) and some other data (for example, the price of the last transaction). This is necessary, among other things, for the operation of one of the functions of embedded risk management - “trailing stop order”.

What is a trailing stop?
Traders limit losses and take profits with STOP orders. For example, when buying stocks or futures, a trader can set a stop at a certain price mark, upon reaching which his position is liquidated - in this case stocks or futures will be sold at the current market price. Such orders have one drawback - they periodically need to be removed and re-exposed with the edited conditions. If the price "went" upwards, then leaving the original order is unprofitable, since if it falls, the potential profit will be lost.

Using the function of a moving stop order, you can automatically “pull up” the value of the stop following the changed price of a financial instrument. In the case of a long position (presence of purchased shares or futures), the moving stop for the sale of shares (sell operation) will increase with price and will not change with its decrease. In the case of a short position (sold by a broker to “borrow” shares with the expectation of a drop in their value for further redemption), a sliding stop at its closure (closeshort) will, on the contrary, decrease with a fall in price and will not change if it grows.

In addition, the merging of order flows and bidding information is necessary to calculate information about the collateral that should be withheld from the client to guarantee his transaction obligations — the state of the account depends on the number of bids made (the greater the number, the less available funds, since future transactions are needed than provide something).

If this value is set to False, then orders and quotes will not merge, which will improve performance. This method is well suited for those traders who put up many bids and work with instruments that often change market parameters. Refusal to process them saves system resources.

DoNotCacheCanceledOrders

Disabling this feature prevents the program from storing canceled requests in the memory. In general, they do not carry much value for a trading strategy, but especially active traders may have a lot of them (up to millions). Refusal to store this information allows you to save system memory, as well as speed up the drawing of the table of requests and schedules (in case current requests are displayed on it by lines).

DoNotRequestOrdersHistory

Rejection of this item brings the greatest performance gain in the event that the connection to trading occurs in the middle of the trading session. In addition, this function is closely related to the previous item.

When a trader has a lot of canceled orders (which the trading robot put up and removed, for example), then when connected to the trading terminal, he requests information from the broker's database about all the requests of a particular user. In the event that there are millions of these applications for their “pumping over” it takes time and memory to store them. Accordingly, the rejection of this function allows you to speed up the operation of the terminal.

In the terminal of the previous generation there were no such opportunities. As a result, in the presence of several tens of thousands of applications, he began to “slow down” greatly. The new product is faster by itself and can cope with about 2 million applications without any special problems, and when you turn off the above settings, its performance grows even more. At the same time, it takes quite a bit of time to make changes to the configuration file.

These items are not available through the standard terminal settings menu, so the “undocumented features” can be used by those who really need it, and most users can use the program without complicating its interface.

PS If you find a typo or mistake, write us a personal message and we will fix everything promptly.

Posts and related links:

Source: https://habr.com/ru/post/234741/


All Articles