0bps

Strategy vault / Other

Simple Iceberg order to buy

Very simple, just for learn. Code is best annotation. Iceberg entrusted buying, which divides the order into small M purchases to avoid impacting the market, is a good learning strategy for simple entry into Bitcoin…

JavaScriptOther
Author
小草
Complexity
Starter · 23 lines
Parameters
3

Very simple, just for learn. Code is best annotation.

Iceberg entrusted buying, which divides the order into small M purchases to avoid impacting the market, is a good learning strategy for simple entry into Bitcoin quantitative trading.

Parameters

NameDefaultWhat it controls
BUYAMOUNT2amount to buy
BUYSIZE0.1iceberg order size
INTERVAL3orders exist time(second)

Source JavaScript

function main(){
    var initAccount = _C(exchange.GetAccount)
    while(true){
        var account = _C(exchange.GetAccount)
        var dealAmount = account.Stocks - initAccount.Stocks
        var ticker = _C(exchange.GetTicker)
        if(BUYAMOUNT - dealAmount > BUYSIZE){
            var id = exchange.Buy(ticker.Sell, BUYSIZE)
            Sleep(INTERVAL*1000)
            if(id){
                exchange.CancelOrder(id) // May cause error log when the order is completed, which is all right.
            }else{
                throw 'buy error'
            }
        }else{
            account = _C(exchange.GetAccount)
            var avgCost = (initAccount.Balance - account.Balance)/(account.Stocks - initAccount.Stocks)
            Log('Iceberg order to buy is done, avg cost is ', avgCost) // including fee cost
            return
        }
        
    }
}

Published by 小草 on the FMZ strategy square · last modified 2020-03-20. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Simple-Iceberg-order-to-buy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open