forked from ccxt/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen_interest_service.go
53 lines (46 loc) · 1.33 KB
/
open_interest_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
package eoptions
import (
"context"
"encoding/json"
"net/http"
)
type OpenInterest struct {
Symbol string `json:"symbol"`
SumOpenInterest string `json:"sumOpenInterest"`
SumOpenInterestUsd string `json:"sumOpenInterestUsd"`
Timestamp string `json:"timestamp"`
}
// underlying: Spot trading pairs such as BTCUSDT
type OpenInterestService struct {
c *Client
underlyingAsset string //Target assets, such as ETH or BTC
expiration string //Maturity date, such as 221225
}
// Underlying set underlying
func (s *OpenInterestService) UnderlyingAsset(underlyingAsset string) *OpenInterestService {
s.underlyingAsset = underlyingAsset
return s
}
func (s *OpenInterestService) Expiration(expiration string) *OpenInterestService {
s.expiration = expiration
return s
}
// Do send request
func (s *OpenInterestService) Do(ctx context.Context, opts ...RequestOption) (res []*OpenInterest, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/eapi/v1/openInterest",
}
r.setParam("underlyingAsset", s.underlyingAsset)
r.setParam("expiration", s.expiration)
data, _, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return []*OpenInterest{}, err
}
res = make([]*OpenInterest, 0)
err = json.Unmarshal(data, &res)
if err != nil {
return []*OpenInterest{}, err
}
return res, nil
}