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 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() {