Skip to content
This repository was archived by the owner on Dec 11, 2024. It is now read-only.

Commit 95c0805

Browse files
authored
Merge pull request #18 from Kucoin/dev
Update API for July
2 parents 5d6677a + d0b4eef commit 95c0805

File tree

16 files changed

+314
-77
lines changed

16 files changed

+314
-77
lines changed

account.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package kumex
22

33
import (
4-
"encoding/json"
4+
"github.com/json-iterator/go"
55
"net/http"
66
)
77

@@ -65,12 +65,12 @@ func (as *ApiService) SubApiKeys(apiKey, subName string) (*ApiResponse, error) {
6565
type SubApiKeysModel []*SubApiKeyModel
6666

6767
type SubApiKeyModel struct {
68-
SubName string `json:"subName"`
69-
Remark string `json:"remark"`
70-
ApiKey string `json:"apiKey"`
71-
Permission string `json:"permission"`
72-
IpWhitelist string `json:"ipWhitelist"`
73-
CreatedAt json.Number `json:"createdAt"`
68+
SubName string `json:"subName"`
69+
Remark string `json:"remark"`
70+
ApiKey string `json:"apiKey"`
71+
Permission string `json:"permission"`
72+
IpWhitelist string `json:"ipWhitelist"`
73+
CreatedAt jsoniter.Number `json:"createdAt"`
7474
}
7575

7676
// CreateSubApiKey This endpoint can be used to create Futures APIs for sub-accounts.
@@ -80,14 +80,14 @@ func (as *ApiService) CreateSubApiKey(p map[string]string) (*ApiResponse, error)
8080
}
8181

8282
type CreateSubApiKeyRes struct {
83-
SubName string `json:"subName"`
84-
Remark string `json:"remark"`
85-
ApiKey string `json:"apiKey"`
86-
Permission string `json:"permission"`
87-
IpWhitelist string `json:"ipWhitelist"`
88-
CreatedAt json.Number `json:"createdAt"`
89-
ApiSecret string `json:"apiSecret"`
90-
Passphrase string `json:"passphrase"`
83+
SubName string `json:"subName"`
84+
Remark string `json:"remark"`
85+
ApiKey string `json:"apiKey"`
86+
Permission string `json:"permission"`
87+
IpWhitelist string `json:"ipWhitelist"`
88+
CreatedAt jsoniter.Number `json:"createdAt"`
89+
ApiSecret string `json:"apiSecret"`
90+
Passphrase string `json:"passphrase"`
9191
}
9292

9393
// ModifySubApiKey TThis endpoint can be used to modify sub-account Futures APIs.
@@ -130,24 +130,24 @@ func (as *ApiService) SubAccountsBalance(currency string) (*ApiResponse, error)
130130

131131
type SubAccountBalanceModel struct {
132132
Summary struct {
133-
AccountEquityTotal json.Number `json:"accountEquityTotal"`
134-
UnrealisedPNLTotal json.Number `json:"unrealisedPNLTotal"`
135-
MarginBalanceTotal json.Number `json:"marginBalanceTotal"`
136-
PositionMarginTotal json.Number `json:"positionMarginTotal"`
137-
OrderMarginTotal json.Number `json:"orderMarginTotal"`
138-
FrozenFundsTotal json.Number `json:"frozenFundsTotal"`
139-
AvailableBalanceTotal json.Number `json:"availableBalanceTotal"`
140-
Currency string `json:"currency"`
133+
AccountEquityTotal jsoniter.Number `json:"accountEquityTotal"`
134+
UnrealisedPNLTotal jsoniter.Number `json:"unrealisedPNLTotal"`
135+
MarginBalanceTotal jsoniter.Number `json:"marginBalanceTotal"`
136+
PositionMarginTotal jsoniter.Number `json:"positionMarginTotal"`
137+
OrderMarginTotal jsoniter.Number `json:"orderMarginTotal"`
138+
FrozenFundsTotal jsoniter.Number `json:"frozenFundsTotal"`
139+
AvailableBalanceTotal jsoniter.Number `json:"availableBalanceTotal"`
140+
Currency string `json:"currency"`
141141
} `json:"summary"`
142142
Accounts []struct {
143-
AccountName string `json:"accountName"`
144-
AccountEquity json.Number `json:"accountEquity"`
145-
UnrealisedPNL json.Number `json:"unrealisedPNL"`
146-
MarginBalance json.Number `json:"marginBalance"`
147-
PositionMargin json.Number `json:"positionMargin"`
148-
OrderMargin json.Number `json:"orderMargin"`
149-
FrozenFunds json.Number `json:"frozenFunds"`
150-
AvailableBalance json.Number `json:"availableBalance"`
151-
Currency string `json:"currency"`
143+
AccountName string `json:"accountName"`
144+
AccountEquity jsoniter.Number `json:"accountEquity"`
145+
UnrealisedPNL jsoniter.Number `json:"unrealisedPNL"`
146+
MarginBalance jsoniter.Number `json:"marginBalance"`
147+
PositionMargin jsoniter.Number `json:"positionMargin"`
148+
OrderMargin jsoniter.Number `json:"orderMargin"`
149+
FrozenFunds jsoniter.Number `json:"frozenFunds"`
150+
AvailableBalance jsoniter.Number `json:"availableBalance"`
151+
Currency string `json:"currency"`
152152
} `json:"accounts"`
153153
}

