Skip to content

Latest commit

 

History

History
100 lines (80 loc) · 2.57 KB

数字货币现货打新抢币策略教学.md

File metadata and controls

100 lines (80 loc) · 2.57 KB

Name

数字货币现货打新抢币策略教学

Author

小小梦

Strategy Description

相关文章:https://www.fmz.com/bbs-topic/9262

Strategy Arguments

Argument Default Description
symbol null 监控的交易对
ApiReqInterval 200 api请求间隔
pendingPrice -1 挂单价格
pendingAmount -1 挂单量
deltaPrice -1 价格变动
deltaAmount -1 订单量变动
ordersNum 10 订单数量

Source (javascript)

function pendingOrders(ordersNum, price, amount, deltaPrice, deltaAmount) {
    var routineOrders = []
    var ordersIDs = []
    for (var i = 0 ; i < ordersNum ; i++) {
        var routine = exchange.Go("Buy", price + i * deltaPrice, amount + i * deltaAmount)
        routineOrders.push(routine)
        Sleep(ApiReqInterval)        
    }
    for (var i = 0 ; i < routineOrders.length ; i++) {
        var orderId = routineOrders[i].wait()
        if (orderId) {
            ordersIDs.push(orderId)
            Log("成功挂单", orderId)
        }        
    }
    return ordersIDs
}

function main() {
    if (symbol == "null" || pendingPrice == -1 || pendingAmount == -1 || pendingPrice == -1 || deltaPrice == -1 || deltaAmount == -1) {
        throw "参数设置错误"
    }
    exchange.SetCurrency(symbol)
    // 屏蔽错误信息
    SetErrorFilter("GetDepth")
    while (true) {
        var msg = ""
        var depth = exchange.GetDepth()
        if (!depth || (depth.Bids.length == 0 && depth.Asks.length == 0)) {
            // 没有深度
            msg = "没有深度数据,等待!"
            Sleep(500)
        } else {
            // 获取到深度
            Log("并发下单!")
            var ordersIDs = pendingOrders(ordersNum, pendingPrice, pendingAmount, deltaPrice, deltaAmount)
            while (true) {
                var orders = _C(exchange.GetOrders)
                if (orders.length == 0) {
                    Log("当前挂单个数0,停止运行")
                    return 
                }
                var tbl = {
                    type: "table",
                    title: "当前挂单",
                    cols: ["id", "价格", "数量"], 
                    rows: []
                }
                _.each(orders, function(order) {
                    tbl.rows.push([order.Id, order.Price, order.Amount])
                })
                LogStatus(_D(), "\n`" + JSON.stringify(tbl) + "`")
                Sleep(500)
            }
        }
        LogStatus(_D(), msg)
    }
}

Detail

https://www.fmz.com/strategy/358383

Last Modified

2022-04-20 18:43:33