2021-12-29 18:17:03 +00:00
|
|
|
//go:build ignore
|
2021-12-21 17:04:33 +00:00
|
|
|
// +build ignore
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"text/template"
|
|
|
|
|
|
|
|
"github.com/c9s/bbgo/pkg/exchange/kucoin/kucoinapi"
|
|
|
|
)
|
|
|
|
|
|
|
|
var packageTemplate = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT.
|
|
|
|
package kucoin
|
|
|
|
|
2023-11-02 17:03:16 +00:00
|
|
|
var SymbolMap = map[string]string{
|
2021-12-21 17:04:33 +00:00
|
|
|
{{- range $k, $v := . }}
|
|
|
|
{{ printf "%q" $k }}: {{ printf "%q" $v }},
|
|
|
|
{{- end }}
|
|
|
|
}
|
|
|
|
|
2023-11-02 17:03:16 +00:00
|
|
|
func ToLocalSymbol(symbol string) string {
|
2021-12-21 17:04:33 +00:00
|
|
|
s, ok := symbolMap[symbol]
|
|
|
|
if ok {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
return symbol
|
|
|
|
}
|
|
|
|
`))
|
|
|
|
|
|
|
|
type Market struct {
|
|
|
|
Symbol string `json:"symbol"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ApiResponse struct {
|
|
|
|
Data []Market `json:"data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
const apiUrl = kucoinapi.RestBaseURL + "/v1/symbols"
|
|
|
|
|
|
|
|
resp, err := http.Get(apiUrl)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
r := &ApiResponse{}
|
2022-06-17 04:01:15 +00:00
|
|
|
if err := json.NewDecoder(resp.Body).Decode(r); err != nil {
|
2021-12-21 17:04:33 +00:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var data = map[string]string{}
|
|
|
|
for _, m := range r.Data {
|
|
|
|
key := strings.ReplaceAll(strings.ToUpper(strings.TrimSpace(m.Symbol)), "-", "")
|
|
|
|
data[key] = m.Symbol
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|