account_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import (
55
)
66

77
func TestApiService_AccountOverview(t *testing.T) {
8-
t.SkipNow()
98

109
s := NewApiServiceFromEnv()
1110
p := map[string]string{}
12-
p["currency"] = "XBT"
11+
p["currency"] = "USDT"
1312

1413
rsp, err := s.AccountOverview(p)
1514
if err != nil {

funding.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,18 @@ func (as *ApiService) FundingRatesTimeRange(symbol, from, to string) (*ApiRespon
4646
})
4747
return as.Call(req)
4848
}
49+
50+
type TradeFeesV1Resp struct {
51+
Symbol string `json:"symbol"`
52+
TakerFeeRate string `json:"takerFeeRate"`
53+
MakerFeeRate string `json:"makerFeeRate"`
54+
}
55+
56+
// TradeFeesV1 This interface is for the actual fee rate of the trading pair.
57+
// The fee rate of your sub-account is the same as that of the master account.
58+
func (as *ApiService) TradeFeesV1(symbol string) (*ApiResponse, error) {
59+
req := NewRequest(http.MethodGet, "/api/v1/trade-fees", map[string]string{
60+
"symbol": symbol,
61+
})
62+
return as.Call(req)
63+
}

funding_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,17 @@ func TestApiService_FundingRatesTimeRange(t *testing.T) {
4747
t.Log(ToJsonString(o))
4848
}
4949
}
50+
51+
func TestApiService_TradeFeesV1(t *testing.T) {
52+
s := NewApiServiceFromEnv()
53+
rsp, err := s.TradeFeesV1("XBTUSDTM")
54+
if err != nil {
55+
t.Fatal(err)
56+
}
57+
58+
os := TradeFeesV1Resp{}
59+
if err := rsp.ReadData(&os); err != nil {
60+
t.Fatal(err)
61+
}
62+
t.Log(ToJsonString(os))
63+
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module github.com/Kucoin/kucoin-futures-go-sdk
22

33
require (
4+
github.com/google/go-querystring v1.1.0 // indirect
45
github.com/gorilla/websocket v1.4.0
56
github.com/json-iterator/go v1.1.12
67
github.com/pkg/errors v0.8.1

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
22
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
33
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
5+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
6+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
47
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
58
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
69
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
@@ -25,3 +28,4 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
2528
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
2629
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
2730
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
31+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package kumex
22

33
import (
4-
"encoding/json"
4+
"github.com/json-iterator/go"
55
"strconv"
66
)
77

@@ -12,7 +12,7 @@ func IntToString(i int64) string {
1212

1313
// ToJsonString converts any value to JSON string.
1414
func ToJsonString(v interface{}) string {
15-
b, err := json.Marshal(v)
15+
b, err := jsoniter.Marshal(v)
1616
if err != nil {
1717
return ""
1818
}

http.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Request struct {
3232
}
3333

3434
// NewRequest creates a instance of Request.
35-
func NewRequest(method, path string, params map[string]string) *Request {
35+
func NewRequest(method, path string, params interface{}) *Request {
3636
r := &Request{
3737
Method: method,
3838
Path: path,
@@ -51,17 +51,21 @@ func NewRequest(method, path string, params map[string]string) *Request {
5151
return r
5252
}
5353

54-
func (r *Request) addParams(params map[string]string) {
54+
func (r *Request) addParams(p interface{}) {
55+
if p == nil {
56+
return
57+
}
5558
switch r.Method {
5659
case http.MethodGet, http.MethodDelete:
57-
for key, value := range params {
60+
if v, ok := p.(url.Values); ok {
61+
r.Query = v
62+
return
63+
}
64+
for key, value := range p.(map[string]string) {
5865
r.Query.Add(key, value)
5966
}
6067
default:
61-
if params == nil {
62-
return
63-
}
64-
b, err := jsoniter.Marshal(params)
68+
b, err := jsoniter.Marshal(p)
6569
if err != nil {
6670
log.Panic("Cannot marshal params to JSON string:", err.Error())
6771
}

market.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package kumex
22

33
import (
4-
"encoding/json"
4+
"github.com/json-iterator/go"
55
"net/http"
66
)
77

@@ -230,7 +230,7 @@ func (as *ApiService) FundingRate(Symbol string) (*ApiResponse, error) {
230230
}
231231

232232
type TradeStatisticsModel struct {
233-
TurnoverOf24h json.Number `json:"turnoverOf24h"`
233+
TurnoverOf24h jsoniter.Number `json:"turnoverOf24h"`
234234
}
235235

236236
// TradeStatistics Get 24h trade statistics.

order.go

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ func (as *ApiService) CreateOrder(params map[string]string) (*ApiResponse, error
1313
return as.Call(req)
1414
}
1515

16+
// CreateOrderTest places a new order.
17+
func (as *ApiService) CreateOrderTest(params map[string]string) (*ApiResponse, error) {
18+
req := NewRequest(http.MethodPost, "/api/v1/orders/test", params)
19+
return as.Call(req)
20+
}
21+
1622
// A CancelOrderResultModel represents the result of CancelOrder().
1723
type CancelOrderResultModel struct {
1824
CancelledOrderIds []string `json:"cancelledOrderIds"`
@@ -76,7 +82,7 @@ type OrderModel struct {
7682
PostOnly bool `json:"postOnly"`
7783
Hidden bool `json:"hidden"`
7884
IceBerg bool `json:"iceberg"`
79-
VisibleSize string `json:"visibleSize"`
85+
VisibleSize int64 `json:"visibleSize"`
8086
Leverage string `json:"leverage"`
8187
ForceHold bool `json:"forceHold"`
8288
CloseOrder bool `json:"closeOrder"`
@@ -134,3 +140,44 @@ func (as *ApiService) CancelOrderClientId(clientOid, symbol string) (*ApiRespons
134140
req := NewRequest(http.MethodDelete, "/api/v1/orders/client-order/"+clientOid, p)
135141
return as.Call(req)
136142
}
143+
144+
type CreateOrderReq struct {
145+
// BASE PARAMETERS
146+
ClientOid string `json:"clientOid"`
147+
Side string `json:"side"`
148+
Symbol string `json:"symbol,omitempty"`
149+
Leverage string `json:"leverage,omitempty"`
150+
Type string `json:"type,omitempty"`
151+
Remark string `json:"remark,omitempty"`
152+
Stop string `json:"stop,omitempty"`
153+
StopPrice string `json:"stopPrice,omitempty"`
154+
StopPriceType string `json:"stopPriceType,omitempty"`
155+
ReduceOnly string `json:"reduceOnly,omitempty"`
156+
CloseOrder string `json:"closeOrder,omitempty"`
157+
ForceHold string `json:"forceHold,omitempty"`
158+
Stp string `json:"stp,omitempty"`
159+
160+
// MARKET ORDER PARAMETERS
161+
Size string `json:"size,omitempty"`
162+
163+
// LIMIT ORDER PARAMETERS
164+
Price string `json:"price,omitempty"`
165+
TimeInForce string `json:"timeInForce,omitempty"`
166+
PostOnly bool `json:"postOnly,omitempty"`
167+
Hidden bool `json:"hidden,omitempty"`
168+
IceBerg bool `json:"iceberg,omitempty"`
169+
VisibleSize string `json:"visibleSize,omitempty"`
170+
}
171+
172+
type CreateOrderRes struct {
173+
OrderId string `json:"orderId"`
174+
ClientOid string `json:"clientOid"`
175+
Symbol string `json:"symbol"`
176+
}
177+
type CreateMultiOrdersRes []*CreateOrderRes
178+
179+
// CreateMultiOrders places multi order.
180+
func (as *ApiService) CreateMultiOrders(p []*CreateOrderReq) (*ApiResponse, error) {
181+
req := NewRequest(http.MethodPost, "/api/v1/orders/multi", p)
182+
return as.Call(req)
183+
}

0 commit comments

Comments
 (0)