okex: implement query ticker

This commit is contained in:
c9s 2021-05-26 02:44:03 +08:00
parent 3511bcf13f
commit d8c6545d2d
2 changed files with 21 additions and 2 deletions

View File

@ -9,7 +9,6 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
// OKB is the platform currency of OKEx, pre-allocate static string here // OKB is the platform currency of OKEx, pre-allocate static string here
const OKB = "OKB" const OKB = "OKB"
@ -81,7 +80,23 @@ func (e *Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error) {
} }
func (e *Exchange) QueryTicker(ctx context.Context, symbol string) (*types.Ticker, error) { func (e *Exchange) QueryTicker(ctx context.Context, symbol string) (*types.Ticker, error) {
return nil, nil symbol = toLocalSymbol(symbol)
marketTicker, err := e.client.MarketTicker(symbol)
if err != nil {
return nil, err
}
return &types.Ticker{
Time: marketTicker.Timestamp.Time(),
Volume: marketTicker.Volume24H.Float64(),
Last: marketTicker.Last.Float64(),
Open: marketTicker.Open24H.Float64(),
High: marketTicker.High24H.Float64(),
Low: marketTicker.Low24H.Float64(),
Buy: marketTicker.BidPrice.Float64(),
Sell: marketTicker.AskPrice.Float64(),
}, nil
} }
func (e *Exchange) QueryTickers(ctx context.Context, symbol string) (*types.Ticker, error) { func (e *Exchange) QueryTickers(ctx context.Context, symbol string) (*types.Ticker, error) {

View File

@ -14,6 +14,10 @@ func (t MillisecondTimestamp) String() string {
return time.Time(t).String() return time.Time(t).String()
} }
func (t MillisecondTimestamp) Time() time.Time {
return time.Time(t)
}
func (t *MillisecondTimestamp) UnmarshalJSON(data []byte) error { func (t *MillisecondTimestamp) UnmarshalJSON(data []byte) error {
var v interface{} var v interface{}