goex
goex copied to clipboard
http代理优化建议
spot proxy可以通过
&builder.HttpClientConfig{
HttpTimeout: 3 * time.Second,
Proxy: proxy,
MaxIdleConns: 10,
}
去设定,但是spot_ws 代码中写死只能通过 环境变量去获取,
func NewSpotWs() *SpotWs {
spotWs := &SpotWs{}
logger.Debugf("proxy url: %s", os.Getenv("HTTPS_PROXY"))
spotWs.wsBuilder = goex.NewWsBuilder().
WsUrl("wss://stream.binance.com:9443/stream?streams=depth/miniTicker/ticker/trade").
ProxyUrl(os.Getenv("HTTPS_PROXY")).
ProtoHandleFunc(spotWs.handle).AutoReconnect()
spotWs.reqId = 1
return spotWs
}
这里硬编码可以优化一下,不然本地调试 spot和spot_ws需要创建两个实例,如果统一的代理方式,直接可以使用一个实例
builder.NewAPIBuilder2(&builder.HttpClientConfig{
HttpTimeout: 3 * time.Second,
Proxy: proxy,
MaxIdleConns: 10,
}).APIKey(g.access).APISecretkey(g.secret).ApiPassphrase(g.passphrase)
因为ws构建和rest构建逻辑目前是完全不一样的,我考虑下怎么优化吧