-
Notifications
You must be signed in to change notification settings - Fork 102
/
trade_data.go
190 lines (177 loc) · 6.27 KB
/
trade_data.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package rest
import (
"encoding/json"
"github.com/amir-the-h/okex"
requests "github.com/amir-the-h/okex/requests/rest/tradedata"
responses "github.com/amir-the-h/okex/responses/trade_data"
"net/http"
)
// TradeData
//
// https://www.okex.com/docs-v5/en/#rest-api-tradeing-data
type TradeData struct {
client *ClientRest
}
// NewTradeData returns a pointer to a fresh TradeData
func NewTradeData(c *ClientRest) *TradeData {
return &TradeData{c}
}
// GetSupportCoin
// Get the currency supported by the transaction big data interface
//
// https://www.okex.com/docs-v5/en/#rest-api-trading-data-get-support-coin
func (c *TradeData) GetSupportCoin() (response responses.GetSupportCoin, err error) {
p := "/api/v5/rubik/stat/trading-data/support-coin"
res, err := c.client.Do(http.MethodGet, p, false)
if err != nil {
return
}
defer res.Body.Close()
d := json.NewDecoder(res.Body)
err = d.Decode(&response)
return
}
// GetTakerVolume
// This is the taker volume for both buyers and sellers. This shows the influx and exit of funds in and out of {coin}.
//
// https://www.okex.com/docs-v5/en/#rest-api-trading-data-get-support-coin
func (c *TradeData) GetTakerVolume(req requests.GetTakerVolume) (response responses.GetTakerVolume, err error) {
p := "/api/v5/rubik/stat/taker-volume"
m := okex.S2M(req)
res, err := c.client.Do(http.MethodGet, p, false, m)
if err != nil {
return
}
defer res.Body.Close()
d := json.NewDecoder(res.Body)
err = d.Decode(&response)
return
}
// GetMarginLendingRatio
// This indicator shows the ratio of cumulative data value between currency pair leverage quote currency and underlying asset over a given period of time.
//
// https://www.okex.com/docs-v5/en/#rest-api-trading-data-get-margin-lending-ratio
func (c *TradeData) GetMarginLendingRatio(req requests.GetRatio) (response responses.GetRatio, err error) {
p := "/api/v5/rubik/stat/margin/loan-ratio"
m := okex.S2M(req)
res, err := c.client.Do(http.MethodGet, p, false, m)
if err != nil {
return
}
defer res.Body.Close()
d := json.NewDecoder(res.Body)
err = d.Decode(&response)
return
}
// GetLongShortRatio
// This is the ratio of users with net long vs short positions. It includes data from futures and perpetual swaps.
//
// https://www.okex.com/docs-v5/en/#rest-api-trading-data-get-long-short-ratio
func (c *TradeData) GetLongShortRatio(req requests.GetRatio) (response responses.GetRatio, err error) {
p := "/api/v5/rubik/stat/contracts/long-short-account-ratio"
m := okex.S2M(req)
res, err := c.client.Do(http.MethodGet, p, false, m)
if err != nil {
return
}
defer res.Body.Close()
d := json.NewDecoder(res.Body)
err = d.Decode(&response)
return
}
// GetContractsOpenInterestAndVolume
// Open interest is the sum of all long and short futures and perpetual swap positions.
//
// https://www.okex.com/docs-v5/en/#rest-api-trading-data-get-contracts-open-interest-and-volume
func (c *TradeData) GetContractsOpenInterestAndVolume(req requests.GetRatio) (response responses.GetOpenInterestAndVolume, err error) {
p := "/api/v5/rubik/stat/contracts/open-interest-volume"
m := okex.S2M(req)
res, err := c.client.Do(http.MethodGet, p, false, m)
if err != nil {
return
}
defer res.Body.Close()
d := json.NewDecoder(res.Body)
err = d.Decode(&response)
return
}
// GetOptionsOpenInterestAndVolume
// This shows the sum of all open positions and how much total trading volume has taken place.
//
// https://www.okex.com/docs-v5/en/#rest-api-trading-data-get-options-open-interest-and-volume
func (c *TradeData) GetOptionsOpenInterestAndVolume(req requests.GetRatio) (response responses.GetOpenInterestAndVolume, err error) {
p := "/api/v5/rubik/stat/option/open-interest-volume"
m := okex.S2M(req)
res, err := c.client.Do(http.MethodGet, p, false, m)
if err != nil {
return
}
defer res.Body.Close()
d := json.NewDecoder(res.Body)
err = d.Decode(&response)
return
}
// GetPutCallRatio
// This shows the relative buy/sell volume for calls and puts. It shows whether traders are bullish or bearish on price and volatility.
//
// https://www.okex.com/docs-v5/en/#rest-api-trading-data-get-put-call-ratio
func (c *TradeData) GetPutCallRatio(req requests.GetRatio) (response responses.GetPutCallRatio, err error) {
p := "/api/v5/rubik/stat/option/open-interest-volume-ratio"
m := okex.S2M(req)
res, err := c.client.Do(http.MethodGet, p, false, m)
if err != nil {
return
}
defer res.Body.Close()
d := json.NewDecoder(res.Body)
err = d.Decode(&response)
return
}
// GetOpenInterestAndVolumeExpiry
// This shows the volume and open interest for each upcoming expiration. You can use this to see which expirations are currently the most popular to trade.
//
// https://www.okex.com/docs-v5/en/#rest-api-trading-data-get-open-interest-and-volume-expiry
func (c *TradeData) GetOpenInterestAndVolumeExpiry(req requests.GetRatio) (response responses.GetOpenInterestAndVolumeExpiry, err error) {
p := "/api/v5/rubik/stat/option/open-interest-volume-expiry"
m := okex.S2M(req)
res, err := c.client.Do(http.MethodGet, p, false, m)
if err != nil {
return
}
defer res.Body.Close()
d := json.NewDecoder(res.Body)
err = d.Decode(&response)
return
}
// GetOpenInterestAndVolumeStrike
// This shows what option strikes are the most popular for each expiration.
//
// https://www.okex.com/docs-v5/en/#rest-api-trading-data-get-open-interest-and-volume-strike
func (c *TradeData) GetOpenInterestAndVolumeStrike(req requests.GetOpenInterestAndVolumeStrike) (response responses.GetOpenInterestAndVolumeStrike, err error) {
p := "/api/v5/rubik/stat/option/open-interest-volume-strike"
m := okex.S2M(req)
res, err := c.client.Do(http.MethodGet, p, false, m)
if err != nil {
return
}
defer res.Body.Close()
d := json.NewDecoder(res.Body)
err = d.Decode(&response)
return
}
// GetTakerFlow
// This shows the relative buy/sell volume for calls and puts. It shows whether traders are bullish or bearish on price and volatility.
//
// https://www.okex.com/docs-v5/en/#rest-api-trading-data-get-taker-flow
func (c *TradeData) GetTakerFlow(req requests.GetRatio) (response responses.GetTakerFlow, err error) {
p := "/api/v5/rubik/stat/option/taker-block-volume"
m := okex.S2M(req)
res, err := c.client.Do(http.MethodGet, p, false, m)
if err != nil {
return
}
defer res.Body.Close()
d := json.NewDecoder(res.Body)
err = d.Decode(&response)
return
}