资源加载中... loading...

Crawling down Binance's announcement of delisting currencies

Author: , Created: 2019-02-20 11:28:46, Updated:

Strategy purpose:

On February 15, Binance announced the taking off announcement of the CLOAK, MOD, SALT, SUB, WINGS. After the announcement, the currency involved immediately began to fall, generally down 15% in an hour, with more and more users knew the news, the decline continued and there was no rebound, and it has fallen by half so far. If you can sell the coins held in the first time after the announcement, you can recover a lot of losses.

This strategy runs on the FMZ quantitative trading platform (formerly BotVS).

Idea:

Crawling down the Binance security announcement pages and observe the information of the nearest two times of announcement. The specific format is “Binance will delist CLOAK, MOD, SALT, SUB, WINGS”, “Binance will delist BCN, CHAT, ICN, TRIG”.

The strategy will use the “will delist” as a keyword to crawl the new release announcement, of course, does not rule out the Binance change notification format, you can refer to this strategy to improve. Since the crawler task is too simple, it will be written in simple JavaScript. After crawling down the delist currency, the account information will be checked. If there is a delist currency, it will be sold at a lower price. If there is an uncompleted order, it will be revoked first. Until the sale of the remaining coins is completely sold.

Crawling code:

var html = HttpQuery('https://support.binance.com/hc/zh-cn/sections/115000202591-%E6%9C%80%E6%96%B0%E5%85%AC%E5%91%8A')//Announcement page
html = html.slice(html.indexOf('article-list'),html.indexOf('pagination')) // Article list section
if(html.indexOf('will delist')>0){
    if(html.slice(html.indexOf('will delist')+3,html.indexOf('</a>')) != title){ //crawl only the first delist information
        var title = html.slice(html.indexOf('delist')+3,html.indexOf('</a>'))
        var downList = title.split('、')
        Log('New announcement is detected, the currency will be delist:', title, '@')//WeChat push release announcement
    }
}

Revoking order code:

function cancellOrder(){
    var openOrders = exchange.IO('api', 'GET', '/api/v3/openOrders')//Get all unexecuted orders
    for (var i=0; i<openOrders.length; i++){
        var order = openOrders[i];
        for (var j=0;j<downList.length;j++){
            if(order.symbol.startsWith(downList[j])){
                var currency = downList[j] + '_' + order.symbol.slice(downList[j].length);
                Log('There is a delist currency order exist, revoked', currency)
                exchange.IO("currency", currency)//To revoke a order, you need the trading pair information, so you must first switch to the trading pair.
                exchange.CancelOrder(order.orderId)
            }
        }
    }
}

Check account code:

function checkAccount(){
    var done = false
    while(!done){
        account = _C(exchange.GetAccount)
        done = true
        for (var i=0; i<account.Info.balances.length; i++){
            if(downList.indexOf(account.Info.balances[i].asset)>-1 && parseFloat(account.Info.balances[i].free)>pairInfo[account.Info.balances[i].asset+'BTC'].minQty){
                Log('delist currency will be emptied', account.Info.balances[i].asset)
                sellAll(account.Info.balances[i].asset, parseFloat(account.Info.balances[i].free))
                done = false
            }
        }
        Sleep(1000)
    }
    Log('Sale completed')
}

Placing order code:

var exchangeInfo = JSON.parse(HttpQuery('https://api.binance.com/api/v1/exchangeInfo'))
var pairInfo = {}  //Trading pair information, storing transaction progress, minimum trading volume and other related information, placing order will needed
if(exchangeInfo){
    for (var i=0; i<exchangeInfo.symbols.length; i++){
        var info = exchangeInfo.symbols[i];
        pairInfo[info.symbol] = {minQty:parseFloat(info.filters[2].minQty),tickerSize:parseFloat(info.filters[0].tickSize), 
            stepSize:parseFloat(info.filters[2].stepSize), minNotional:parseFloat(info.filters[3].minNotional)}
    }
}else{
    Log('Failed to get transaction information')
}
function sellAll(coin, free){
    var symbol = coin + 'BTC'
    exchange.IO("currency", coin+'_BTC') //switching trading pair
    var ticker = _C(exchange.GetTicker)
    var sellPrice = _N(ticker.Buy*0.7, parseInt((Math.log10(1.1/pairInfo[symbol].tickerSize))))
    var sellAmount = _N(free, parseInt((Math.log10(1.1/pairInfo[symbol].stepSize))))
    if (sellAmount > pairInfo[symbol].minQty && sellPrice*sellAmount > pairInfo[symbol].minNotional){
        exchange.Sell(sellPrice, sellAmount, symbol)
    }
}

To sum up:

The above code is only for demonstration, the complete code can be found at FMZ.COM. The announcement page can be crawled once in a minute, which will have enough time to sell before the ordinary user.

But there may be some problems, such as crawling being blocked, announcement format changes, and so on. If the currency is not on the Binance, you can also refer to this strategy to other exchanges. After all, the delist currency will affect all platforms.


More