0
关注
74
关注者

Simplified version of Multi-platform Hedging Stabilization Arbitrage strategy (Study purpose only)

创建于: 2018-08-30 10:28:43, 更新于: 2023-11-14 21:08:18
comments   2
hits   2179

Simplified version of Multi-platform Hedging Stabilization Arbitrage strategy  (Study purpose only)

Simplified version of Multi-platform Hedging Stabilization Arbitrage www.fmz.com the original version of this strategy, you can find it at: https://www.fmz.com/bbs-topic/2279 it contains a very specific comments about the code.

This shorter version is for study purpose only, due to our website’s tech improvement, most of your complicated strategies can be tremendously saving time on coding part. We are currently rebuilding our API function, we will make them easier to read and more effective to execute, besides the basic function, we will gather more method in some particular function than once you called the function, it will perform a serious great action.

Here is the simplified version:

var preSumBalance = 0
var initSumBalance = 0
function UpdateAccount(isFirst){
    var msg = ""
    var sumStocks = 0
    var sumBalance = 0
    for(var i = 0; i < exchanges.length; i++){
        if(exchanges[i].needUpdate == true || isFirst == true){
            exchanges[i].account = _C(exchanges[i].GetAccount)
            exchanges[i].needUpdate = false
            if(isFirst == true){
                initSumBalance += (exchanges[i].account.Balance + exchanges[i].account.FrozenBalance)
                exchanges[i].SetPrecision(_CurrencyPrecision, _BaseCurrencyPrecision)
            }
        }
        sumStocks += (exchanges[i].account.Stocks + exchanges[i].account.FrozenStocks)
        sumBalance += (exchanges[i].account.Balance + exchanges[i].account.FrozenBalance)
        msg += exchanges[i].GetName() + "coin:" + exchanges[i].account.Stocks + "Frozen coin:" + exchanges[i].account.FrozenStocks + "money:" + exchanges[i].account.Balance + "Frozen money:" + exchanges[i].account.FrozenBalance + "\n"
    }
    LogStatus(_D(), "Total Coins:" + sumStocks, "Total Money:" + sumBalance, "\n", msg)
    if(preSumBalance != sumBalance){
        LogProfit(sumBalance - initSumBalance, preSumBalance = sumBalance)
    }
}
function main(){
    UpdateAccount(true)
    while(1){
        for(var i = 0; i < exchanges.length; i++){
            for(var j = 0; j < exchanges.length; j++){
                if(i == 0 && j == 0){
                    for(var m = 0; m < exchanges.length; m++){
                        exchanges[m].thread = exchanges[m].Go("GetTicker")
                    }
                    for(var n = 0; n < exchanges.length; n++){
                        exchanges[n].ticker = exchanges[n].thread.wait()
                    }
                }
                if(exchanges[i].GetName() != exchanges[j].GetName() && exchanges[i].ticker && exchanges[j].ticker && exchanges[i].ticker.Buy - exchanges[j].ticker.Sell > _HedgePrice){
                    if(exchanges[i].account.Stocks > _HedgeAmount && exchanges[j].account.Balance / ((exchanges[i].ticker.Buy + exchanges[j].ticker.Sell) / 2) > _HedgeAmount){
                        var sellId_I = exchanges[i].Sell((exchanges[i].ticker.Buy + exchanges[j].ticker.Sell) / 2, _HedgeAmount, exchanges[i].GetName())
                        var buyId_J = exchanges[j].Buy((exchanges[i].ticker.Buy + exchanges[j].ticker.Sell) / 2, _HedgeAmount, exchanges[i].GetName())
                        exchanges[i].needUpdate = exchanges[j].needUpdate = true
                    }
                }
            }
        }
        UpdateAccount(false)
        Sleep(300)      // test
    }
}
相关推荐
更多内容
全部留言
avatar of QQ4830163
QQ4830163
zan
2018-08-30 11:38:15
avatar of 发明者量化-小小梦
发明者量化-小小梦
Gooood!
2018-08-30 11:18:30