The resource loading... loading...

In addition, the number of plug-ins sold has been increasing.

Author: The grass, Date: 2020-03-20 14:09:21
Tags:

Holding the buy or sell position is also a way to move slowly, with less impact on the market. This strategy has some improvements, such as manually changing the minimum volume or precision of the trade. I'm going to buy it.https://www.fmz.com/strategy/191582It was sold:https://www.fmz.com/strategy/191730

The plug-in can be started at the touch of a button on the transaction terminal, without charging a fee, and facilitates manual transactions.https://www.fmz.com/digest-topic/5051


function GetPrecision(){
    var precision = {price:0, amount:0}
    var depth = exchange.GetDepth()
    for(var i=0;i<depth.Asks.length;i++){
        var amountPrecision = depth.Asks[i].Amount.toString().indexOf('.') > -1 ? depth.Asks[i].Amount.toString().split('.')[1].length : 0
        precision.amount = Math.max(precision.amount,amountPrecision)
        var pricePrecision = depth.Asks[i].Price.toString().indexOf('.') > -1 ? depth.Asks[i].Price.toString().split('.')[1].length : 0
        precision.price = Math.max(precision.price,pricePrecision)
    }
    return precision
}

function main(){
    var initAccount = exchange.GetAccount()
    if(!initAccount){return '无法获取账户信息'}
    var precision = GetPrecision()
    var sellPrice = 0
    var lastId = 0
    var done = false
    while(true){
        var account = _C(exchange.GetAccount)
        var dealAmount = - account.Stocks + initAccount.Stocks
        var ticker = _C(exchange.GetTicker)
        if(SellAmount - dealAmount > 1/Math.pow(10,precision.amount) && ticker.Sell < sellPrice){
            if(lastId){exchange.CancelOrder(lastId)}
            var id = exchange.Sell(ticker.Sell, _N(SellAmount - dealAmount,precision.amount))
            if(id){
                lastId = id
            }else{
                done = true
            }
        }
        if(BuyAmount - dealAmount <= 1/Math.pow(10,precision.amount)){done = true}
        if(done){
            var avgCost = (-initAccount.Balance + account.Balance)/dealAmount
            return 'order is done, avg cost is ' + avgCost  // including fee cost
        }
        Sleep(Intervel*1000)
    }
}

More