-
Notifications
You must be signed in to change notification settings - Fork 3
/
ticker_service.go
68 lines (60 loc) · 1.81 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
63
64
65
66
67
68
package phemex
import (
"context"
"encoding/json"
)
// ListPriceChangeStatsService show stats of price change in last 24 hours for all symbols
type ListPriceChangeStatsService struct {
c *Client
symbol *string
}
// Symbol set symbol
func (s *ListPriceChangeStatsService) Symbol(symbol string) *ListPriceChangeStatsService {
s.symbol = &symbol
return s
}
// Do send request
func (s *ListPriceChangeStatsService) Do(ctx context.Context, opts ...RequestOption) (res *PriceChangeStats, err error) {
r := &request{
method: "GET",
endpoint: "/v1/md/ticker/24hr/all",
}
if s.symbol != nil {
r.setParam("symbol", *s.symbol)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return res, err
}
resp := new(BaseTickerResponse)
resp.Result = new(PriceChangeStats)
err = json.Unmarshal(data, resp)
if err != nil {
return nil, err
}
return resp.Result.(*PriceChangeStats), nil
}
// BaseTickerResponse base ticker response
type BaseTickerResponse struct {
Error int64 `json:"error"`
ID int64 `json:"id"`
Result interface{} `json:"result"`
}
// PriceChangeStats define price change stats
type PriceChangeStats struct {
AskEp int64 `json:"askEp"`
BidEp int64 `json:"bidEp"`
OpenEp int64 `json:"openEp"`
HighEp int64 `json:"highEp"`
LowEp int64 `json:"lowEp"`
LastEp int64 `json:"lastEp"`
IndexEp int64 `json:"indexEp"`
MarkEp int64 `json:"markEp"`
OpenInterest float64 `json:"openInterest"`
FundingRateEr float64 `json:"fundingRateEr"`
PredFundingRateEr float64 `json:"predFundingRateEr"`
Timestamp int64 `json:"timestamp"`
Symbol string `json:"symbol"`
TurnoverEv int64 `json:"turnoverEv"`
Volume float64 `json:"volume"`
}