0bps

Strategy vault / Other

Tutorial on the Strategy of New Digital Currency Spot Games and Grabbing Coins

Related articles:https://www.fmz.com/bbs-topic/9262

JavaScriptOther
Author
发明者量化-小小梦
Complexity
Intermediate · 60 lines
Parameters
7

Related articles:https://www.fmz.com/bbs-topic/9262

Parameters

NameDefaultWhat it controls
symbolnullMonitored trading pair
ApiReqInterval200apiRequest Interval
pendingPrice-1Order Price
pendingAmount-1Pending order volume
deltaPrice-1Price Change
deltaAmount-1Order Quantity Change
ordersNum10Order Quantity

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("Successfully Placed Order", orderId)
        }        
    }
    return ordersIDs
}

function main() {
    if (symbol == "null" || pendingPrice == -1 || pendingAmount == -1 || pendingPrice == -1 || deltaPrice == -1 || deltaAmount == -1) {
        throw "Parameter setting error"
    }
    exchange.SetCurrency(symbol)
    // Suppress error messages
    SetErrorFilter("GetDepth")
    while (true) {
        var msg = ""
        var depth = exchange.GetDepth()
        if (!depth || (depth.Bids.length == 0 && depth.Asks.length == 0)) {
            // No Depth
            msg = "No depth data, waiting!"
            Sleep(500)
        } else {
            // Obtain Depth
            Log("Concurrent Orders!")
            var ordersIDs = pendingOrders(ordersNum, pendingPrice, pendingAmount, deltaPrice, deltaAmount)
            while (true) {
                var orders = _C(exchange.GetOrders)
                if (orders.length == 0) {
                    Log("Current number of pending orders0,Stop Running")
                    return 
                }
                var tbl = {
                    type: "table",
                    title: "Current pending order",
                    cols: ["id", "Price, Quantity"], 
                    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)
    }
}

Published by 发明者量化-小小梦 on the FMZ strategy square · last modified 2022-04-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/Tutorial-on-the-Strategy-of-New-Digital-Currency-Spot-Games-and-Grabbing-Coins.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