Handshake teaches you how to give an old-fashioned strategy a seamless websocket market interface

Author: The Little Dream, Created: 2019-09-26 15:47:53, Updated: 2023-10-18 19:54:36

img

Handshake teaches you how to give an old-fashioned strategy a seamless websocket market interface

The inventor of the quantum trading platformStrategy SquareThere's a lot of interesting tricks that were used in the digital currency exchanges back then.restMany of the strategies are based on the protocol's API.restIn addition, some exchanges have recently emerged, such as the New York Stock Exchange (NYSE) and the New York Stock Exchange (NYSE).restInterface failures that cause the policy to be unusable.websocketSupporting 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?websocketWhat about the interface? This is a perfect example of the great flexibility of inventors' quantitative trading platforms.

  • 1, use the "template library" policy.
  • Two, yes.exchange.GetTickerThe 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.websocketThe data drives pushed by the business interface are running. Use of coding languagesJavaScriptThe language.

Analytical strategies

For example, we want to change a classic old strategy called "ice breaker".

Policy address

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 bytickerIn the dataBuySellLastThese attributes are very important.tickerData from the FMZ platform's API function:exchange.GetTickerWe have to get it done.exchange.GetTickerFunctionHookThis 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.

Template library features andinitCoordination of functions

We created a "template library" called:SeamlessConnWSIn the end, it's all about the code.

img

And then giveSeamlessConnWSThe template has two parameters

  • IsUsedWebSocket
  • Hook_GetTicker@IsUsedWebSocket

img

Used to control whether or not to turn it onwebsocketInterface functions, controls specify the specific industry interface to open. In this case, because of the limited size, only theexchange.GetTickerThe interface does the hook operation.GetTickerThe 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.websocketThese 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.initFunctions 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.websocketIn addition, the exchange rate of the currency is set at the exchange rate between the two currencies.initThe function is to make the icebreaker strategy reference.SeamlessConnWSAfter the template, when the hard drive is running, it is executed first.initFunctions that can be automatically turned onexchange.GetTickerSubstitute function content for usewebsocketThe code implementation of the interface, thus enabling seamless pairingwebsocketI'm going to go shopping.

SeamlessConnWS template address

How to use it

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:

img

Select, save, and that's it.

The "ice breaker" strategy of creating a real-time robot, the exchange chooses BinanceimgI'm not sure. StartedSeamlessConnWSControl parameters on the template.img

It's running:img

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.img

The robot's log shows:img

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.GetTickerExplanation of the strategy of a transactional interface function, other transactional interfaces such asexchange.GetDepthexchange.GetTradesexchange.GetRecordsAnd it's the same thing!SeamlessConnWSThis is the first time that I've been able to do this.

For specific links in the templatewebsocketimplemented, usedDialFunctions (see API documentation for Dial functions) can be adjusted as needed.read()Specify the parameters of the function-2That's just going back.websocketThe latest data in the buffer zone of the data receiver is connected.

Thank you for reading.


Related

More

congcong009Monk, can I get a little more Python version?

The bride too.Good stuff, should be shared early.

The Little DreamThank you for the suggestion.