Add Binance testnet API integration#7
Conversation
- Add TestnetWebSocket for testnet market streams (wss://stream.testnet.binance.vision:9443) - Add TestnetSpot.dispose() for proper resource cleanup - Add comprehensive market data endpoints: - ping(), getExchangeInfo() with filters - getUIKlines(), getTradingDayTicker() - getRollingWindowTicker() for rolling window stats - Proper weight tracking for all endpoints - Add advanced order types for testnet trading: - OCO (One-Cancels-Other) orders - OTO (One-Triggers-Other) orders - OTOCO (One-Triggers-OCO) orders - Cancel-Replace operations - Add testnet failover endpoints in BinanceBase (api1.testnet.binance.vision) - Add Demo Trading API support as alternative testnet: - DemoSpot, DemoTrading, DemoMarket classes - DemoFuturesUsd for futures demo trading - DemoWebSocket (wss://demo-stream.binance.com) - Base URL: https://demo-api.binance.com - Add Binance.demo() factory constructor - Update testnet example with new features documentation
Add comprehensive COIN-M (inverse) futures testnet integration: - TestnetFuturesCoinM class for COIN-margined delivery futures - TestnetFuturesCoinMMarket with full market data endpoints: - ping, getServerTime, getExchangeInfo - getOrderBook, getRecentTrades, getHistoricalTrades, getAggTrades - getKlines, getContinuousKlines, getIndexPriceKlines, getMarkPriceKlines - getPremiumIndex, getFundingRate, get24HrTicker - getTickerPrice, getBookTicker, getOpenInterest, getOpenInterestHist - TestnetFuturesCoinMTrading with all trading operations: - placeOrder, placeBatchOrders - getOrder, cancelOrder, cancelAllOrders, cancelBatchOrders - setAutoCancel, getCurrentOpenOrder, getOpenOrders, getAllOrders - getBalance, getAccountInfo - changeInitialLeverage, changeMarginType - modifyIsolatedPositionMargin, getPositionMarginHistory - getPositionRisk, getUserTrades, getIncomeHistory - getLeverageBracket, changePositionMode, getPositionMode - getForceOrders, getAdlQuantile, getCommissionRate - TestnetFuturesCoinMUserDataStream for user data streaming - Updated example with COIN-M futures documentation COIN-M futures are settled in cryptocurrency (BTC, ETH) rather than USDT, using /dapi/ endpoints on testnet.binancefuture.com.
Major fixes based on comprehensive code review: Security Fixes: - Make API credentials private (_apiKey, _apiSecret) to prevent exposure - Remove public accessors that could leak sensitive data Reliability Fixes: - Add thread-safe locking to TokenBucket rate limiter - Add server time sync locking to prevent race conditions - Add bounded buffer (10k messages) to WebSocket to prevent memory leaks - Fix JSON parsing with proper FormatException handling for WAF/CDN errors - Complete dispose() method to clean up all resources Financial Precision Fixes: - Change order quantity/price from double to String for exact precision - Prevents floating-point rounding errors in financial calculations Parameter Validation: - Add comprehensive order parameter validation (side, type, required fields) - Validate LIMIT orders require price and timeInForce - Validate STOP orders require stopPrice - Normalize inputs (uppercase symbols, sides, types) Code Quality: - Remove dead code (Awesome class) - Improve error messages for debugging These fixes address CRITICAL and HIGH severity issues from: - Principal Test Engineer review (15 critical, 24 high) - Principal Developer #1 review (5 critical, 10 high) - Principal Developer #2 review (8 critical, 6 high)
Critical fix for financial precision issues across all trading endpoints: - FuturesTrading.placeOrder: quantity, price, stopPrice now String - FuturesTrading.changePositionMargin: amount now String - MarginTrading.marginBorrow/marginRepay: amount now String - MarginTrading.placeMarginOrder: quantity, price now String - TestnetTrading: placeOrder, testOrder, cancelReplace, OCO, OTO, OTOCO - TestnetFuturesUsdTrading.placeOrder: all financial params String - TestnetFuturesCoinMTrading.placeOrder: all financial params String - DemoTrading.placeOrder/testOrder: all financial params String - DemoFuturesUsdTrading.placeOrder: all financial params String Added input validation for side/type parameters with helpful error messages. Added isOrder flag for proper rate limiting on order endpoints.
Fixes the remaining precision issue in COIN-M futures margin modification endpoint. The amount parameter now uses String instead of double to prevent precision loss in cryptocurrency margin operations.
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThis pull request substantially expands testnet and demo trading capabilities, introduces demo endpoints (DemoSpot, DemoFutures), adds WebSocket support to testnet environments, refactors credential handling with private fields and thread-safe locking, converts numeric parameter types from double to String across trading methods, and enhances error handling and buffer management. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Poem
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (9)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.