0bps

Strategy vault / Other

Huobi Precision

- $.getAmountPrecision(Currency) Trading pair base currency counting precision (number of decimal places)) Return value type number - $.getPricePrecision(Currency) Precision of trading pair quotes (decimal places).)…

JavaScriptOther
Author
一拳男孩
Complexity
Intermediate · 104 lines
Parameters
1
  • $.getAmountPrecision(Currency)

Trading pair base currency counting precision (number of decimal places)) Return value type number

  • $.getPricePrecision(Currency)

Precision of trading pair quotes (decimal places).) Return value type number

  • $.getMinOrderAmount(Currency)

Minimum order size of trading pair Return value type number

  • $.getMaxOrderAmount(Currency)

Maximum order size of trading pair Return value type number

  • $.getValuePrecision(Currency)

Precision of the trading pair transaction amount (decimal places)) Return value type number

  • $.getMinValue(Currency)

Minimum order amount (the order amount refers to (amount * price) passed in by the order interface when the order type is a limit order. When the order type is buy-market, the order amount is passed in by the order interface'amount') Return value type number

Parameters

NameDefaultWhat it controls
TICKER_EXPIRE_TIME600Market data cache time (seconds))

Source JavaScript

var _symbols = _C(getSymbols)
var _cacheTicker = {}

function parseJson(str) {
    try {
        return JSON.parse(str)
    } catch(e) {
        Log(str + e.message + '#FF0000')
        return null
    }
}

function getSymbols() {
    var ret = parseJson(HttpQuery('https://api.huobi.pro/v1/common/symbols'))
    if (ret && ret.status === 'ok') {
        return ret.data
    } else {
        return null
    }
}

function getTicker(ex) {
    var currency = getCurreny(ex)
    if (_cacheTicker[currency] && Unix() - _cacheTicker[currency].UpdatedAt < TICKER_EXPIRE_TIME) {
        return _cacheTicker[currency]
    }
    var sym = currency.replace('_', '').toLocaleLowerCase()
    var ret = parseJson(HttpQuery('https://api.huobi.pro/market/detail/merged?symbol=' + sym))
    if (ret && ret.status === 'ok') {
        _cacheTicker[currency] = _.extend({ UpdatedAt: Unix() }, ret.tick)
        return ret.data
    } else {
        return null
    }
}

function getCurreny(ex) {
    var currency = null
    if (typeof(ex) === 'object') {
        return ex.GetCurrency()
    } else {
        return ex
    }
}

function getCoin(ex) {
    var currency = getCurreny(ex)
    var currencyAry = _.map(currency.split('_'), function(sym) { return sym.toLocaleLowerCase() })
    return _.find(_symbols, function(coin) {
        return currencyAry[0] === coin['base-currency'] && currencyAry[1] === coin['quote-currency']
    })
}

$.getSymbols = getSymbols

$.getAmountPrecision = function (ex) {
    var coin = getCoin(ex)
    if (coin) {
        return coin['amount-precision']
    }
    return 0
}

$.getPricePrecision = function(ex) {
    var coin = getCoin(ex)
    if (coin) {
        return coin['price-precision']
    }
    return 0
}

$.getMinOrderAmount = function(ex, price) {
    var coin = getCoin(ex)
    if (coin) {
        price = price || _C(getTicker, ex).close
        return +(new Decimal(coin['min-order-value']).mul(1.1).div(price).toFixed($.getAmountPrecision(ex), Decimal.ROUND_CEIL))
    }
    return 0
}

$.getMaxOrderAmount = function(ex) {
    var coin = getCoin(ex)
    if (coin) {
        return coin['max-order-amt']
    }
    return 0
}

$.getValuePrecision = function(ex) {
    var coin = getCoin(ex)
    if (coin) {
        return coin['value-precision']
    }
    return 0
}

$.getMinValue = function(ex) {
    var coin = getCoin(ex)
    if (coin) {
        return coin['min-order-value']
    }
    return 0
}

Published by 一拳男孩 on the FMZ strategy square · last modified 2019-07-31. 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/Huobi-Precision.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