In a high-frequency trading strategy of commodity futures, the receiving speed of the Tick market quotes has a decisive influence on the profit result of the strategy. However, most of the trading frameworks on the market use the callback mode mechanism. It would be nice not to miss onBar/onTick and Tick, so why? Because in the onBar/onTick function, you have to deal with the entire code logic, which is a waste of time; whether you want it or not, your strategy logic must be interrupted, and you must use a state machine mode, such as:
var state = STATE_IDLE;
function onTick() {
if (state == STATE_IDLE) {
// do something...
} else if (state == ....) {
// do something
}
}
FFMZ Quant does not adopt the backward callback mechanism, but adopts the “main” function entry mechanism that does not interrupt the strategy logic, so that users can control the strategy flow more naturally; use C++ and Golang as the stable strategy underlayer, and use Javascript/Python on the upper layer to deal with logic problems. Do not think the scripting language is slow, unless you use it for NNS training; even if you use NNS training, after adding Jit hot compilation, it will be enough for any occasion; Chrome defeating IE instantly is an example. Combined with the event triggering mechanism, the strategy can also process TAQ at the fastest speed in the first time. The entry-level strategy will not be written here, as far as the synthesis of high-frequency ticks in futures is concerned, For example, when we access a futures company, we can only receive the TAQ of this futures company. The speed and quality of the TAQ we get is related to our own network, and also related to the load of the futures company’s front-end machine. So, how can we obtain more accurate futures tick data faster?
Under the strategy model, you can easily operate the accounts of N different futures companies, merge their TAQ, and place orders at the fastest speed. Under normal circumstances, we can get two ticks per second from the futures companies, but by the technology of merging TAQ, taking MA801 as an example, we can get a maximum of 6 non-repetitive ticks per second.
Let’s go straight to the code (the code can only be operated in the bot, not in the backtest), and the use of IO function can refer to: https://www.fmz.cn/api#io函数
When a bot adds a platform, N futures companies can be added to process the concurrent merging of TAQ; here we temporarily add two, and demonstrate this:
Code as follows:
function main() {
Log("Prepare to access the platform and subscribe to TAQ")
// Step 1: all futures front-end processors are subscribing for symbols
_.each(exchanges, function(e) {
// wait to access the platform, and yes, the strategy runs continuously for 365 days, and it can run even after the market is closed, and it is not the logic of event callback
good mistake
while (!e.IO("status")) Sleep(1000);
// Use the _C retry function to eliminate network errors, and subscribe to TAQ just access to the platform; there may be an error that CTP is not ready
_C(e.SetContractType, "MA801")
// Switch the TAQ receiving mode to immediate return mode instead of event trigger mode, please refer to the API documentation
e.IO("mode", 0)
})
Log("Start to merge data...")
// Step 2: here comes the important part
var preVolume = 0
while (true) {
var ts = new Date().getTime()
// If any platform has tick event, return
var e = exchange.IO("wait_any")
// Reset Volume at a proper time
if (e.Nano/1000000 - ts > 60000) {
preVolume = 0
}
if (e.Event == 'tick' && e.Ticker.Volume >= preVolume) {
Log(ret, e.Ticker.Last, e.Ticker.Volume)
preVolume = e.Ticker.Volume
}
}
}
Result as follows:
It can be seen that at 21:24:44, the data of the first futures company arrives before the second one, and the result can be seen by adding two futures companies. If more than 5 futures companies are added to merge together Then you basically have no chance to miss Tick. If you use it to develop high-frequency trading strategies, you have solved a very important and decisive step, that is, the speed, stability and reliability of obtaining Tick.
FMZ Quant (former BotVS) is a platform specially created for developers who have critical requirements on strategy stability and speed. The underlayer protocol technology is independently developed, which can be operated under Linux/Windows/Mac/ARM single chip microcomputers or even mobile phones, and its ordering speed is extremely fast. The reaction to TAQ is fast, and it is the best choice for developing high-frequency strategies.