forked from ccxt/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathticker_service.go
62 lines (56 loc) · 1.58 KB
/
ticker_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package eoptions
import (
"context"
"encoding/json"
"net/http"
)
type Ticker struct {
Symbol string `json:"symbol"`
PriceChange string `json:"priceChange"`
PriceChangePercent string `json:"priceChangePercent"`
LastPrice string `json:"lastPrice"`
LastQty string `json:"lastQty"`
Open string `json:"open"`
High string `json:"high"`
Low string `json:"low"`
Volume string `json:"volume"`
Amount string `json:"amount"`
BidPrice string `json:"bidPrice"`
AskPrice string `json:"askPrice"`
OpenTime int64 `json:"openTime"`
CloseTime int64 `json:"closeTime"`
FirstTradeId int `json:"firstTradeId"`
TradeCount int `json:"tradeCount"`
StrikePrice string `json:"strikePrice"`
ExercisePrice string `json:"exercisePrice"`
}
// TickerService list recent trades in orderbook
type TickerService struct {
c *Client
symbol *string
}
// Symbol set symbol
func (s *TickerService) Symbol(symbol string) *TickerService {
s.symbol = &symbol
return s
}
// Do send request
func (s *TickerService) Do(ctx context.Context, opts ...RequestOption) (res []*Ticker, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/eapi/v1/ticker",
}
if s.symbol != nil {
r.setParam("symbol", *s.symbol)
}
data, _, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return []*Ticker{}, err
}
res = make([]*Ticker, 0)
err = json.Unmarshal(data, &res)
if err != nil {
return []*Ticker{}, err
}
return res, nil
}