In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to use the inventor quantitative trading platform to expand API to achieve TradingView alarm signal trading. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
Links to related parts of the inventor's API document
The main function of extended API is to provide interfaces for programmatic inventors to quantify various functions on the trading platform, such as starting robots in batches at the same time, timing robot start and stop, reading robot information details and so on. We use the inventor quantitative trading platform extension API to achieve TradingView alarm signal trading. This requirement plan only uses the CommandRobot (RobotId, Cmd) interface in the extended API, which can send interactive instructions to the specified ID robot, and the robot can perform corresponding operations (such as placing an order to buy, sell, etc.) when it receives the instruction.
To use the extended API, you first need to create your own API KEY for the inventor's account:
The API KEY secret key is composed of access key and secret key. API KEY is the key of the quantitative trading platform for the inventors of programmed operation, so be sure to keep it safe and do not disclose it.
Extending the direct access mode of API
The direct access mode refers to writing the API KEY directly in the Query of URL. For example, the URL of accessing the inventor's quantitative 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"]
Where https://www.fmz.com/api/v1 is the interface address,? This is followed by Query. The parameter access_key key is represented by xxx (enter the access_key of your own FMZ account when you use it), and the parameter secret_key key is expressed by yyyy (you enter your account secret_key when using it). Parameter method is the specific name of the extended API API to be accessed, and args is the parameter of the method API to be called.
We use TradingView as the signal source to send transaction orders to the inventor's quantitative trading platform robot. In fact, we only use the interface CommandRobot.
TradingView
First of all, you need to have an account at the TradingView Pro level, and the WebHood function in the alarm cannot be used at the Basic level. Let's go to the TradingView chart.
Add an indicator to the chart, which can also be another scripting algorithm. Here to facilitate the demonstration we use the most commonly used MACD indicator, and then set the K-line period to 1 minute (to make the signal trigger faster, easy to demonstrate).
Right-click on the chart and select "add Alert" from the pop-up menu.
Set WebHook in the "alarm" pop-up window. At this point, you don't have to worry about it. Let's start running the robot whose inventors quantify the monitoring signals on this side of the trading platform.
Monitoring signal placing order robot
Policy source code:
/ / Global variable var BUY = "buy" var SELL = "sell" var LONG = "long" var SHORT = "short" var COVER_LONG = "cover_long" var COVER_SHORT = "cover_short" function main () {/ / clear the log if not required You can delete LogReset (1) / / set precision exchange.SetPrecision (QuotePrecision, BasePrecision) / / identify whether futures or spot var eType = 0var eName = exchange.GetName () var patt = / Futures_/if (patt.test (eName)) {Log ("added exchange is futures exchange:", eName, "# FF0000") eType = 1if (Ct = ") {throw" Ct contract is set empty} else {Log (exchange.SetContractType (Ct)) "set contract:", Ct, "# FF0000")}} else {Log ("the added exchange is a spot exchange:", eName "# 32CD32")} var lastMsg = "" var acc = _ C (exchange.GetAccount) while (true) {var cmd = GetCommand () if (cmd) {/ / detect interactive command lastMsg = "Command:" + cmd + "time:" + _ D () var arr = cmd.split (":") if (arr.length! = 2) {Log ("cmd message error:", 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 ("not supported by spot exchanges!" , "# FF0000")}} else if (eType = = 1) {var tradeInfo = nullvar 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 ("Futures Exchange does not support!" , "# FF0000")} if (tradeInfo) {Log ("tradeInfo:", tradeInfo)}} else {throw "eType error, eType:" + eType} acc = _ C (exchange.GetAccount)} var tbl = {type: "table", title: "status Information" Cols: ["data"], rows: []} tbl.rows.push ([JSON.stringify (acc)]) LogStatus (_ D (), eName, "commands received last time:", lastMsg, "\ n", "`" + JSON.stringify (tbl) +`) Sleep (1000)}}
Policy source code
The policy code is very simple and detects the return value of the GetCommand function. When an interactive message is sent to the policy program, the GetCommand function returns the message, and then the policy program makes the corresponding transaction operation according to the content of the message. Interactive buttons have been set on the strategy to test interactive functions, such as running the strategy to configure the robot with the inventor's simulated exchange WexApp of the trading platform.
Click the interactive button to test the robot's ability to receive orders to buy.
You can see that the command string received by the robot is: buy:0.01.
When the TradingView alarm is triggered, when WebHook requests the URL to access the inventor's quantitative trading platform to extend the CommandRobot interface of API, the parameter is buy:0.01.
Set the WebHook of TradingView
Back in TradingView, we fill in the URL of WebHook. Enter your own API KEY for the access_key and secret_key parameters. Method is fixed, and all we need to access is the extended API API CommandRobot. The args parameter is in the form of [robot ID, command string]. Robot ID can be obtained directly from the robot page, as shown in the figure:
When we let the signal trigger this time, buy 0.02 coins, and the command string is: "buy:0.02". So the WebHook URL is done.
Https://www.fmz.com/api/v1?access_key=e3809e173e23004821a9bfb6a468e308&secret_key=45a811e0009d91ad21154e79d4074bc6&method=CommandRobot&args=[191755,"buy:0.02"]
Set up on TradingView:
Wait for the signal to trigger.
Wait for the signal to trigger..
Wait for the signal to trigger.
...
The robot picked up the signal:
In this way, we can use the rich chart functions and index algorithms on TradingView to cooperate with the strategy robot of the inventor's quantitative trading platform to realize the automatic transaction we want. compared with transplanting the strategy on TradingView into JavaScript and Python language, the difficulty is reduced.
The above is the editor for you to share how to use the inventor quantitative trading platform to expand API to achieve TradingView alarm signal trading, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.