How to exploit brainless robots for sale with high-frequency strategies of 80 lines of code

Author: The grass, Created: 2023-12-24 21:37:45, Updated: 2023-12-26 15:40:23

img

Opportunity to observe

It's strange to see that Binance has a Binance STORJ market in the last two days, the volume of transactions is very large, and the frequency of transactions is very fast, the specific K line in a minute is shown below, you can see that the volume of transactions per minute is consistent, and on the minute line you can see the long shadow line.imgUsing the 1-second K-line of the binan, it was found that the endpoints, where someone will trade between 20,000 and 20,000 STORJs every 5-7s, regardless of the cost, drilled a small hole directly on the K-line, and the price will recover in the short term. This operation was obviously caused by the robot commissioned by the iceberg. This operation sold lasted very long, the total amount is estimated to reach the level of tens of millions of dollars, and many times the slippage was 1 in a thousand, which means that the slippage of the trade alone, the executor of this strategy loses hundreds of thousands of dollars.img

In a few minutes, the robot that was commissioned to exploit the brainless iceberg was ready, simply changing the original high-frequency strategy of the spot market.

Strategic thought

Since the market price is sold every few seconds, we only need to find 10,000 depths in the purchase book and hang the unit in front. So when this iceberg is sold, there is a high probability that the market robot will receive it, and the transaction is very active at this time, and the instant price drop also triggered some bids, the same logic hanging the sale of a single order is thrown out, so repeated operation.

Strategic performance

The strategy is as follows, at the beginning of the earnings were not printed, this afternoon changed, printed out the earnings, the crazy selling robot has changed the amount of each time to about 5000, so it is past the period of the best rate. Just started probably can cook 100-200U per hour, the key is risk-free, low cost. From here, on the other hand, the iceberg commission actually has a lot of tricks, if you write a strategy, spend a dozen or so minutes on FMZ can write out the purchase order in depth determine the order size and price, observe the size of the proactive payment adjustment of the size of the order and the iceberg commission strategy, which is characterized by features such as the size of the plate and occupies the mouth, easily save about tens of thousands of dollars.

img

Policy source code

The strategy code is very simple, only 80 lines. For beginners, some of the parameters here are written in the program, such as simple accuracy, you can change them yourself, the necessary parameters are as shown below, it is recommended to save them in case the exchange trades against other traders, and at any time collect interest from them.img

function CancelPendingOrders() {
    var orders = _C(exchange.GetOrders)
    for (var j = 0; j < orders.length; j++) {
        exchange.CancelOrder(orders[j].Id, orders[j])
    }
}

function onexit(){
    CancelPendingOrders()
}

function GetPrice(Type, Depth) {
    var sumAmount = 0
    var checkAmount = Type == "Buy" ? CheckBuyAmount : CheckSellAmount
    var deep = Type == "Buy" ? Depth.Bids : Depth.Asks
    for(var i = 0; i < Math.min(20, deep.length); i++) {
        if(Type == "Buy"  && deep[i].Price == lastBuyPrice && buyId){
            sumAmount += deep[i].Amount - amountBuy //这里要减去自己的挂单
        }else if(Type == "Sell"  && deep[i].Price == lastSellPrice && sellId){
            sumAmount += deep[i].Amount - amountSell
        }else{
            sumAmount += deep[i].Amount
        }
        if(sumAmount >= checkAmount){
            return deep[i].Price
        }
    }
    return deep[19].Price
}

function OnTick() {
    var depth = _C(exchange.GetDepth)
    var buyPrice = _N(Math.min(GetPrice("Buy", depth) + 0.0001, depth.Asks[0].Price-0.0001) , 4) //保证在盘口
    var sellPrice = _N(Math.max(GetPrice("Sell", depth) - 0.0001, depth.Bids[0].Price+0.0001), 4)
    LogStatus('buy_price:'+buyPrice, '  sell price: '+sellPrice)
    if ((sellPrice - buyPrice) < DiffPrice) {
        buyPrice = 0
    }
    if(sellPrice != lastSellPrice && sellId){
        exchange.CancelOrder(sellId);
        sellId = 0
        lastSellPrice = 0
    }
    if(buyPrice != lastBuyPrice && buyId){
        exchange.CancelOrder(buyId);
        buyId = 0
        lastBuyPrice = 0
    }   
    var acc = _C(exchange.GetAccount)
    if(account.Stocks+account.FrozenStocks != acc.Stocks+acc.FrozenStocks){
        LogProfit((acc.Stocks+acc.FrozenStocks)*depth.Bids[0].Price+acc.Balance+acc.FrozenBalance - 2000)
        Log('free '+acc.Stocks, ' lock: '+ acc.FrozenStocks, ' total: ' , (acc.Stocks+acc.FrozenStocks)*depth.Bids[0].Price+acc.Balance+acc.FrozenBalance)
    }
    account = acc
    amountBuy = _N(Math.min(account.Balance / buyPrice - 0.1, Amount), 0)
    amountSell = _N(account.Stocks, 0)
    if (sellPrice > 0 && amountSell > 40 && sellId == 0) {
        sellId = exchange.Sell(_N(sellPrice,4), amountSell)
        lastSellPrice = sellPrice
    }
    if (buyPrice>0 && amountBuy > 40 && buyId == 0) {
        buyId = exchange.Buy(_N(buyPrice,4), amountBuy)
        lastBuyPrice = buyPrice
    }
    Sleep(Interval)
}
var account = {Stocks:0, FrozenStocks:0, Balance:0, FrozenBalance:0}
var buyId = 0
var sellId = 0
var lastBuyPrice = 0
var lastSellPrice = 0
var amountSell = 0
var amountBuy = 0
function main() {
    CancelPendingOrders()
    while (true) {
        OnTick()
    }
}

More

checkpointGrass God, how much does this tactical procedure cost?

yc123hTeacher, if this policy is effective, is it possible that at the beginning of each round, you will often see two failed orders before the cancellation (i.e. the buy and sell orders are in effect)?

The grassSo this is a zero fee.

yc123hThank you very much, I also want to ask you about the parameters. For example, how to optimize the parameters of this high-frequency strategy. For example, I see the strategy you shared in 2014, the default training interval reached 3500ms. If it is high frequency, the training interval should be a little shorter.

The grassRevocation fails, it's a deal, it's money to prove it works