]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/blobdiff - markets/poloniex.go
Set poloniex client timeout to 20 seconds.
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git] / markets / poloniex.go
index 58645b2b2a23750c4adae2633e7c7297bfb71d19..595d5a4890ac73001f37c2a20f9cf4ba5abe18eb 100644 (file)
@@ -16,11 +16,13 @@ var (
        IPRestricted                          = utils.InitFlag(&ErrorFlagCounter, "IPRestricted")
 )
 
+const defaultTimeout = 10
+
 func poloniexInvalidCredentialsError(err error) bool {
        if err == nil {
                return false
        }
-       return strings.Contains(err.Error(), "Invalid API key/secret pair")
+       return strings.Contains(err.Error(), "Invalid API key/secret pair") || strings.Contains(err.Error(), "Set the API KEY and API SECRET")
 }
 
 func poloniexRestrictedIPError(err error) bool {
@@ -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()
 
@@ -65,11 +67,11 @@ func (p *Poloniex) TestCredentials(apiKey, apiSecret string) error {
                return utils.Error{IPRestricted, "IP restricted api key"}
        }
 
-       return nil
+       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()