Expanded API to enable TradingView alarm signal trading using inventor's quantified trading platform (recommended)

Author: The Little Dream, Created: 2020-04-29 17:08:27, Updated: 2023-10-08 19:56:04

img

Expanded API to enable TradingView alarm signal trading using inventor's quantified trading platform

Video link to station B

The Inventor Quantitative Trading Platform Extension API has recently been upgraded to support direct access mode, which makes it easy to send TradingView alerts to the Inventor Quantitative Trading Platform robot to automate trading.

Inventors of the Quantitative Trading Platform Extension API

Links to relevant parts of the Inventor API documentation

The main role of the API extension is to provide an interface to the various functions of the inventor's quantitative trading platform for programmatic operations, such as simultaneous batch start of the robot, timing of the robot's start, stop, reading of the robot's information details, etc. We use the Inventor's quantitative trading platform extension to implement the API TradingView alarm signals trading.CommandRobot(RobotId, Cmd)The interface can send interactive instructions to the specified robot ID, which the robot receives and then performs the corresponding operation (e.g. placing an order to buy, sell, etc.).

To use the API extension, you first need to create your own inventor account.API KEY: img API KEYThe secret key isaccess keyandsecret keyIt's not just a question of time.API KEYThe inventor of the programmatic operation of the quantitative trading platform key, so it must be properly stored and never leaked.API KEYYou can specify permissions, like the one above, just for this.API KEYGiving accessCommandRobot(RobotId, Cmd)Permissions for the interface, for security reasons in this example, please only give the extension to FMZAPI KEYGivingCommandRobot(RobotId, Cmd)Access to the interface.

Direct access mode of the extended API

The direct access mode means thatAPI KEYA query written directly into a URL, such as the URL for an Inventor Quantified Trading Platform Extension API, can be written as:

https://www.fmz.com/api/v1?access_key=xxx&secret_key=yyyy&method=CommandRobot&args=[186515,"ok12345"]

In this case,https://www.fmz.com/api/v1It's the address of the interface.?And then there wasQuery, the parametersaccess_keyThe secret key example is represented by xxx (the access_key of your FMZ account when using it), the parametersecret_keyThe secret key is indicated by the symbol YYYYY (if used, specify your account secret_key), the parametermethodThis is the name of the extension API that you want to access.argsTo be calledmethodThe parameters of the interface.

We use TradingView as a signal source to send trading orders to the inventor's quantified trading platform robot, which in fact only usesCommandRobotThis interface.

TradingView

First you have to have an account at the TradingView Pro level, the Basic level is not able to use the WebHood function in the alarm.

img

Adding an indicator to a graph can also be another scripting algorithm. Here, for ease of demonstration, we use the most commonly usedMACDIndicator, and then set the K-line cycle to 1 minute (to make the signal trigger faster, easy to demonstrate).

img

Right-click on the chart and select "Add alerts" from the pop-up menu.

img

Set in the "Alarm" pop-up windowWebHookAt this point, it is possible to set up without any haste, and we start with the inventor's robotic monitoring signal on the side of the trading platform.

Robots with surveillance signals

The source code of the strategy:

// 全局变量
var BUY = "buy"     // 注意:现货用的命令
var SELL = "sell"   //      现货用的命令
var LONG = "long"   // 期货用的命令
var SHORT = "short" // 期货用的命令
var COVER_LONG = "cover_long"   // 期货用的命令
var COVER_SHORT = "cover_short" // 期货用的命令

