@@ -18,6 +18,7 @@ import (
1818 "github.com/stellar/kelp/plugins"
1919 "github.com/stellar/kelp/support/kelpos"
2020 "github.com/stellar/kelp/support/toml"
21+ "github.com/stellar/kelp/support/utils"
2122 "github.com/stellar/kelp/trader"
2223)
2324
@@ -69,11 +70,13 @@ func (s *APIServer) upsertBotConfig(w http.ResponseWriter, r *http.Request) {
6970 return
7071 }
7172
73+ // validate before init validation so we return validation errors to user instead of throwing unknown errors on init if file is invalid
7274 if errResp := s .validateConfigs (req ); errResp != nil {
7375 s .writeJson (w , errResp )
7476 return
7577 }
7678
79+ // init after validation so we return validation errors to user instead of throwing unknown errors on init if file is invalid
7780 e = req .TraderConfig .Init ()
7881 if e != nil {
7982 s .writeErrorJson (w , fmt .Sprintf ("error running Init() for TraderConfig: %s" , e ))
@@ -121,6 +124,24 @@ func (s *APIServer) validateConfigs(req upsertBotConfigRequest) *upsertBotConfig
121124 if _ , e := strkey .Decode (strkey .VersionByteSeed , req .TraderConfig .TradingSecretSeed ); e != nil {
122125 errResp .TraderConfig .TradingSecretSeed = "invalid Trader Secret Key"
123126 hasError = true
127+ } else {
128+ // only check this if it is a valid trading secret seed
129+ tradingAccount , e := utils .ParseSecret (req .TraderConfig .TradingSecretSeed )
130+ if e != nil {
131+ errResp .TraderConfig .TradingSecretSeed = fmt .Sprintf ("unable to parse: %s" , e )
132+ hasError = true
133+ } else {
134+ if req .TraderConfig .IssuerA == * tradingAccount {
135+ errResp .TraderConfig .TradingSecretSeed = "cannot trade using issuer account"
136+ errResp .TraderConfig .IssuerA = "cannot trade asset issued by trading account"
137+ hasError = true
138+ }
139+ if req .TraderConfig .IssuerB == * tradingAccount {
140+ errResp .TraderConfig .TradingSecretSeed = "cannot trade using issuer account"
141+ errResp .TraderConfig .IssuerB = "cannot trade asset issued by trading account"
142+ hasError = true
143+ }
144+ }
124145 }
125146
126147 if req .TraderConfig .AssetCodeA == "" || len (req .TraderConfig .AssetCodeA ) > 12 {
0 commit comments