From 908ee2dd22c85d5d850f62b1a9d0066b43b80a69 Mon Sep 17 00:00:00 2001 From: jloup Date: Mon, 26 Mar 2018 10:54:48 +0200 Subject: [PATCH] Handle poloniex ip restriction. --- api/const.go | 3 ++- api/const_string.go | 4 ++-- cmd/web/js/poloniex.jsx | 5 +++++ markets/poloniex.go | 8 ++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/api/const.go b/api/const.go index 1b22355..d3e5f42 100644 --- a/api/const.go +++ b/api/const.go @@ -19,6 +19,7 @@ const ( InvalidCredentials InvalidEmail InvalidMarketCredentials + IPRestrictedApiKey InvalidOtp InvalidPassword NeedOtpValidation @@ -35,7 +36,7 @@ func StatusToHttpCode(status Status, code ErrorCode) int { } switch code { - case BadRequest, InvalidPassword, InvalidEmail, InvalidMarketCredentials: + case BadRequest, InvalidPassword, InvalidEmail, InvalidMarketCredentials, IPRestrictedApiKey: return http.StatusBadRequest case InvalidCredentials, InvalidOtp: diff --git a/api/const_string.go b/api/const_string.go index e4b9e50..58ed230 100644 --- a/api/const_string.go +++ b/api/const_string.go @@ -15,9 +15,9 @@ func (i Status) String() string { return _Status_name[_Status_index[i]:_Status_index[i+1]] } -const _ErrorCode_name = "BadRequestEmailExistsExternalServiceTimeoutInternalErrorInvalidCredentialsInvalidEmailInvalidMarketCredentialsInvalidOtpInvalidPasswordNeedOtpValidationNotAuthorizedNotFoundOtpAlreadySetupOtpNotSetupUserNotConfirmed" +const _ErrorCode_name = "BadRequestEmailExistsExternalServiceTimeoutInternalErrorInvalidCredentialsInvalidEmailInvalidMarketCredentialsIPRestrictedApiKeyInvalidOtpInvalidPasswordNeedOtpValidationNotAuthorizedNotFoundOtpAlreadySetupOtpNotSetupUserNotConfirmed" -var _ErrorCode_index = [...]uint8{0, 10, 21, 43, 56, 74, 86, 110, 120, 135, 152, 165, 173, 188, 199, 215} +var _ErrorCode_index = [...]uint8{0, 10, 21, 43, 56, 74, 86, 110, 128, 138, 153, 170, 183, 191, 206, 217, 233} func (i ErrorCode) String() string { i -= 3 diff --git a/cmd/web/js/poloniex.jsx b/cmd/web/js/poloniex.jsx index 482dbb6..813a506 100644 --- a/cmd/web/js/poloniex.jsx +++ b/cmd/web/js/poloniex.jsx @@ -32,6 +32,8 @@ class PoloniexController extends React.Component { console.error(err, data); if (err.code === 'invalid_market_credentials') { this.setState({'flag': 'invalidCredentials', 'valueCurrency': null, 'balanceValue': null, 'balance': null}); + } else if (err.code === 'ip_restricted_api_key') { + this.setState({'flag': 'ipRestricted', 'valueCurrency': null, 'balanceValue': null, 'balance': null}); } return; } @@ -68,6 +70,9 @@ class PoloniexController extends React.Component { case 'invalidCredentials': displayText = 'Invalid poloniex credentials'; break; + case 'ipRestricted': + displayText = 'Your API key is IP restricted. Please whitelist us.'; + break; case 'emptyCredentials': displayText = 'Please provide poloniex credentials'; break; diff --git a/markets/poloniex.go b/markets/poloniex.go index 5e1ec64..34ebb7e 100644 --- a/markets/poloniex.go +++ b/markets/poloniex.go @@ -13,6 +13,7 @@ var ( ErrorFlagCounter utils.Counter = 0 CurrencyPairNotInTicker = utils.InitFlag(&ErrorFlagCounter, "CurrencyPairNotInTicker") InvalidCredentials = utils.InitFlag(&ErrorFlagCounter, "InvalidCredentials") + IPRestricted = utils.InitFlag(&ErrorFlagCounter, "IPRestricted") ) func poloniexInvalidCredentialsError(err error) bool { @@ -22,6 +23,13 @@ func poloniexInvalidCredentialsError(err error) bool { return strings.Contains(err.Error(), "Invalid API key/secret pair") } +func poloniexRestrictedIPError(err error) bool { + if err == nil { + return false + } + return strings.Contains(err.Error(), "Permission denied") +} + type CurrencyPair struct { Name string Rate decimal.Decimal -- 2.41.0