]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/blobdiff - markets/poloniex.go
Add column 'status' to market_configs.
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git] / markets / poloniex.go
index 9aaeafbfcb1cedc3f6812bb0cd34d61a97ff160d..cadc8295c2464c6dedbab9306671eeea4ae7a031 100644 (file)
@@ -20,7 +20,7 @@ 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 {
@@ -52,6 +52,22 @@ func NewPoloniex() *Poloniex {
        }
 }
 
+func (p *Poloniex) TestCredentials(apiKey, apiSecret string) error {
+       client, _ := poloniex.NewClient(apiKey, apiSecret)
+
+       _, err := client.TradeReturnDepositAdresses()
+
+       if poloniexInvalidCredentialsError(err) {
+               return utils.Error{InvalidCredentials, "invalid poloniex credentials"}
+       }
+
+       if poloniexRestrictedIPError(err) {
+               return utils.Error{IPRestricted, "IP restricted api key"}
+       }
+
+       return err
+}
+
 func (p *Poloniex) GetBalance(apiKey, apiSecret string) (Summary, error) {
        client, _ := poloniex.NewClient(apiKey, apiSecret)
        var summary Summary