cryptofx

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

crypto-fx-converter

Zero-dependency Python (decimal.Decimal), Go (cryptofx), and JavaScript (ESM) library + CLI for crypto-to-multi-fiat (USD, EUR, GBP, CNY, CAD, AUD, JPY) conversion, OTC / P2P USDT spread calculation, and multi-chain USDT withdrawal fee basis-point comparison.

Live Interactive Converters & References

Installation & Usage

1. Python (pypi.org)
pip install crypto-fx-converter
from crypto_fx_converter import (
    convert_crypto_fiat,
    analyze_p2p_spread,
    compare_usdt_network_fees,
)

# 1) Convert 0.25 BTC at $96,400 into EUR (including 0.10% spot fee & 20% permanent rebate)
quote = convert_crypto_fiat(
    quantity="0.25",
    usd_price="96400",
    fiat_code="EUR",
    fx_rate_per_usd="0.9350",
    trading_fee_rate="0.001",
    rebate_rate="0.20",
    symbol="BTC",
)
print(f"{quote.usd_value} USD -> {quote.fiat_value} EUR (net {quote.net_fiat_after_fee} EUR)")

# 2) Measure P2P USDT quote spread vs. mid-market USD/CNY (e.g. 7.31 vs 7.245)
spread = analyze_p2p_spread(mid_fx_rate="7.2450", p2p_quote_rate="7.3100", fiat_code="CNY")
print(f"P2P Spread: +{spread.spread_pct}% ({spread.spread_bps} bps)")

# 3) Compare multi-chain withdrawal fees on a 500 USDT transfer
for row in compare_usdt_network_fees("500"):
    print(f"{row.network:10s} fee={row.fee_usdt} USDT ({row.cost_bps} bps)")

CLI (crypto-fx):

crypto-fx --symbol BTC --qty 0.5 --usd 96400 --fiat EUR --transfer-usdt 500
2. Go (pkg.go.dev)
go get github.com/dalangdalang934/crypto-fx-converter@latest
package main

import (
	"fmt"
	cryptofx "github.com/dalangdalang934/crypto-fx-converter"
)

func main() {
	q, _ := cryptofx.ConvertCryptoFiat("BTC", 0.5, 96400, "EUR", 0.935, 0.001, 0.20)
	fmt.Printf("USD: %.2f | EUR: %.2f (net %.2f)\n", q.USDValue, q.FiatValue, q.NetFiatAfterFee)
}
3. JavaScript (ESM)
import { convertCryptoFiat, analyzeP2PSpread, compareUsdtNetworkFees } from './src/index.mjs';

console.log(convertCryptoFiat({ symbol: 'ETH', quantity: 2, usdPrice: 3650, fiatCode: 'GBP' }));
console.log(analyzeP2PSpread(7.245, 7.31, 'CNY'));
console.log(compareUsdtNetworkFees(250));

Why P2P USDT Quotes Differ from Mid-Market FX

Bank and interbank FX feeds quote USD/CNY or USD/EUR on wire settlement, whereas peer-to-peer (P2P / C2C) stablecoin desks price local fiat liquidity, T+1 withdrawal protections, and payment-rail friction:

P2P Spread (%) = (Quote_P2P − FX_Mid) / FX_Mid × 100%
Net Effective Spot Fee = Base_Fee × (1 − BNB_Discount) × (1 − Referral_Rebate)

With a standard 0.10% spot fee, stacking a 25% BNB deduction and a 20% permanent referral rebate reduces effective spot execution cost to 0.06% (6 bps)—often smaller than a single basis-point swing in the P2P FX spread. See the full Binance Fee & Rebate Breakdown (中文手续费说明) and TRC20 vs ERC20 vs BEP20 Comparison.

License

MIT © HoldWins

Documentation

Overview

Package cryptofx provides zero-dependency crypto-to-fiat conversion, OTC/P2P USDT spread calculation, and multi-chain stablecoin withdrawal fee basis-point comparison.

Live interactive converters & fee references:

Index

Constants

This section is empty.

Variables

View Source
var DefaultUSDTNetworkFees = map[string]float64{
	"opBNB":    0.00,
	"BEP20":    0.01,
	"Polygon":  0.035,
	"Arbitrum": 0.10,
	"Optimism": 0.10,
	"Solana":   0.22,
	"ERC20":    0.60,
	"TRC20":    2.00,
}

DefaultUSDTNetworkFees lists reference USDT withdrawal fees across major chains.

View Source
var ReferenceFiatPerUSD = map[string]float64{
	"USD": 1.0,
	"EUR": 0.9350,
	"GBP": 0.7880,
	"CNY": 7.2450,
	"CAD": 1.4020,
	"AUD": 1.5380,
	"JPY": 151.40,
	"HKD": 7.7820,
	"SGD": 1.3440,
}

ReferenceFiatPerUSD provides baseline mid-market FX rates per 1 USD.

Functions

This section is empty.

Types

type ConversionQuote

type ConversionQuote struct {
	Symbol          string
	Quantity        float64
	USDPrice        float64
	USDValue        float64
	FiatCode        string
	FXRatePerUSD    float64
	FiatValue       float64
	NetFiatAfterFee float64
}

ConversionQuote represents a crypto-to-USD and target-fiat valuation.

func ConvertCryptoFiat

func ConvertCryptoFiat(symbol string, quantity, usdPrice float64, fiatCode string, fxRatePerUSD, tradingFeeRate, rebateRate float64) (ConversionQuote, error)

ConvertCryptoFiat converts an asset quantity into USD and target fiat net of trading fees and rebates.

type NetworkFeeRow

type NetworkFeeRow struct {
	Network         string
	FeeUSDT         float64
	NetReceivedUSDT float64
	CostBps         float64
}

NetworkFeeRow ranks a chain's fixed withdrawal fee as basis points of transfer size.

func CompareUSDTNetworkFees

func CompareUSDTNetworkFees(transferUSDT float64, customFees map[string]float64) ([]NetworkFeeRow, error)

CompareUSDTNetworkFees returns chains sorted from lowest to highest withdrawal cost in basis points.

type P2PSpreadQuote

type P2PSpreadQuote struct {
	FiatCode                string
	MidFXRate               float64
	P2PQuoteRate            float64
	SpreadPerUSDT           float64
	SpreadPct               float64
	SpreadBps               float64
	USDTReceivedFor1000Fiat float64
}

P2PSpreadQuote quantifies P2P/OTC USDT quote premium or discount vs mid-market FX.

func AnalyzeP2PSpread

func AnalyzeP2PSpread(midFXRate, p2pQuoteRate float64, fiatCode string) (P2PSpreadQuote, error)

AnalyzeP2PSpread computes the percentage and basis-point spread of a P2P USDT quote over mid-market FX.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL