mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-27 17:25:16 +00:00
66 lines
1.1 KiB
Go
66 lines
1.1 KiB
Go
//go:build ignore
|
|
// +build ignore
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
"text/template"
|
|
)
|
|
|
|
var packageTemplate = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT.
|
|
package ftx
|
|
var symbolMap = map[string]string{
|
|
{{- range $k, $v := . }}
|
|
{{ printf "%q" $k }}: {{ printf "%q" $v }},
|
|
{{- end }}
|
|
}
|
|
`))
|
|
|
|
type Market struct {
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
type ApiResponse struct {
|
|
Success bool `json:"success"`
|
|
|
|
Result []Market `json:"result"`
|
|
}
|
|
|
|
func main() {
|
|
var data = map[string]string{}
|
|
|
|
const url = "https://ftx.com/api/markets"
|
|
|
|
resp, err := http.Get(url)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
return
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
r := &ApiResponse{}
|
|
json.NewDecoder(resp.Body).Decode(r)
|
|
|
|
for _, m := range r.Result {
|
|
key := strings.ReplaceAll(strings.ToUpper(strings.TrimSpace(m.Name)), "/", "")
|
|
data[key] = m.Name
|
|
}
|
|
|
|
f, err := os.Create("symbols.go")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
err = packageTemplate.Execute(f, data)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|