-
Notifications
You must be signed in to change notification settings - Fork 2
/
server_service.go
56 lines (48 loc) · 1.27 KB
/
server_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
package binance
import (
"context"
"github.com/crypto-zero/go-binance/v2/common"
)
// PingService ping server
type PingService struct {
c *Client
}
// Do send Request
func (s *PingService) Do(ctx context.Context, opts ...common.RequestOption) (err error) {
r := common.NewGetRequestPublic("/api/v3/ping")
return s.c.CallAPI(ctx, r, nil, opts...)
}
// ServerTimeService get server time
type ServerTimeService struct {
c *Client
}
// Do send Request
func (s *ServerTimeService) Do(ctx context.Context, opts ...common.RequestOption) (serverTime int64, err error) {
r := common.NewGetRequestPublic("/api/v3/time")
f := func(data []byte) error {
j, err := newJSON(data)
if err != nil {
return err
}
serverTime = j.Get("serverTime").MustInt64()
return nil
}
if err = s.c.CallAPI(ctx, r, f, opts...); err != nil {
return 0, err
}
return serverTime, nil
}
// SetServerTimeService set server time
type SetServerTimeService struct {
c *Client
}
// Do send Request
func (s *SetServerTimeService) Do(ctx context.Context, opts ...common.RequestOption) (timeOffset int64, err error) {
serverTime, err := s.c.NewServerTimeService().Do(ctx)
if err != nil {
return 0, err
}
timeOffset = currentTimestamp() - serverTime
s.c.UpdateTimeOffset(timeOffset)
return timeOffset, nil
}