Loading ...

通过获取深度解决下单精度问题

Author: 小草, Created: 2020-03-20 09:10:52, Updated: 2020-03-20 09:11:16

由于各个交易所的不统一,FMZ并没有统一的下单精度返回函数。如果策略只做一个币种还好,如果要兼容多个交易对又兼容多个交易所,这里推荐使用获取深度,根据深度信息自动推算出下单精度。当然,如果要交易多个币种,还是推荐用HttpQuery访问原始API接口。 函数如下:

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


More

小草 /upload/asset/1a65c7984cded325640.jpg /upload/asset/1fbed0c3795dbecac04.jpg

小草 /upload/asset/1a65c7984cded325640.jpg

小草 /upload/asset/20c45ed76cbe4acc2bd.csv /upload/asset/1ef1af8ec28a75a2dcb.csv /upload/asset/1d4282a201cd858a6a2.jpg

小草 /upload/asset/20c45ed76cbe4acc2bd.csv /upload/asset/1ef1af8ec28a75a2dcb.csv

小草 /upload/asset/20c45ed76cbe4acc2bd.csv