mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-14 02:53:50 +00:00
65 lines
1.0 KiB
Go
65 lines
1.0 KiB
Go
|
// +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)
|
||
|
}
|
||
|
}
|