goex icon indicating copy to clipboard operation
goex copied to clipboard

http代理优化建议

Open silver-brother opened this issue 3 years ago • 1 comments

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)

silver-brother avatar Jun 15 '21 14:06 silver-brother

因为ws构建和rest构建逻辑目前是完全不一样的,我考虑下怎么优化吧

nntaoli avatar Jun 16 '21 14:06 nntaoli