0bps

Strategy vault / Other

Automatically Retrieve Minimum Opening Unit Precision for Binance Perpetual Contracts Abandoned

Originally, directly obtaining trading precision from the trading rules was reasonable, but Binance often does not update this promptly, so it was abandoned.

PythonOther
Author
GCC
Complexity
Starter · 30 lines
Parameters
0

Originally, directly obtaining trading precision from the trading rules was reasonable, but Binance often does not update this promptly, so it was abandoned.

Source Python

def init():
    global symbols, min_value
    # Get Trading Rules
    exchange.SetBase('https://dapi.binance.com')
    rule = exchange.IO("api", "GET", "/dapi/v1/exchangeInfo", "", "")["symbols"]
    Log(rule)
    # Get trading pair name
    for i in range(len(exchanges)):
        exchanges[i].SetMarginLevel(M)
        exchanges[i].SetContractType("swap")  # Set Perpetual Contract
        _symbol = exchanges[i].GetCurrency().split("_")[0]   # +'USDT'Coin-margined trading pair name
        # Set Trading Precision
        j = 0
        flag1 = False
        flag2 = False
        #Log(rule)
        while (j < len(rule)) and flag1 == False and flag2 == False:
            if str(rule[j]["symbol"]).rfind(_symbol)>=0:
                for x in rule[j]["filters"]:
                    if x["filterType"] == "PRICE_FILTER" and flag1 == False:
                        #Log("Price",x["tickSize"])
                        #Log(len(str(float(x["tickSize"])).split('.')[-1]))
                        price_precision = len(str(float(x["tickSize"])).split('.')[-1])
                        flag1 = True
                    elif x["filterType"] == "LOT_SIZE" and flag2 == False:
                        amount_precision = len(x["minQty"].split('.')[-1])
                        flag2 = True
            j = j + 1
        exchanges[i].SetPrecision(price_precision, amount_precision)
    Log("initialization finished")

Published by GCC on the FMZ strategy square · last modified 2021-11-12. 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/Automatically-Retrieve-Minimum-Opening-Unit-Precision-for-Binance-Perpetual-Contracts-Abandoned.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