The inventor of the quantum trading platformStrategy SquareThere's a lot of interesting tricks that were used in the digital currency exchanges back then.rest
Many of the strategies are based on the protocol's API.rest
In addition, some exchanges have recently emerged, such as the New York Stock Exchange (NYSE) and the New York Stock Exchange (NYSE).rest
Interface failures that cause the policy to be unusable.websocket
Supporting the interface requires making some changes to the policy code, which is usually more troublesome (changing the policy is much more difficult than rewriting it).
How can you not change your strategy, but use it?websocket
What about the interface?
This is a perfect example of the great flexibility of inventors' quantitative trading platforms.
exchange.GetTicker
The function obtained by the hook operation.This is done without changing a line of code, so that the policy can be implemented by the user.websocket
The data drives pushed by the business interface are running.
Use of coding languagesJavaScript
The language.
For example, we want to change a classic old strategy called "ice breaker".
Let's first look at the strategy code and find out that the strategy is driven by the tick market, and it's mainly used byticker
In the dataBuy
、Sell
、Last
These attributes are very important.ticker
Data from the FMZ platform's API function:exchange.GetTicker
We have to get it done.exchange.GetTicker
FunctionHook
This is the only way to do it (i.e. rewrite and replace it with another version).
But we can't rewrite the icebreaker strategy, that will affect the strategy, we want seamless coupling!
So the next main character needs to be on the show.
init
Coordination of functionsWe created a "template library" called:SeamlessConnWSIn the end, it's all about the code.
And then giveSeamlessConnWSThe template has two parameters
Used to control whether or not to turn it onwebsocket
Interface functions, controls specify the specific industry interface to open. In this case, because of the limited size, only theexchange.GetTicker
The interface does the hook operation.GetTicker
The interface is the control parameter for the websocket mode: Hook_GetTicker.
Now that the template is created, you can write specific exchanges to access in the template.websocket
These functional codes can be used to create interfaces, subscribe to certain markets, and then wait for the exchange to push the data. The specific code is no longer discussed, you can see the SeamlessConnWS code ((publicly available) /API documentation.init
Functions and global variables_DictConnectCreater
、_ConnMap
:
The code is:
var _DictConnectCreater = {
"Huobi" : WSConnecter_Huobi,
"Binance" : WSConnecter_Binance,
}
var _ConnMap = {}
function init () {
if (IsUsedWebSocket) {
var connectCreater = null
if (exchanges.length != 1) {
Log("切换为ws接口只针对 exchange 交易所对象(即第一个添加的交易所对象)")
}
var isFound = false
for (var name in _DictConnectCreater) {
if (exchange.GetName() == name) {
connectCreater = _DictConnectCreater[name]
isFound = true
}
}
if (!isFound) {
throw "没有找到实现"
}
if (Hook_GetTicker) {
var symbol = exchange.GetCurrency()
_ConnMap.GetTicker = connectCreater("GetTicker", symbol)
exchange.GetTicker = function () {
return _C(_ConnMap.GetTicker.Read)
}
}
// ...
}
}
So you can see that this template is implemented in only two exchanges.websocket
In addition, the exchange rate of the currency is set at the exchange rate between the two currencies.init
The function is to make the icebreaker strategy reference.SeamlessConnWSAfter the template, when the hard drive is running, it is executed first.init
Functions that can be automatically turned onexchange.GetTicker
Substitute function content for usewebsocket
The code implementation of the interface, thus enabling seamless pairingwebsocket
I'm going to go shopping.
SeamlessConnWS template address
It's very simple!SeamlessConnWSAfter the template is copied to its own policy library, it can only be used to refer to the "Icebreaker" policy, as shown below:
Select, save, and that's it.
The "ice breaker" strategy of creating a real-time robot, the exchange chooses BinanceI'm not sure. StartedSeamlessConnWSControl parameters on the template.
It's running:
To make it easier to see the pushed data, I specify 157 lines of code, plus a code to print logs, which will output the pushed data from the exchange.
The robot's log shows:
This allows for seamless pairing using the websocket market interface and policy without modifying a line of policy code.
This case is for use only.exchange.GetTicker
Explanation of the strategy of a transactional interface function, other transactional interfaces such asexchange.GetDepth
、exchange.GetTrades
、exchange.GetRecords
And it's the same thing!SeamlessConnWSThis is the first time that I've been able to do this.
For specific links in the templatewebsocket
implemented, usedDial
Functions (see API documentation for Dial functions) can be adjusted as needed.read()
Specify the parameters of the function-2
That's just going back.websocket
The latest data in the buffer zone of the data receiver is connected.
Thank you for reading.
congcong009Monk, can I get a little more Python version?
The bride too.Good stuff, should be shared early.
Inventors quantify - small dreamsThank you for the suggestion.