0bps

Strategy vault / Tools & templates

Spot Selling Has Always Occupied One Plugin

Always occupying the position of buying one or selling one is also a way to slowly ship goods, which has a relatively small impact on the market. There are still some improvements to this strategy. You can manually…

Author
小草
Complexity
Starter · 40 lines
Parameters
2

Always occupying the position of buying one or selling one is also a way to slowly ship goods, which has a relatively small impact on the market. There are still some improvements to this strategy. You can manually change the minimum transaction volume or accuracy. Buy: https://www.fmz.com/strategy/191582 Sell:https://www.fmz.com/strategy/191730

The plug-in can be started with one click on the trading terminal, free of charge, and convenient for manual trading. Detailed introduction:https://www.fmz.com/digest-topic/5051

Parameters

NameDefaultWhat it controls
SellAmount2Sell Quantity | Sell amount
InterveltrueSleep time (seconds))

Source JavaScript

function GetPrecision(){
    var precision = {price:0, amount:0}
    var depth = exchange.GetDepth()
    for(var i=0;i<depth.Asks.length;i++){
        var amountPrecision = depth.Asks[i].Amount.toString().indexOf('.') > -1 ? depth.Asks[i].Amount.toString().split('.')[1].length : 0
        precision.amount = Math.max(precision.amount,amountPrecision)
        var pricePrecision = depth.Asks[i].Price.toString().indexOf('.') > -1 ? depth.Asks[i].Price.toString().split('.')[1].length : 0
        precision.price = Math.max(precision.price,pricePrecision)
    }
    return precision
}

function main(){
    var initAccount = exchange.GetAccount()
    if(!initAccount){return 'Unable to obtain account information'}
    var precision = GetPrecision()
    var sellPrice = 0
    var lastId = 0
    var done = false
    while(true){
        var account = _C(exchange.GetAccount)
        var dealAmount = - account.Stocks + initAccount.Stocks
        var ticker = _C(exchange.GetTicker)
        if(SellAmount - dealAmount > 1/Math.pow(10,precision.amount) && ticker.Sell < sellPrice){
            if(lastId){exchange.CancelOrder(lastId)}
            var id = exchange.Sell(ticker.Sell, _N(SellAmount - dealAmount,precision.amount))
            if(id){
                lastId = id
            }else{
                done = true
            }
        }
        if(BuyAmount - dealAmount <= 1/Math.pow(10,precision.amount)){done = true}
        if(done){
            var avgCost = (-initAccount.Balance + account.Balance)/dealAmount
            return 'order is done, avg cost is ' + avgCost  // including fee cost
        }
        Sleep(Intervel*1000)
    }
}

Published by 小草 on the FMZ strategy square · last modified 2020-06-09. 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 tested, production-ready module from strategies/Spot-Selling-Has-Always-Occupied-One-Plugin.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