cmd/kline: show klines from restful api

This commit is contained in:
c9s 2022-08-11 00:08:48 +08:00
parent ba87ffab43
commit e735362efd
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"syscall" "syscall"
"time"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -54,6 +55,19 @@ var klineCmd = &cobra.Command{
return err return err
} }
now := time.Now()
kLines, err := session.Exchange.QueryKLines(ctx, symbol, types.Interval(interval), types.KLineQueryOptions{
Limit: 50,
EndTime: &now,
})
if err != nil {
return err
}
log.Infof("kLines from RESTful API")
for _, k := range kLines {
log.Info(k.String())
}
s := session.Exchange.NewStream() s := session.Exchange.NewStream()
s.SetPublicOnly() s.SetPublicOnly()
s.Subscribe(types.KLineChannel, symbol, types.SubscribeOptions{Interval: types.Interval(interval)}) s.Subscribe(types.KLineChannel, symbol, types.SubscribeOptions{Interval: types.Interval(interval)})