Loading ...

币安合约websocket接口查询持仓账户范例

Author: 小小梦, Date: 2020-12-15 15:21:45
Tags: Tool Binance

币安合约websocket接口查询持仓账户范例

币安文档:https://binance-docs.github.io/apidocs/delivery/cn/#e3ee8329c9

测试时添加配置之后的币安期货交易所对象。

img


function main() {
    LogReset(1)
    var ws = null
    exchange.IO("base", "https://dapi.binance.com")
    var obj = exchange.IO("api", "POST", "/dapi/v1/listenKey")
    Log(obj, typeof(obj))
    var listenKey = obj.listenKey
    Log("listenKey:", listenKey)
    var ts = new Date().getTime()
    ws = Dial("wss://dstream.binance.com/ws/" + String(listenKey))
    while (1) {
        var arr = ["balance", "account", "position"]
        for (var i in arr) {
            var info = {
                "method": "REQUEST",
                "params": [
                    listenKey + "@" + arr[i]
                ],
                "id": ts
            }
            ws.write(JSON.stringify(info))
            var ret = ws.read()
            Log(ret)
            Sleep(1000)
        }
        Sleep(1000)
    }
}

Related

More

韬奋量化 这个例子的方法好像只适用于币本位合约吧?我试过把合约地址改成u本位,发现不能通过websocket主动查询"balance", "account", "position"等信息

威萌貔貅 给力

威萌貔貅 给力

小小梦 根据交易所文档写。不一定币本位和U本位是一模一样的 /upload/asset/17a3ea8b5fed6c2d05fd.png /upload/asset/1699cb3f9cea6f9b2012.png