function main() {
    // 清空日志,如不需要,可以删除
    LogReset(1)

    // 设置精度
    exchange.SetPrecision(QuotePrecision, BasePrecision)

    // 识别期货还是现货
    var eType = 0
    var eName = exchange.GetName()
    var patt = /Futures_/
    if (patt.test(eName)) {
        Log("添加的交易所为期货交易所:", eName, "#FF0000")
        eType = 1
        if (Ct == "") {
            throw "Ct 合约设置为空"
        } else {
            Log(exchange.SetContractType(Ct), "设置合约:", Ct, "#FF0000")
        }
    } else {
        Log("添加的交易所为现货交易所:", eName, "#32CD32")
    }
    
    var lastMsg = ""
    var acc = _C(exchange.GetAccount)
    while(true) {
        var cmd = GetCommand()
        if (cmd) {
            // 检测交互命令
            lastMsg = "命令:" + cmd + "时间:" + _D()
            var arr = cmd.split(":")
            if (arr.length != 2) {
                Log("cmd信息有误:", cmd, "#FF0000")
                continue
            }

            var action = arr[0]
            var amount = parseFloat(arr[1])

            if (eType == 0) {
                if (action == BUY) {               
                    var buyInfo = IsMarketOrder ? exchange.Buy(-1, amount) : $.Buy(amount)
                    Log("buyInfo:", buyInfo)
                } else if (action == SELL) {        
                    var sellInfo = IsMarketOrder ? exchange.Sell(-1, amount) : $.Sell(amount)
                    Log("sellInfo:", sellInfo)
                } else {
                    Log("现货交易所不支持!", "#FF0000")
                }
            } else if (eType == 1) {
                var tradeInfo = null
                var ticker = _C(exchange.GetTicker)
                if (action == LONG) {
                    exchange.SetDirection("buy")
                    tradeInfo = IsMarketOrder ? exchange.Buy(-1, amount) : exchange.Buy(ticker.Sell, amount)
                } else if (action == SHORT) {        
                    exchange.SetDirection("sell")
                    tradeInfo = IsMarketOrder ? exchange.Sell(-1, amount) : exchange.Sell(ticker.Buy, amount)
                } else if (action == COVER_LONG) {        
                    exchange.SetDirection("closebuy")
                    tradeInfo = IsMarketOrder ? exchange.Sell(-1, amount) : exchange.Sell(ticker.Buy, amount)
                } else if (action == COVER_SHORT) {        
                    exchange.SetDirection("closesell")
                    tradeInfo = IsMarketOrder ? exchange.Buy(-1, amount) : exchange.Buy(ticker.Sell, amount)
                } else {
                    Log("期货交易所不支持!", "#FF0000")
                }
                if (tradeInfo) {
                    Log("tradeInfo:", tradeInfo)
                }
            } else {
                throw "eType error, eType:" + eType
            }
            acc = _C(exchange.GetAccount)
        }
        var tbl = {
            type : "table", 
            title : "状态信息", 
            cols : ["数据"], 
            rows : []
        }
        // tbl.rows.push([JSON.stringify(acc)])   // 测试时使用
        LogStatus(_D(), eName, "上次接收到的命令:", lastMsg, "\n", "`" + JSON.stringify(tbl) + "`")
        Sleep(1000)
    }
}

Policy source code

The strategy code is very simple, detection.GetCommandThe return value of a function is the value that is returned when an interactive message is sent to a policy program.GetCommandThe function returns the message, and then the policy program makes the corresponding trading action based on the message content. The policy has an interaction button on it, which can test interaction features, such as running this policy and configuring the robot to the inventor of a simulated exchange for a quantized trading platform.WexApp

img

Click on the interaction button to test the functionality of the robot receiving the purchase order.

img

You can see that the command string received by the robot is:buy:0.01

When we simply trigger a TradingView alert, WebHook requests a URL to access the inventor's quantified trading platform extension API.CommandRobotWhen the interface is used, the parameters carried are:buy:0.01It's not that simple.

Set up the WebHook for TradingView

Back in TradingView, we fill in the URL of WebHook.access_keysecret_keyParameters fill in their ownAPI KEYmethodThe only thing we're going to do is visit.CommandRobotThis extended API interface is used to create a user-friendly interface.argsThe parameter is[机器人ID,命令字符串]In the form of a bot ID, we can access it directly from the bot page, as shown below:imgThis time, when the signal is triggered, we buy 0.02 coins and the command string is:"buy:0.02"◦ This is done with the WebHook URL. ◦ This only supports writing the signal in the URL.https://www.fmz.com/api#直接验证

https://www.fmz.com/api/v1?access_key=e3809e173e23004821a9bfb6a468e308&secret_key=45a811e0009d91ad21154e79d4074bc6&method=CommandRobot&args=[191755,"buy:0.02"]

In TradingView, set the following:

img

Wait for the signal to trigger... Wait for the signal to trigger... 等待信号触发.

img

The robot received a signal:

img

This allows you to use the rich charting functionality in TradingView, indicator algorithms that work with the inventor's strategy robot to quantify the trading platform, and achieve the automated trading you want, which is less difficult than porting strategies from TradingView to JavaScript or Python.

The "Monitoring Signal Robot" strategy code is for learning and research purposes only, and for real-world use, it requires self-optimized adjustment, supports futures, and is recommended to be set to the market price order mode. See the policy code parameters for more details. If you have any questions, please leave a comment.


Related

More

pw1013If you could please connect me to the deepcoin exchange, thank you very much.

mingxi1005When will the inventors be able to pair the coins to win the futures contracts?

mingxi1005When will the inventors be able to pair the coins to win the futures contracts?

smilesgYou're right, my contract strategy is that sometimes I'm going to get a raise in the middle of a trade, so when I finally get to the bottom of the trade, I'm going to use cover_long to flatten out all the positions (because I don't know how many times the middle will add up), what's the 1 in "cover_long:1", and I'm going to kneel down and ask for code.

