-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_bot_config.go
59 lines (53 loc) · 1.75 KB
/
get_bot_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package backend
import (
"encoding/json"
"fmt"
"log"
"net/http"
"github.com/stellar/go/support/config"
"github.com/stellar/kelp/gui/model2"
"github.com/stellar/kelp/plugins"
"github.com/stellar/kelp/trader"
)
type botConfigResponse struct {
Name string `json:"name"`
Strategy string `json:"strategy"`
TraderConfig trader.BotConfig `json:"trader_config"`
StrategyConfig plugins.BuySellConfig `json:"strategy_config"`
}
func (s *APIServer) getBotConfig(w http.ResponseWriter, r *http.Request) {
botName, e := s.parseBotName(r)
if e != nil {
s.writeError(w, fmt.Sprintf("error parsing bot name in getBotConfig: %s\n", e))
return
}
filenamePair := model2.GetBotFilenames(botName, "buysell")
traderFilePath := s.botConfigsPath.Join(filenamePair.Trader)
var botConfig trader.BotConfig
e = config.Read(traderFilePath.Native(), &botConfig)
if e != nil {
s.writeErrorJson(w, fmt.Sprintf("cannot read bot config at path '%s': %s\n", traderFilePath, e))
return
}
strategyFilePath := s.botConfigsPath.Join(filenamePair.Strategy)
var buysellConfig plugins.BuySellConfig
e = config.Read(strategyFilePath.Native(), &buysellConfig)
if e != nil {
s.writeErrorJson(w, fmt.Sprintf("cannot read strategy config at path '%s': %s\n", strategyFilePath, e))
return
}
response := botConfigResponse{
Name: botName,
Strategy: "buysell",
TraderConfig: botConfig,
StrategyConfig: buysellConfig,
}
jsonBytes, e := json.MarshalIndent(response, "", " ")
if e != nil {
s.writeErrorJson(w, fmt.Sprintf("cannot marshal botConfigResponse: %s\n", e))
return
}
log.Printf("getBotConfig response for botName '%s': %s\n", botName, string(jsonBytes))
w.WriteHeader(http.StatusOK)
w.Write(jsonBytes)
}