From c086df915bf9884fe514a00b6c6d04f36321e1e3 Mon Sep 17 00:00:00 2001 From: jloup Date: Thu, 21 Jun 2018 09:32:48 +0200 Subject: Set poloniex client timeout to 20 seconds. --- Gopkg.lock | 2 +- api/market_config.go | 4 ++-- markets/poloniex.go | 12 +++++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 0123e1c..e1c76dd 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -161,7 +161,7 @@ branch = "master" name = "github.com/jloup/poloniex" packages = ["."] - revision = "72d53259a0b28f1778281d7a9f7b20469d8c0171" + revision = "8b2cfdf0fc69046e2b4cb10f6ba1fdaa45814d65" [[projects]] branch = "master" diff --git a/api/market_config.go b/api/market_config.go index c7e2e15..155da1a 100644 --- a/api/market_config.go +++ b/api/market_config.go @@ -80,7 +80,7 @@ func (q TestMarketCredentialsQuery) Run() (interface{}, *Error) { } resultErr := CallExternalService(fmt.Sprintf("'%s' TestCredentials", q.In.Market), EXTERNAL_SERVICE_TIMEOUT_SECONDS*time.Second, func() error { - err := Poloniex.TestCredentials(config.Config["key"], config.Config["secret"]) + err := Poloniex.TestCredentials(config.Config["key"], config.Config["secret"], EXTERNAL_SERVICE_TIMEOUT_SECONDS) if utils.ErrIs(err, markets.InvalidCredentials) { return &Error{InvalidMarketCredentials, "wrong market credentials", fmt.Errorf("wrong '%v' market credentials", q.In.Market)} @@ -152,7 +152,7 @@ func (q UpdateMarketConfigQuery) Run() (interface{}, *Error) { } resultErr := CallExternalService(fmt.Sprintf("'%s' TestCredentials", q.In.Market), EXTERNAL_SERVICE_TIMEOUT_SECONDS*time.Second, func() error { - err := Poloniex.TestCredentials(marketConfig.Config["key"], marketConfig.Config["secret"]) + err := Poloniex.TestCredentials(marketConfig.Config["key"], marketConfig.Config["secret"], EXTERNAL_SERVICE_TIMEOUT_SECONDS) if utils.ErrIs(err, markets.InvalidCredentials) { return &Error{InvalidMarketCredentials, "wrong market credentials", fmt.Errorf("wrong '%v' market credentials", q.In.Market)} diff --git a/markets/poloniex.go b/markets/poloniex.go index cadc829..595d5a4 100644 --- a/markets/poloniex.go +++ b/markets/poloniex.go @@ -16,6 +16,8 @@ var ( IPRestricted = utils.InitFlag(&ErrorFlagCounter, "IPRestricted") ) +const defaultTimeout = 10 + func poloniexInvalidCredentialsError(err error) bool { if err == nil { return false @@ -43,7 +45,7 @@ type Poloniex struct { } func NewPoloniex() *Poloniex { - client, _ := poloniex.NewClient("", "") + client, _ := poloniex.NewClient("", "", defaultTimeout) return &Poloniex{ TickerCache: make(map[string]CurrencyPair), @@ -52,8 +54,8 @@ func NewPoloniex() *Poloniex { } } -func (p *Poloniex) TestCredentials(apiKey, apiSecret string) error { - client, _ := poloniex.NewClient(apiKey, apiSecret) +func (p *Poloniex) TestCredentials(apiKey, apiSecret string, timeout int32) error { + client, _ := poloniex.NewClient(apiKey, apiSecret, timeout) _, err := client.TradeReturnDepositAdresses() @@ -68,8 +70,8 @@ func (p *Poloniex) TestCredentials(apiKey, apiSecret string) error { return err } -func (p *Poloniex) GetBalance(apiKey, apiSecret string) (Summary, error) { - client, _ := poloniex.NewClient(apiKey, apiSecret) +func (p *Poloniex) GetBalance(apiKey, apiSecret string, timeout int32) (Summary, error) { + client, _ := poloniex.NewClient(apiKey, apiSecret, timeout) var summary Summary accounts, err := client.TradeReturnAvailableAccountBalances() -- cgit v1.2.3