X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=api%2Fmarket_config.go;h=d5f05d9743df29c178d3eddd325003e3588697a3;hb=73bad1e9ec3c0981151ead328b8f955c70f07429;hp=09eb8a9c00ea2aa22a4521bea2f382afd4c9442a;hpb=c6aa553f48d1014f651441bbd9e023508d0a819c;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FFront.git diff --git a/api/market_config.go b/api/market_config.go index 09eb8a9..d5f05d9 100644 --- a/api/market_config.go +++ b/api/market_config.go @@ -5,9 +5,9 @@ import ( "strings" "time" + "git.immae.eu/Cryptoportfolio/Front.git/db" + "git.immae.eu/Cryptoportfolio/Front.git/markets" "github.com/jloup/utils" - "immae.eu/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front/db" - "immae.eu/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front/markets" ) type MarketConfigQuery struct { @@ -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)} @@ -97,8 +97,23 @@ func (q TestMarketCredentialsQuery) Run() (interface{}, *Error) { return nil }) - if resultErr != nil { + var newStatus db.MarketConfigStatus = config.Status + + if ErrorIs(resultErr, InvalidMarketCredentials) || ErrorIs(resultErr, IPRestrictedApiKey) || ErrorIs(resultErr, MarketCredentialsNotConfigured) { + newStatus = db.MarketConfigInvalidCredentials + } else if resultErr != nil { + return nil, NewInternalError(resultErr) + } else if resultErr != nil { return nil, NewInternalError(resultErr) + } else if resultErr == nil { + newStatus = db.MarketConfigEnabled + } + + if newStatus != config.Status { + config, err = db.SetMarketConfigStatus(*config, newStatus) + if err != nil { + return nil, NewInternalError(err) + } } return nil, nil @@ -139,7 +154,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)} @@ -158,7 +173,7 @@ func (q UpdateMarketConfigQuery) Run() (interface{}, *Error) { var newStatus db.MarketConfigStatus = db.MarketConfigEnabled - if ErrorIs(resultErr, InvalidMarketCredentials) || ErrorIs(resultErr, IPRestrictedApiKey) { + if ErrorIs(resultErr, InvalidMarketCredentials) || ErrorIs(resultErr, IPRestrictedApiKey) || ErrorIs(resultErr, MarketCredentialsNotConfigured) { newStatus = db.MarketConfigInvalidCredentials } else if resultErr != nil { return nil, NewInternalError(resultErr)