diff options
author | jloup <jean-loup.jamet@trainline.com> | 2018-06-21 09:32:48 +0200 |
---|---|---|
committer | jloup <jean-loup.jamet@trainline.com> | 2018-06-21 09:33:10 +0200 |
commit | c086df915bf9884fe514a00b6c6d04f36321e1e3 (patch) | |
tree | 874017c71c0c7801cf9b42192cefbe0dd316dacf | |
parent | f7521f251456fea091d1eb950fd55a7cd4257c65 (diff) | |
download | Front-c086df915bf9884fe514a00b6c6d04f36321e1e3.tar.gz Front-c086df915bf9884fe514a00b6c6d04f36321e1e3.tar.zst Front-c086df915bf9884fe514a00b6c6d04f36321e1e3.zip |
Set poloniex client timeout to 20 seconds.v0.0.21
-rw-r--r-- | Gopkg.lock | 2 | ||||
-rw-r--r-- | api/market_config.go | 4 | ||||
-rw-r--r-- | markets/poloniex.go | 12 |
3 files changed, 10 insertions, 8 deletions
@@ -161,7 +161,7 @@ | |||
161 | branch = "master" | 161 | branch = "master" |
162 | name = "github.com/jloup/poloniex" | 162 | name = "github.com/jloup/poloniex" |
163 | packages = ["."] | 163 | packages = ["."] |
164 | revision = "72d53259a0b28f1778281d7a9f7b20469d8c0171" | 164 | revision = "8b2cfdf0fc69046e2b4cb10f6ba1fdaa45814d65" |
165 | 165 | ||
166 | [[projects]] | 166 | [[projects]] |
167 | branch = "master" | 167 | 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) { | |||
80 | } | 80 | } |
81 | 81 | ||
82 | resultErr := CallExternalService(fmt.Sprintf("'%s' TestCredentials", q.In.Market), EXTERNAL_SERVICE_TIMEOUT_SECONDS*time.Second, func() error { | 82 | resultErr := CallExternalService(fmt.Sprintf("'%s' TestCredentials", q.In.Market), EXTERNAL_SERVICE_TIMEOUT_SECONDS*time.Second, func() error { |
83 | err := Poloniex.TestCredentials(config.Config["key"], config.Config["secret"]) | 83 | err := Poloniex.TestCredentials(config.Config["key"], config.Config["secret"], EXTERNAL_SERVICE_TIMEOUT_SECONDS) |
84 | 84 | ||
85 | if utils.ErrIs(err, markets.InvalidCredentials) { | 85 | if utils.ErrIs(err, markets.InvalidCredentials) { |
86 | return &Error{InvalidMarketCredentials, "wrong market credentials", fmt.Errorf("wrong '%v' market credentials", q.In.Market)} | 86 | 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) { | |||
152 | } | 152 | } |
153 | 153 | ||
154 | resultErr := CallExternalService(fmt.Sprintf("'%s' TestCredentials", q.In.Market), EXTERNAL_SERVICE_TIMEOUT_SECONDS*time.Second, func() error { | 154 | resultErr := CallExternalService(fmt.Sprintf("'%s' TestCredentials", q.In.Market), EXTERNAL_SERVICE_TIMEOUT_SECONDS*time.Second, func() error { |
155 | err := Poloniex.TestCredentials(marketConfig.Config["key"], marketConfig.Config["secret"]) | 155 | err := Poloniex.TestCredentials(marketConfig.Config["key"], marketConfig.Config["secret"], EXTERNAL_SERVICE_TIMEOUT_SECONDS) |
156 | 156 | ||
157 | if utils.ErrIs(err, markets.InvalidCredentials) { | 157 | if utils.ErrIs(err, markets.InvalidCredentials) { |
158 | return &Error{InvalidMarketCredentials, "wrong market credentials", fmt.Errorf("wrong '%v' market credentials", q.In.Market)} | 158 | 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 ( | |||
16 | IPRestricted = utils.InitFlag(&ErrorFlagCounter, "IPRestricted") | 16 | IPRestricted = utils.InitFlag(&ErrorFlagCounter, "IPRestricted") |
17 | ) | 17 | ) |
18 | 18 | ||
19 | const defaultTimeout = 10 | ||
20 | |||
19 | func poloniexInvalidCredentialsError(err error) bool { | 21 | func poloniexInvalidCredentialsError(err error) bool { |
20 | if err == nil { | 22 | if err == nil { |
21 | return false | 23 | return false |
@@ -43,7 +45,7 @@ type Poloniex struct { | |||
43 | } | 45 | } |
44 | 46 | ||
45 | func NewPoloniex() *Poloniex { | 47 | func NewPoloniex() *Poloniex { |
46 | client, _ := poloniex.NewClient("", "") | 48 | client, _ := poloniex.NewClient("", "", defaultTimeout) |
47 | 49 | ||
48 | return &Poloniex{ | 50 | return &Poloniex{ |
49 | TickerCache: make(map[string]CurrencyPair), | 51 | TickerCache: make(map[string]CurrencyPair), |
@@ -52,8 +54,8 @@ func NewPoloniex() *Poloniex { | |||
52 | } | 54 | } |
53 | } | 55 | } |
54 | 56 | ||
55 | func (p *Poloniex) TestCredentials(apiKey, apiSecret string) error { | 57 | func (p *Poloniex) TestCredentials(apiKey, apiSecret string, timeout int32) error { |
56 | client, _ := poloniex.NewClient(apiKey, apiSecret) | 58 | client, _ := poloniex.NewClient(apiKey, apiSecret, timeout) |
57 | 59 | ||
58 | _, err := client.TradeReturnDepositAdresses() | 60 | _, err := client.TradeReturnDepositAdresses() |
59 | 61 | ||
@@ -68,8 +70,8 @@ func (p *Poloniex) TestCredentials(apiKey, apiSecret string) error { | |||
68 | return err | 70 | return err |
69 | } | 71 | } |
70 | 72 | ||
71 | func (p *Poloniex) GetBalance(apiKey, apiSecret string) (Summary, error) { | 73 | func (p *Poloniex) GetBalance(apiKey, apiSecret string, timeout int32) (Summary, error) { |
72 | client, _ := poloniex.NewClient(apiKey, apiSecret) | 74 | client, _ := poloniex.NewClient(apiKey, apiSecret, timeout) |
73 | var summary Summary | 75 | var summary Summary |
74 | 76 | ||
75 | accounts, err := client.TradeReturnAvailableAccountBalances() | 77 | accounts, err := client.TradeReturnAvailableAccountBalances() |