add binance paper trade endpoint

This commit is contained in:
zenix 2022-02-25 12:30:40 +09:00
parent bc0429c0fd
commit 36a746d415

View File

@ -29,9 +29,13 @@ import (
const BNB = "BNB" const BNB = "BNB"
const BinanceUSBaseURL = "https://api.binance.us" const BinanceUSBaseURL = "https://api.binance.us"
const BinanceTestBaseURL = "https://testnet.binance.vision"
const BinanceUSWebSocketURL = "wss://stream.binance.us:9443" const BinanceUSWebSocketURL = "wss://stream.binance.us:9443"
const WebSocketURL = "wss://stream.binance.com: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 FuturesWebSocketURL = "wss://fstream.binance.com"
const FuturesWebSocketTestURL = "wss://stream.binancefuture.com"
// 5 per second and a 2 initial bucket // 5 per second and a 2 initial bucket
var orderLimiter = rate.NewLimiter(5, 2) var orderLimiter = rate.NewLimiter(5, 2)
@ -56,6 +60,11 @@ func isBinanceUs() bool {
return err == nil && v return err == nil && v
} }
func paperTrade() bool {
v, err := strconv.ParseBool(os.Getenv("PAPER_TRADE"))
return err == nil && v
}
type Exchange struct { type Exchange struct {
types.MarginSettings types.MarginSettings
types.FuturesSettings types.FuturesSettings
@ -80,6 +89,11 @@ func New(key, secret string) *Exchange {
client.BaseURL = BinanceUSBaseURL client.BaseURL = BinanceUSBaseURL
} }
if paperTrade() {
client.BaseURL = BinanceTestBaseURL
futuresClient.BaseURL = FutureTestBaseURL
}
var err error var err error
if len(key) > 0 && len(secret) > 0 { if len(key) > 0 && len(secret) > 0 {
timeSetter.Do(func() { timeSetter.Do(func() {