forked from stellar-deprecated/kelp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_new_bot_config.go
40 lines (36 loc) · 1006 Bytes
/
get_new_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
package backend
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
func (s *APIServer) getNewBotConfig(w http.ResponseWriter, r *http.Request) {
botName, e := s.doGenerateBotName()
if e != nil {
s.writeErrorJson(w, fmt.Sprintf("cannot generate a new bot name: %s", e))
return
}
sampleTrader := s.makeSampleTrader("")
strategy := "buysell"
sampleBuysell := makeSampleBuysell()
// remove asset data from the trader file for the new config
sampleTrader.AssetCodeA = ""
sampleTrader.IssuerA = ""
sampleTrader.AssetCodeB = ""
sampleTrader.IssuerB = ""
response := botConfigResponse{
Name: botName,
Strategy: strategy,
TraderConfig: *sampleTrader,
StrategyConfig: *sampleBuysell,
}
jsonBytes, e := json.MarshalIndent(response, "", " ")
if e != nil {
s.writeErrorJson(w, fmt.Sprintf("cannot marshal botConfigResponse: %s\n", e))
return
}
log.Printf("getNewBotConfig response: %s\n", string(jsonBytes))
w.WriteHeader(http.StatusOK)
w.Write(jsonBytes)
}