tyk950115My TV policy message is this: order {{strategy.order.action}}@{{strategy.order.contracts}} ticker; new policy position {{strategy.position_size}} If I want to do a contract, do I have to add four alerts? Can webhook reference the fields in the policy? Or do I have to write it off? How do the four ways in webhook long, cover_long\short, cover_short match the messages in the alert?

Quantitative measurements of small insectsI want to send the text of the news from tv, but unfortunately I can't carry it, only the URL can carry the parameters, not the information for tradingview.

NingQuestion: [1234567, "buy:50"] This is a $50 BTC buy, and it's a $50 USD buy. But when I sell it, [1234567, "sell:50"] it shows the error: Sell ((-1, 50): insufficient balance. So how do I set it up to sell all the BTC I bought the first time?

wqyThis is powerful!

lanbnHello teacher, I'm following your steps step by step, the server selected is the server that the inventor brought with him, but the TV has already sent a signal, but the robot on the inventor's side still does not execute the signal command, is it because of the server?

tnmmhmIt's great, take it slow.

Reverse the Q./upload/asset/19a5ed382b58652c4dd19.png /upload/asset/19b0ea9ffa5100a3594f3.png /upload/asset/19a806e32e9b589696fa0.png /upload/asset/19a5005173219393cf2d9.png Why is the contract code that I added in step by step still showing an error, is that the wrong step?

wuxianFor example, if there are multiple heads in the tv policy, will this be based on the tips in the tv policy?

PY008What does the futures contract code say?

melo23Where is the video tutorial for the futures?

sug210Is the Binance Futures not supported?

yuanlijieHow did the contract work? I am a programmer and I don't know English except for the spelling of the letters.

mikelslI'm going to go to the bathroom and I'm going to go to the bathroom and I'm going to go to the bathroom and I'm going to go to the bathroom.

skyfffireIt's a great step, but it's also a simple one.

homilyThat's great.

pw1013I asked the copyright owner about you.

hexiao49I have a problem in my community, can you help me see it?

The Little DreamThe problem is that without an API, you can't do anything.

hexiao49Deep doesn't even have an API?

The Little DreamThis depends on how many users want it.

The Little DreamThis stop loss requires a specific change in strategy, not one or two sentences. FMZ directly supports the PINE language, which makes it easier to run PINE scripts directly.

mingxi1005Teacher: I want to add the function of shutdown after opening the tab on your robot, where should I add it?

The Little DreamYes, I have also asked their customer service to root out the API interface bugs that are not under contract.

mingxi1005There's no way.

The Little DreamThis is a live API, boss! #_#! FMZ has already supported this feature.

mingxi1005This website has an API, and you need a ladder to open /upload/asset/2986424014eb005f8cda2.png

mingxi1005https://www.coinw.fit/front/API This website has an API, you need a ladder to open it

The Little DreamThis address cannot be opened. No API documentation is contracted.

mingxi1005API entry link: https://coinw.pw/API

The Little DreamThis is the live API for coinw, which is already supported by FMZ, and they don't have a contract interface. You'd better check with Coinw. I asked their customer service and they said no contract API.

mingxi1005Can we bind ourselves using the common protocol? Just ask to fill in the IP address, which IP address to fill in? API entry link: https://coinw.pw/API

The Little DreamI'm embarrassed, but are you sure that the coin-winning contract has an API?

mingxi1005Yes, little dream teacher, if you access, there will be a lot of quantitative access because the coin wins 80% commission.

The Little DreamHello, do you need a contract to access this exchange? haven't evaluated this exchange yet.

Two or two old waves.I've been having the same problem.

lanbnBrother, did you succeed in the TV strategy of directly linking FMZ?

