mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
gensymbols to generate spot symbol map
This commit is contained in:
parent
d8c6545d2d
commit
c9aa0df054
|
@ -6,9 +6,10 @@ func toGlobalSymbol(symbol string) string {
|
|||
return strings.ReplaceAll(symbol, "-", "")
|
||||
}
|
||||
|
||||
//go:generate sh -c "echo \"package okex\nvar symbolMap = map[string]string{\n\" $(curl -s -L 'https://okex.com/api/v5/public/instruments?instType=SPOT' | jq -r '.data[] | \"\\(.instId | sub(\"-\" ; \"\") | tojson ): \\( .instId | tojson),\n\"') \"\n}\" > symbols.go"
|
||||
////go:generate sh -c "echo \"package okex\nvar spotSymbolMap = map[string]string{\n\" $(curl -s -L 'https://okex.com/api/v5/public/instruments?instType=SPOT' | jq -r '.data[] | \"\\(.instId | sub(\"-\" ; \"\") | tojson ): \\( .instId | tojson),\n\"') \"\n}\" > symbols.go"
|
||||
//go:generate go run gensymbols.go
|
||||
func toLocalSymbol(symbol string) string {
|
||||
if s, ok := symbolMap[symbol]; ok {
|
||||
if s, ok := spotSymbolMap[symbol]; ok {
|
||||
return s
|
||||
}
|
||||
|
||||
|
|
51
pkg/exchange/okex/gensymbols.go
Normal file
51
pkg/exchange/okex/gensymbols.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/exchange/okex/okexapi"
|
||||
)
|
||||
|
||||
var packageTemplate = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT.
|
||||
package okex
|
||||
|
||||
var spotSymbolMap = map[string]string{
|
||||
{{- range $k, $v := . }}
|
||||
{{ printf "%q" $k }}: {{ printf "%q" $v }},
|
||||
{{- end }}
|
||||
}
|
||||
|
||||
`))
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
client := okexapi.NewClient()
|
||||
instruments, err := client.PublicDataService.NewGetInstrumentsRequest().InstrumentType(okexapi.InstrumentTypeSpot).Do(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var data = map[string]string{}
|
||||
for _, instrument := range instruments {
|
||||
symbol := strings.ReplaceAll(instrument.InstrumentID, "-", "")
|
||||
data[symbol] = instrument.InstrumentID
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user