Understanding Zhang and Coin Calculations on OKEx
OKEx uses two measurement units for contract trading:
- Coin (币): Represents the actual cryptocurrency amount
- Zhang (张): Represents contract units (1 Zhang = contract multiplier × coin value)
This guide explains how to:
- Convert coin amounts to Zhang units
- Convert Zhang units back to coin amounts
- Use OKEx's API for automated calculations
Conversion Formulas Explained
Coin to Zhang Conversion
function AmountToZhang(currency, px, sz) {
let instId = currency.replace("_","-")+"-SWAP";
let str = "https://www.okx.com/join/BLOCKSTARapi/v5/public/convert-contract-coin?instId="+instId+"&px="+px+"&sz="+sz;
let ret = JSON.parse(HttpQuery(str));
return ret.data[0].sz;
}Zhang to Coin Conversion
function ZhangToAmount(currency, px, sz) {
let instId = currency.replace("_","-")+"-SWAP";
let str = "https://www.okx.com/join/BLOCKSTARapi/v5/public/convert-contract-coin?type=2&instId="+instId+"&px="+px+"&sz="+sz;
let ret = JSON.parse(HttpQuery(str));
return ret.data[0].sz;
}Key Factors Affecting Conversion
- Contract Multiplier: Varies by trading pair
- Current Price: Affects value calculations
- Leverage: Modifies position sizing (note API returns base values)
👉 Master OKEx contract trading with our advanced guide
Practical Examples
| Trading Pair | 1 Zhang Equals | Conversion Example |
|---|---|---|
| BTC-USDT-SWAP | 0.01 BTC | 100 Zhang = 1 BTC |
| ETH-USDT-SWAP | 0.1 ETH | 10 Zhang = 1 ETH |
| BCH-USDT-SWAP | 10 BCH | 1 Zhang = 10 BCH |
API Implementation Guide
To implement automated conversions:
- Format trading pairs correctly (replace "_" with "-")
- Include "-SWAP" suffix for swap contracts
- Specify conversion type (1 for coin→zhang, 2 for zhang→coin)
// Example implementation
function main() {
let currency = "ETH_USDT";
let price = 3500;
let amount = 1;
let zhang = AmountToZhang(currency, price, amount);
let coins = ZhangToAmount(currency, price, 1);
Log(`${amount} ${currency} = ${zhang} Zhang`);
Log(`1 Zhang = ${coins} ${currency}`);
}Frequently Asked Questions
What determines the Zhang-to-Coin ratio?
The contract multiplier set by OKEx for each trading pair. Different cryptocurrencies have different multipliers based on their volatility and market size.
Why does leverage affect my position size?
While the base conversion remains constant, leverage modifies your effective position size. A 20x leverage position would require 20x less capital for the same contract size.
How often do conversion rates change?
The Zhang-to-Coin ratio remains constant per contract, but the USD value changes with market price fluctuations.
Can I use these conversions for spot trading?
No, Zhang units only apply to derivative contracts (futures and perpetual swaps).
Where can I find official conversion rates?
👉 OKEx's official API documentation provides updated contract specifications for all trading pairs.
Advanced Conversion Considerations
- Margin Calculations: Remember to account for leverage in final position sizing
- Cross vs Isolated: Margin mode affects how conversions translate to position risk