The Little DreamThis can be specifically designed, for example, you design the request cover_long:1, change it to cover_long:all, so that in this listening policy of FMZ you change the time of receiving the interaction cover_long, judging if it is all, then all is flat. To achieve this you have to modify this policy. What's up? // global variable var BUY = "buy" // note: command for spot var SELL = "sell" // command to use on the spot var LONG = "long" // The command to use the futures var SHORT = "short" // command for the futures var COVER_LONG = "cover_long" // the command to use the futures var COVER_SHORT = "cover_short" // The command used for the futures I'm not going to lie. I'm not sure. I mean... I'm not sure. } else if (eType == 1) { var tradeInfo is null This is a list of all the different ways Var ticker is credited in the database. if (action == LONG) { exchange.SetDirection (("buy") TradeInfo = IsMarketOrder? exchange.Buy ((-1, amount)): exchange.Buy ((ticker.Sell, amount) is the name of the order. } else if (action == SHORT) { exchange.SetDirection (("sell") TradeInfo = IsMarketOrder? exchange.Sell ((-1, amount)): exchange.Sell ((ticker.Buy, amount) is the name of the order. } else if (action == COVER_LONG) { // COVER_LONG is the cover_long , determine if this is the action, enter if here // Here you can specify parameters like all, to do the operation design of all of the placement, specifically write exchange.SetDirection (("closebuy") TradeInfo = IsMarketOrder? exchange.Sell ((-1, amount)): exchange.Sell ((ticker.Buy, amount) is the name of the order. } else if (action == COVER_SHORT) { Exchange.SetDirection (("closesell")) is a directory of the exchange. TradeInfo = IsMarketOrder? exchange.Buy ((-1, amount)): exchange.Buy ((ticker.Sell, amount) is the name of the order. } else { Log (("Futures exchanges not supported!", "#FF0000") I'm not sure. if (tradeInfo) { is the number of Log (("tradeInfo:", tradeInfo) is the name of the I'm not sure. } else { throw "eType error, eType:" + eType I'm not sure. Acc = _C (exchange.GetAccount) I'm not sure. What's up?

yidaiHave you solved your question?

The Little DreamThe stability of the TV alarms is not so clear, that depends on the TV.

beiyeargs=[191755, "buy:0.02"], adding a parameter here, doing more at the same time can also do nothing. Is one of the parameters better?

The Little DreamReceive TV requests using FMZ's extended API and access Body content at: https://www.fmz.com/api# Direct verification Now the data in the body can be received in the url of the TV request.

1131717062Please ask me how to set up the alert on tv, how to set up the alert on strategy, webhook url

The Little DreamYou can access Body content using FMZ's extended API to receive TV requests, see: https://www.fmz.com/api#%E7%9B%B4%E6%8E%A5%E9%AA%8C%E8%AF%81

Quantitative measurements of small insects https://www.fmz.com/strategy/221850,看到了,感谢大神!!

The Little DreamThere is a direct link to the requested body information, which can be found in the Strategy Square search.

The Little DreamThe policy was changed to 50 divided by the price then.

The Little DreamIf a command is received, the Robot Status tab is turned on, and the Last Received Command tab is turned on. This will show the command received. Check to see if there is no configuration.

lanbnIt is configured as a real-time Binance, no hint on the robot log, the TV is just a trigger condition and set it on the webhook, right?

The Little DreamTo answer the specific question, is the exchange configured on your robot spot, futures, what does the robot log show?

The Little Dream/upload/asset/16afbca03eec23516d37.png This is a list of all the different ways Afbca03eec23516d37 is credited in the database. You added the wrong exchange.

The Little DreamBrother, the API KEY screenshot needs to be encoded, security first.

Reverse the Q./upload/asset/19aee891571def2a6c4f3.png I have both the API permissions on the binance and I have an open contract account, but I can't always add a futures exchange when the strategy is running, is the code a problem?

The Little DreamThe log shows Binance explaining that the exchange object added is Binance Cash. But your policy set the futures contract code, so it is an error.

The Little DreamYou need to set an alarm in Trading view, fill in the webhook address in the alarm setting.

The Little Dreamhttps://www.fmz.com/api#exchange.setcontracttype... This function is described in the description and can be viewed here.

The Little DreamThe link is at the beginning of this article.

melo23What's the name of the B station video?

The Little DreamThe same applies to futures spot, just change the parameters inside the link. var BUY = "buy" Var SELL is "sell". var LONG is "long". var SHORT = "short" This is the last time I'm going to do this. This is the first time I've seen this. long is the open multihead position, short is the open blank position, cover_long is the flat multihead, cover_short is the flat blank position. What's up? This is a list of all the different ways Access_key=e3809e173e23004821a9bfb6a468e308&secret_key=45a811e0009d91ad21154e79d4074bc6&method=CommandRobot&args=[191755, "buy:0.02"] is credited in the database. What's up? The link to buy is replaced.

The Little DreamTwo alarms are added to the TV. One is cheap and one is empty.

sug210If you want to have multiple slots, i.e. the signal setup is cover_long:10 and short:10, but the TV is set to execute only one signal, isn't that a loss?

The Little DreamIn this case, the instruction to use the futures is not to buy, but to sell.

The Little DreamThe futures settings contract is done, and the policy parameters, in addition to the webhook url configured on the TV, use the futures commands long, cover_long and so on.

key986That's the operating code for the set of futures, please ask the futures should be re-written.

The Little DreamThere are video tutorials available here, from B Station.