[add] 新增币安的代理
This commit is contained in:
parent
8f98cf650e
commit
ae47d3d3b7
|
@ -42,6 +42,7 @@ type ExchangeSession struct {
|
||||||
Key string `json:"key,omitempty" yaml:"key,omitempty"`
|
Key string `json:"key,omitempty" yaml:"key,omitempty"`
|
||||||
Secret string `json:"secret,omitempty" yaml:"secret,omitempty"`
|
Secret string `json:"secret,omitempty" yaml:"secret,omitempty"`
|
||||||
Passphrase string `json:"passphrase,omitempty" yaml:"passphrase,omitempty"`
|
Passphrase string `json:"passphrase,omitempty" yaml:"passphrase,omitempty"`
|
||||||
|
Proxy string `json:"proxy,omitempty" yaml:"proxy,omitempty"`
|
||||||
SubAccount string `json:"subAccount,omitempty" yaml:"subAccount,omitempty"`
|
SubAccount string `json:"subAccount,omitempty" yaml:"subAccount,omitempty"`
|
||||||
|
|
||||||
// Withdrawal is used for enabling withdrawal functions
|
// Withdrawal is used for enabling withdrawal functions
|
||||||
|
@ -793,7 +794,7 @@ func (session *ExchangeSession) newBasicPrivateExchange(exchangeName types.Excha
|
||||||
var err error
|
var err error
|
||||||
var exMinimal types.ExchangeMinimal
|
var exMinimal types.ExchangeMinimal
|
||||||
if session.Key != "" && session.Secret != "" {
|
if session.Key != "" && session.Secret != "" {
|
||||||
exMinimal, err = exchange2.New(exchangeName, session.Key, session.Secret, session.Passphrase)
|
exMinimal, err = exchange2.New(exchangeName, session.Key, session.Secret, session.Passphrase, session.Proxy)
|
||||||
} else {
|
} else {
|
||||||
exMinimal, err = exchange2.NewWithEnvVarPrefix(exchangeName, session.EnvVarPrefix)
|
exMinimal, err = exchange2.NewWithEnvVarPrefix(exchangeName, session.EnvVarPrefix)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package binance
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -90,7 +92,7 @@ type Exchange struct {
|
||||||
|
|
||||||
var timeSetterOnce sync.Once
|
var timeSetterOnce sync.Once
|
||||||
|
|
||||||
func New(key, secret string) *Exchange {
|
func New(key, secret, proxy string) *Exchange {
|
||||||
if util.IsPaperTrade() {
|
if util.IsPaperTrade() {
|
||||||
binance.UseTestnet = true
|
binance.UseTestnet = true
|
||||||
}
|
}
|
||||||
|
@ -109,6 +111,19 @@ func New(key, secret string) *Exchange {
|
||||||
client2 := binanceapi.NewClient(client.BaseURL)
|
client2 := binanceapi.NewClient(client.BaseURL)
|
||||||
futuresClient2 := binanceapi.NewFuturesRestClient(futuresClient.BaseURL)
|
futuresClient2 := binanceapi.NewFuturesRestClient(futuresClient.BaseURL)
|
||||||
|
|
||||||
|
if proxy != "" {
|
||||||
|
proxyURL, err := url.Parse(proxy)
|
||||||
|
if err == nil {
|
||||||
|
proxyTransport := &http.Transport{
|
||||||
|
Proxy: http.ProxyURL(proxyURL),
|
||||||
|
}
|
||||||
|
client.HTTPClient.Transport = proxyTransport
|
||||||
|
futuresClient.HTTPClient.Transport = proxyTransport
|
||||||
|
client2.HttpClient.Transport = proxyTransport
|
||||||
|
futuresClient2.HttpClient.Transport = proxyTransport
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ex := &Exchange{
|
ex := &Exchange{
|
||||||
key: key,
|
key: key,
|
||||||
secret: secret,
|
secret: secret,
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewPublic(exchangeName types.ExchangeName) (types.Exchange, error) {
|
func NewPublic(exchangeName types.ExchangeName) (types.Exchange, error) {
|
||||||
exMinimal, err := New(exchangeName, "", "", "")
|
exMinimal, err := New(exchangeName, "", "", "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,11 @@ func NewPublic(exchangeName types.ExchangeName) (types.Exchange, error) {
|
||||||
return nil, fmt.Errorf("exchange %T does not implement types.Exchange", exMinimal)
|
return nil, fmt.Errorf("exchange %T does not implement types.Exchange", exMinimal)
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(n types.ExchangeName, key, secret, passphrase string) (types.ExchangeMinimal, error) {
|
func New(n types.ExchangeName, key, secret, passphrase, proxy string) (types.ExchangeMinimal, error) {
|
||||||
switch n {
|
switch n {
|
||||||
|
|
||||||
case types.ExchangeBinance:
|
case types.ExchangeBinance:
|
||||||
return binance.New(key, secret), nil
|
return binance.New(key, secret, proxy), nil
|
||||||
|
|
||||||
case types.ExchangeMax:
|
case types.ExchangeMax:
|
||||||
return max.New(key, secret), nil
|
return max.New(key, secret), nil
|
||||||
|
@ -70,5 +70,6 @@ func NewWithEnvVarPrefix(n types.ExchangeName, varPrefix string) (types.Exchange
|
||||||
}
|
}
|
||||||
|
|
||||||
passphrase := os.Getenv(varPrefix + "_API_PASSPHRASE")
|
passphrase := os.Getenv(varPrefix + "_API_PASSPHRASE")
|
||||||
return New(n, key, secret, passphrase)
|
proxy := os.Getenv(varPrefix + "_PROXY")
|
||||||
|
return New(n, key, secret, passphrase, proxy)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user