Precision
Precision and Amount Handling
Token Decimal Systems
Overview
The Opinion CLOB SDK interacts with token standards employing distinct decimal precision schemes. Precision handling accuracy is critical for preventing calculation errors and fund loss.
USDT (Collateral Token)
Decimal Specification: 18 (ERC-20 standard)
Conversion Implementation:
# Human-readable: 100 USDT
usdt_amount = 100
# Contract representation
amount_micro_usdt = usdt_amount * 10**18
# Reverse transformation
usdt_amount = amount_micro_usdt / 10**18 # 100.0 USDTConversion Table:
1 USDT
1 Γ 10^18
10 USDT
10 Γ 10^18
0.5 USDT
0.5 Γ 10^18
100.50 USDT
100.5 Γ 10^18
0.000001 USDT
10^-18 (minimum unit)
Outcome Tokens (YES/NO)
Decimal Specification: 18 (ERC-1155 standard, Wei base unit)
Conversion Implementation:
Conversion Table:
1 YES
1_000_000_000_000_000_000
1 Γ 10^18
10 YES
10_000_000_000_000_000_000
10 Γ 10^18
0.1 YES
100_000_000_000_000_000
0.1 Γ 10^18
0.000000000000000001 YES
1
10^-18 (Wei, minimum unit)
Price Representation
Format Specification
Prices encode implied probability as decimal strings, representing the USDT cost per outcome token (normalized to $1.00 payout).
Type Constraints:
Data Type:
strValue Range:
[0.01, 0.99](1% to 99% implied probability)Precision: Maximum 4 decimal places (0.0001 tick size)
Price Interpretation Table:
"0.01"
1%
$0.01
$1.00
$0.99 (9900% ROI)
"0.50"
50%
$0.50
$1.00
$0.50 (100% ROI)
"0.652"
65.2%
$0.652
$1.00
$0.348 (53.3% ROI)
"0.99"
99%
$0.99
$1.00
$0.01 (1.01% ROI)
Order Amount Specifications
Quote Token Amount (makerAmountInQuoteToken)
Specifies the USDT amount to spend (BUY orders) or receive (SELL orders).
BUY Order Calculation:
SELL Order Calculation:
Implementation:
Note: The SDK handles conversion to Wei internally. Provide amounts in human-readable decimal format.
Base Token Amount (makerAmountInBaseToken)
Specifies the exact number of outcome tokens to buy or sell.
BUY Order Calculation:
SELL Order Calculation:
Implementation:
Smart Contract Amount Specifications
Split Operation
Converts USDT collateral into outcome token pairs (YES + NO).
Decimal Conversion:
Merge Operation
Converts outcome token pairs (YES + NO) back into USDT collateral.
Decimal Conversion:
Redeem Operation
Claims winnings from resolved markets.
Floating Point Precision Issues
Problem: IEEE 754 Rounding Errors
Python's float type implements IEEE 754 binary floating-point arithmetic, which cannot precisely represent all decimal fractions.
Problematic Pattern:
Correct Pattern:
Best Practices for Precision
Amount Formatting
Display Formatting
Common Precision Errors
Error 1: Incorrect Decimal Places
Error 2: Float to Wei Conversion
Error 3: Price Outside Valid Range
Position Size Calculations
Total Position Value
Profit and Loss Calculation
Break-even Analysis
API Response Amount Parsing
Parse Balance Response
Next Steps
API Reference - Models - Data type specifications
Last updated