There are many manual trading friends in the coin circle who need a tracking robot, but they are suffering from the fact that it takes a long time for the introduction of programmatic design on the basis of 0. We based on such needs this article together to design a simple spot tracking robot, to help 0 basic learning program trading entry coin circle friends.

First of all, let’s analyze the requirements. The function of this robot is to realize that when a buying and selling operation occurs in one account, other documentary accounts follow the execution of this operation. Therefore, we first define two subjects:

  • Reference account: the account that is being monitored. Monitor every move of the account.
  • Documentary account: A documentary account that performs the same action as the reference account.

Having preliminarily identified this requirement, we should continue to think about it in the next step. How do we identify the movements of the reference account?

Monitoring the reference account is very simple for the spot account, we just compare the number of coins in the last account information data with the number of coins in the latest account information data currently obtained. If the number of coins in the latest account information data currently obtained is more than the previous record, the reference account has performed a purchase operation and the purchase has been successful. Conversely, if the coins are less, a sell operation is performed for the reference account. Once we find this action, we can simply have other exchange accounts perform the same action.

When a reference account is found to have executed a transaction, it is important to update the last account data record and compare it with the account information obtained next time to determine whether there is a new transaction action. The above logic is described in policy code:

Var amount = (nowacc.stocks + nowacc.frozenStocks) - (initacc.stocks + initacc.frozenStocks If (amount = $.Buy) else if (amount < 0) {if (amount = $.Sell) else { Continue} // Execute the Log(" Log! ", Math. Abs (amount), "#FF0000") for (var I = 1; i < exchanges.length ; Func (exchanges[I], math.abs (amount)); // Perform a specific trading function, such as $.buy or $.sell. InitAcc = nowAcc // Update the last account of the reference exchange for the next comparisonCopy the code

The main detection logic of the policy is the above code. To simplify the design, the policy uses the FMZ official [Digital Currency Transaction Class Library] template, $.Buy, $.Sell are functions of this template, the function is to execute the order operation. Add some status bar display to the policy to facilitate monitoring of the data of each account. The complete policy is as follows:

Var ts = new Date().gettime () if (ts % (1000 * 60 * 60 * 6) > 1000 * 60 * 60 * 5.5) {function test() {var ts = new Date().gettime () if (ts % (1000 * 60 * 60 * 6) > 1000 * 60 * 60 * 5.5) { Sleep(1000 * 60 * 10) var x = math.random () if (x > 0.5) {$.buy (exchange, x / 10)} else {$.sell (exchange, x / 10)} X / 10)}}} the function main () {LogReset (1) if (exchanges. Length < 2) {throw "no documentary exchange"} var exName = Exchange.GetName() if (exname.includes ("Futures_")) {throw "only support"} Log(" start monitoring ", exName, "exchange ", Var I = 1; var I = 1; i < exchanges.length ; If (exchanges[I].getName ().includes("Futures_")) {if (exchanges[I].getname ().includes("Futures_")) {if (exchanges[I].getname ().includes("Futures_")) {if (exchanges[I].getName ().includes("Futures_"))} While (1) {if(IsVirtual()) {// Test function test()} Sleep(5000) // Update the current account information of the reference account var nowAcc = _C(exchange.getAccount) // Var refTbl = {type: "table", title: "reference exchange ", cols: [" name "," coin ", "money "," money "], rows: [] } refTbl.rows.push([exName, nowAcc.Stocks, nowAcc.FrozenStocks, nowAcc.Balance, Var followTbl = {type: "table", title: "followTbl ", cols: [" name ", "c", "frozen currency", "money", "frozen money], rows: []} for (var I = 1; i < exchanges.length ; i++) { var acc = _C(exchanges[i].GetAccount) var name = exchanges[i].GetName() followTbl.rows.push([name, acc.Stocks, Acc.frozenstocks, acc.balance, acc.frozenBalance])} LogStatus(_D(), "\n '" + json.stringify (refTbl) + "' ", "\n '" + json.stringify (followTbl) + "' ") var amount = (nowacc.stocks + nowacc.frozenStocks) - (initacc.stocks + initAcc.FrozenStocks) var func = null if (amount > 0) { func = $.Buy } else if (amount < 0) { func = $.Sell } else { Continue} // Execute the Log(" Log! ", Math. Abs (amount), "#FF0000") for (var I = 1; i < exchanges.length ; I ++) {func(exchanges[I], math.abs (amount))}Copy the code

Let’s take a real test, using FMZ’s wexApp to simulate the exchange test. Here I have added three wexApp accounts, all of which are independent of each other. One serves as a reference exchange and the other two serve as a documentary exchange.

Then we manually place an order using FMZ’s transaction terminal to see if the robot will automatically follow the orders.

You can see that the robot detects the transaction and performs the tracking operation.

Complete strategy: www.fmz.com/strategy/25…

The policy is for learning only. If you have any questions, thank you.