暗号通貨スポットのシンプルなオーダー監督ボットを実現する

作者: リン・ハーンニナバダス作成日:2022年4月11日 11:54:34 更新日:2022年4月11日 11:55:08

暗号通貨スポットのシンプルなオーダー監督ボットを実現する

クリプトコインサークルの友人はたくさんいますが,ゼロベースでプログラム設計を始めるのに時間がかかるので苦しんでいます. このようなニーズに基づいて,この記事では,ゼロベースでプログラム取引を学ぶ友人を助けるためのシンプルなスポットオーダー監督ボットを設計します.

まず,このボットの機能は,アカウントが購入または販売操作を行うとき,他のオーダー監督アカウントも操作をフォローして実行することを認識することです. まず2つのテーマを定義します

  • 基準口座: 監視されている口座で,その各行事は監視されています.
  • オーダー監督口座: オーダー監督口座. 基準口座がアクションを行う場合,オーダー監督口座は同じアクションを実行します.

この要求が最初に明確になった後,次のステップについて考え続けます.参照アカウントのすべての行動をどのように識別することができますか.

参照口座を監視します. 現金取引口座では非常に簡単です. 最新の口座情報データにおけるシンボルの金額を, 最新の口座情報データにおける現在のシンボルの金額と比較するだけです. 現在入手した最新のアカウント情報データにおけるシンボルの金額が前のレコードよりも多い場合,参照アカウントが購入操作を実行し,実行が成功したことを証明します.逆に,シンボルが少ない場合は,参照アカウントのために販売操作が行われます.アクションを検出した後,他のプラットフォームアカウントが同じ操作を実行してください.

基準口座が取引を行ったことが判明した場合,最新の口座データ記録を更新し,次の取引時に取得した口座情報と比較して,新たな取引が行われているかどうかを決定する必要があります.

上記の論理の戦略コード記述:

        // detect order supervising
        var amount = (nowAcc.Stocks + nowAcc.FrozenStocks) - (initAcc.Stocks + initAcc.FrozenStocks)  // detect the currency amount changes 
        var func = null 
        if (amount > 0) {   // the amount increased 
            func = $.Buy    // buy
        } else if (amount < 0) {  // the amount decreased 
            func = $.Sell         // sell 
        } else {
            continue
        }
        
        // execute order supervising 
        Log("Order supervising! Amount:", Math.abs(amount), "#FF0000")
        for (var i = 1 ; i < exchanges.length ; i++) {    // when i equals 0, it indicates the reference platform, not to be processed; process other order supervising platforms 
            func(exchanges[i], Math.abs(amount))          // execute the specified trading function, and it could be $.Buy or $.Sell, which needs to be determined by observing whether amount is larger than 0 or less than 0
        }
        
        // update the information record of the reference account after order supervising 
        initAcc = nowAcc                                  // update the latest account information of the reference platform, to compare it with the next one 

戦略の主な検出論理は上記のコードです. デザインを簡素化するために,戦略は公式のFMZ [デジタル通貨取引図書館]テンプレートを使用し,$.Buyそして$.Sellテンプレートのすべての関数である場合,その関数はオーダー操作を実行することです.

各アカウントのデータの監視を容易にするため,戦略にいくつかのステータスバー表示を追加します. 完全な戦略は以下のとおりです:

function test() { 
    // test function 
    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)    
        }        
    }
}

function main() {
    LogReset(1)
    if (exchanges.length < 2) {
        throw "no platform of order supervising"
    }
    var exName = exchange.GetName()
    // detect the reference platform 
    if (exName.includes("Futures_")) {
        throw "only support sport order supervising"
    }
    Log("start monitoring", exName, "platform", "#FF0000")
    
    // detect the order supervising platforms 
    for (var i = 1 ; i < exchanges.length ; i++) {
        if (exchanges[i].GetName().includes("Futures_")) {
            throw "Do not support the order supervising of futures platfroms"
        }
    }
    
    var initAcc = _C(exchange.GetAccount)
    while(1) {
        if(IsVirtual()) {
           // test function
           test()  
        }  
        Sleep(5000)
        
        // update the current information of the reference account 
        var nowAcc = _C(exchange.GetAccount)
        
        // the account information of the reference platform
        var refTbl = {
            type : "table", 
            title : "reference platform",
            cols : ["name", "symbol", "frozen symbol", "assets", "frozen assets"],
            rows : []
        }
        refTbl.rows.push([exName, nowAcc.Stocks, nowAcc.FrozenStocks, nowAcc.Balance, nowAcc.FrozenBalance])
        
        // the account information of the order supervising platform
        var followTbl = {
            type : "table", 
            title : "order supervising platform",
            cols : ["name", "symbol", "frozen symbol", "assets", "frozen assets"],
            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])
        }
        
        // status bar display 
        LogStatus(_D(), "\n`" + JSON.stringify(refTbl) + "`", "\n`" + JSON.stringify(followTbl) + "`")
        
        // detect order supervising 
        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 order supervising 
        Log("Order supervising! Amount:", Math.abs(amount), "#FF0000")
        for (var i = 1 ; i < exchanges.length ; i++) {            
            func(exchanges[i], Math.abs(amount))
        }
        
        // update the information record of the reference account after order supervising 
        initAcc = nowAcc
    }
}

FMZ wexAppシミュレーションプラットフォームで,実際のボットでテストしてみましょう.ここで私は3つのwexAppアカウントを追加しました.これらはすべて独立したアカウントです. 1つは参照プラットフォームとして,他の2つは注文監督プラットフォームとして機能します.

img

自動でオーダーを監視できるか調べました 自動でオーダーを監視できるか調べました

img

ボットが取引を検知し オーダー監督の操作を行いました

img

完全な戦略:https://www.fmz.com/strategy/255182

戦略は研究のためだけにあります.質問がある場合は,そのことについてコメントを残してください.


もっと