From 36a746d415c2b1c609c97698baeaafce9047b9e4 Mon Sep 17 00:00:00 2001 From: zenix Date: Fri, 25 Feb 2022 12:30:40 +0900 Subject: [PATCH] add binance paper trade endpoint --- pkg/exchange/binance/exchange.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/exchange/binance/exchange.go b/pkg/exchange/binance/exchange.go index 204871045..71b38f34a 100644 --- a/pkg/exchange/binance/exchange.go +++ b/pkg/exchange/binance/exchange.go @@ -29,9 +29,13 @@ import ( const BNB = "BNB" const BinanceUSBaseURL = "https://api.binance.us" +const BinanceTestBaseURL = "https://testnet.binance.vision" const BinanceUSWebSocketURL = "wss://stream.binance.us:9443" const WebSocketURL = "wss://stream.binance.com:9443" +const WebSocketTestURL = "wss://testnet.binance.vision" +const FutureTestBaseURL = "https://testnet.binancefuture.com" const FuturesWebSocketURL = "wss://fstream.binance.com" +const FuturesWebSocketTestURL = "wss://stream.binancefuture.com" // 5 per second and a 2 initial bucket var orderLimiter = rate.NewLimiter(5, 2) @@ -56,6 +60,11 @@ func isBinanceUs() bool { return err == nil && v } +func paperTrade() bool { + v, err := strconv.ParseBool(os.Getenv("PAPER_TRADE")) + return err == nil && v +} + type Exchange struct { types.MarginSettings types.FuturesSettings @@ -80,6 +89,11 @@ func New(key, secret string) *Exchange { client.BaseURL = BinanceUSBaseURL } + if paperTrade() { + client.BaseURL = BinanceTestBaseURL + futuresClient.BaseURL = FutureTestBaseURL + } + var err error if len(key) > 0 && len(secret) > 0 { timeSetter.Do(func() {