-
Notifications
You must be signed in to change notification settings - Fork 102
/
public_data.go
241 lines (225 loc) · 7.24 KB
/
public_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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
package rest
import (
"encoding/json"
"github.com/amir-the-h/okex"
requests "github.com/amir-the-h/okex/requests/rest/public"
responses "github.com/amir-the-h/okex/responses/public_data"
"net/http"
)
// PublicData
//
// https://www.okex.com/docs-v5/en/#rest-api-public-data
type PublicData struct {
client *ClientRest
}
// NewPublicData returns a pointer to a fresh PublicData
func NewPublicData(c *ClientRest) *PublicData {
return &PublicData{c}
}
// GetInstruments
// Retrieve a list of instruments with open contracts.
//
// https://www.okex.com/docs-v5/en/#rest-api-public-data-get-instruments
func (c *PublicData) GetInstruments(req requests.GetInstruments) (response responses.GetInstruments, err error) {
p := "/api/v5/public/instruments"
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
}
// GetDeliveryExerciseHistory
// Retrieve the estimated delivery price, which will only have a return value one hour before the delivery/exercise.
//
// https://www.okex.com/docs-v5/en/#rest-api-public-data-get-instruments
func (c *PublicData) GetDeliveryExerciseHistory(req requests.GetDeliveryExerciseHistory) (response responses.GetDeliveryExerciseHistory, err error) {
p := "/api/v5/public/delivery-exercise-history"
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
}
// GetOpenInterest
// Retrieve the total open interest for contracts on OKEx.
//
// https://www.okex.com/docs-v5/en/#rest-api-public-data-get-open-interest
func (c *PublicData) GetOpenInterest(req requests.GetOpenInterest) (response responses.GetOpenInterest, err error) {
p := "/api/v5/public/open-interest"
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
}
// GetLimitPrice
// Retrieve the highest buy limit and lowest sell limit of the instrument.
//
// https://www.okex.com/docs-v5/en/#rest-api-public-data-get-limit-price
func (c *PublicData) GetLimitPrice(req requests.GetLimitPrice) (response responses.GetLimitPrice, err error) {
p := "/api/v5/public/price-limit"
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
}
// GetOptionMarketData
// Retrieve option market data.
//
// https://www.okex.com/docs-v5/en/#rest-api-public-data-get-option-market-data
func (c *PublicData) GetOptionMarketData(req requests.GetOptionMarketData) (response responses.GetOptionMarketData, err error) {
p := "/api/v5/public/opt-summary"
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
}
// GetEstimatedDeliveryExercisePrice
// Retrieve the estimated delivery price which will only have a return value one hour before the delivery/exercise.
//
// https://www.okex.com/docs-v5/en/#rest-api-public-data-get-estimated-delivery-Exercise-price
func (c *PublicData) GetEstimatedDeliveryExercisePrice(req requests.GetEstimatedDeliveryExercisePrice) (response responses.GetEstimatedDeliveryExercisePrice, err error) {
p := "/api/v5/public/estimated-price"
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
}
// GetDiscountRateAndInterestFreeQuota
// Retrieve discount rate level and interest-free quota.
//
// https://www.okex.com/docs-v5/en/#rest-api-public-data-get-discount-rate-and-interest-free-quota
func (c *PublicData) GetDiscountRateAndInterestFreeQuota(req requests.GetDiscountRateAndInterestFreeQuota) (response responses.GetDiscountRateAndInterestFreeQuota, err error) {
p := "/api/v5/public/discount-rate-interest-free-quota"
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
}
// GetSystemTime
// Retrieve API server time.
//
// https://www.okex.com/docs-v5/en/#rest-api-public-data-get-system-time
func (c *PublicData) GetSystemTime() (response responses.GetSystemTime, err error) {
p := "/api/v5/public/time"
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
}
// GetLiquidationOrders
// Retrieve information on liquidation orders in the last 7 days.
//
// https://www.okex.com/docs-v5/en/#rest-api-public-data-get-liquidation-orders
func (c *PublicData) GetLiquidationOrders(req requests.GetLiquidationOrders) (response responses.GetLiquidationOrders, err error) {
p := "/api/v5/public/liquidation-orders"
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
}
// GetMarkPrice
// Retrieve mark price.
//
// We set the mark price based on the SPOT index and at a reasonable basis to prevent individual users from manipulating the market and causing the contract price to fluctuate.
//
// https://www.okex.com/docs-v5/en/#rest-api-public-data-get-mark-price
func (c *PublicData) GetMarkPrice(req requests.GetMarkPrice) (response responses.GetMarkPrice, err error) {
p := "/api/v5/public/mark-price"
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
}
// GetPositionTiers
// Position information,Maximum leverage depends on your borrowings and margin ratio.
//
// https://www.okex.com/docs-v5/en/#rest-api-public-data-get-position-tiers
func (c *PublicData) GetPositionTiers(req requests.GetPositionTiers) (response responses.GetPositionTiers, err error) {
p := "/api/v5/public/position-tiers"
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
}
// GetInterestRateAndLoanQuota
// Get margin interest rate
//
// https://www.okex.com/docs-v5/en/#rest-api-public-data-get-position-tiers
func (c *PublicData) GetInterestRateAndLoanQuota() (response responses.GetInterestRateAndLoanQuota, err error) {
p := "/api/v5/public/interest-rate-loan-quota"
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
}
// GetUnderlying
//
// https://www.okex.com/docs-v5/en/#rest-api-public-data-get-underlying
func (c *PublicData) GetUnderlying(req requests.GetUnderlying) (response responses.GetUnderlying, err error) {
p := "/api/v5/public/underlying"
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
}