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

Commit

Permalink
Merge pull request #12 from fenzheng1991/main
Browse files Browse the repository at this point in the history
feat: update api the latest
  • Loading branch information
fenzheng1991 authored Jun 30, 2023
2 parents 62dd174 + f5df736 commit aa4478f
Show file tree
Hide file tree
Showing 14 changed files with 305 additions and 34 deletions.
68 changes: 68 additions & 0 deletions account.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kumex

import (
"encoding/json"
"net/http"
)

Expand Down Expand Up @@ -50,3 +51,70 @@ func (as *ApiService) TransactionHistory(params map[string]string, pagination *P
req := NewRequest(http.MethodGet, "/api/v1/transaction-history", params)
return as.Call(req)
}

// SubApiKeys This endpoint can be used to obtain a list of Futures APIs pertaining to a sub-account.
func (as *ApiService) SubApiKeys(apiKey, subName string) (*ApiResponse, error) {
p := map[string]string{
"apiKey": apiKey,
"subName": subName,
}
req := NewRequest(http.MethodGet, "/api/v1/sub/api-key", p)
return as.Call(req)
}

type SubApiKeysModel []*SubApiKeyModel

type SubApiKeyModel struct {
SubName string `json:"subName"`
Remark string `json:"remark"`
ApiKey string `json:"apiKey"`
Permission string `json:"permission"`
IpWhitelist string `json:"ipWhitelist"`
CreatedAt json.Number `json:"createdAt"`
}

// CreateSubApiKey This endpoint can be used to create Futures APIs for sub-accounts.
func (as *ApiService) CreateSubApiKey(p map[string]string) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v1/sub/api-key", p)
return as.Call(req)
}

type CreateSubApiKeyRes struct {
SubName string `json:"subName"`
Remark string `json:"remark"`
ApiKey string `json:"apiKey"`
Permission string `json:"permission"`
IpWhitelist string `json:"ipWhitelist"`
CreatedAt json.Number `json:"createdAt"`
ApiSecret string `json:"apiSecret"`
Passphrase string `json:"passphrase"`
}

// ModifySubApiKey TThis endpoint can be used to modify sub-account Futures APIs.
func (as *ApiService) ModifySubApiKey(p map[string]string) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v1/sub/api-key/update", p)
return as.Call(req)
}

type ModifySubApiKeyRes struct {
SubName string `json:"subName"`
Permission string `json:"permission"`
IpWhitelist string `json:"ipWhitelist"`
ApiKey string `json:"apiKey"`
}

// DeleteSubApiKey This endpoint can be used to delete sub-account Futures APIs.
func (as *ApiService) DeleteSubApiKey(apiKey, passphrase, subName string) (*ApiResponse, error) {
p := map[string]string{
"apiKey": apiKey,
"passphrase": passphrase,
"subName": subName,
}
req := NewRequest(http.MethodDelete, "/api/v1/sub/api-key", p)
return as.Call(req)
}

type DeleteSubApiKeyRes struct {
ApiKey string `json:"apiKey"`
SubName string `json:"subName"`
}
66 changes: 66 additions & 0 deletions account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,69 @@ func TestApiService_TransactionHistory(t *testing.T) {
}
}
}

func TestApiService_CreateSubApiKey(t *testing.T) {
t.SkipNow()
s := NewApiServiceFromEnv()
p := map[string]string{
"subName": "TestSubAccount1Fen",
"passphrase": "123abcABC",
"remark": "re",
}
rsp, err := s.CreateSubApiKey(p)
if err != nil {
t.Fatal(err)
}
w := &CreateSubApiKeyRes{}
if err := rsp.ReadData(w); err != nil {
t.Fatal(err)
}
t.Log(ToJsonString(w))
}

func TestApiService_SubApiKeys(t *testing.T) {
s := NewApiServiceFromEnv()
rsp, err := s.SubApiKeys("", "TestSubAccount1Fen")
if err != nil {
t.Fatal(err)
}
w := SubApiKeysModel{}
if err := rsp.ReadData(&w); err != nil {
t.Fatal(err)
}
for _, model := range w {
t.Log(ToJsonString(model))
}
}

func TestApiService_ModifySubApiKey(t *testing.T) {
s := NewApiServiceFromEnv()
p := map[string]string{
"subName": "TestSubAccount1Fen",
"apiKey": "649cfa412b8f770001f5eec1",
"passphrase": "123abcABC",
"permission": "Trade",
}
rsp, err := s.ModifySubApiKey(p)
if err != nil {
t.Fatal(err)
}
w := &ModifySubApiKeyRes{}
if err := rsp.ReadData(w); err != nil {
t.Fatal(err)
}
t.Log(ToJsonString(w))
}

func TestApiService_DeleteSubApiKey(t *testing.T) {
s := NewApiServiceFromEnv()
rsp, err := s.DeleteSubApiKey("649cfa412b8f770001f5eec1", "123abcABC", "TestSubAccount1Fen")
if err != nil {
t.Fatal(err)
}
w := &DeleteSubApiKeyRes{}
if err := rsp.ReadData(w); err != nil {
t.Fatal(err)
}
t.Log(ToJsonString(w))
}
2 changes: 2 additions & 0 deletions deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type DepositAddressesModel []*DepositAddressModel

// DepositAddresses returns the deposit address of currency for deposit.
// If return data is empty, you may need create a deposit address first.
// Deprecated
func (as *ApiService) DepositAddresses(currency string) (*ApiResponse, error) {
params := map[string]string{"currency": currency}
req := NewRequest(http.MethodGet, "/api/v1/deposit-addresses", params)
Expand All @@ -37,6 +38,7 @@ type DepositModel struct {
type DepositsModel []*DepositModel

// Deposits returns a list of deposit.
// Deprecated
func (as *ApiService) Deposits(params map[string]string, pagination *PaginationParam) (*ApiResponse, error) {
pagination.ReadParam(params)
req := NewRequest(http.MethodGet, "/api/v1/deposit-list", params)
Expand Down
2 changes: 2 additions & 0 deletions fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type FillModel struct {
CreatedAt int64 `json:"createdAt"`
SettleCurrency string `json:"settleCurrency"`
TradeTime int64 `json:"tradeTime"`
OpenFeePay string `json:"openFeePay"`
CloseFeePay string `json:"closeFeePay"`
}

// A FillsModel is the set of *FillModel.
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ module github.com/Kucoin/kucoin-futures-go-sdk

require (
github.com/gorilla/websocket v1.4.0
github.com/json-iterator/go v1.1.8
github.com/json-iterator/go v1.1.12
github.com/pkg/errors v0.8.1
github.com/sirupsen/logrus v1.4.1
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a // indirect
)

go 1.13
11 changes: 5 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/json-iterator/go v1.1.8 h1:QiWkFLKq0T7mpzwOTu6BzNDbfTE8OLrYhVKYMLF46Ok=
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -23,6 +23,5 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
1 change: 1 addition & 0 deletions market.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Level2MessageQueryModel struct {
type Level2MessageQueryListModel []*Level2MessageQueryModel

// Level2MessageQuery Level 2 Pulling Messages.
// Deprecated
func (as *ApiService) Level2MessageQuery(symbol string, start, end int64) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/level2/message/query", map[string]string{
"symbol": symbol,
Expand Down
18 changes: 16 additions & 2 deletions order.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ func (as *ApiService) StopOrders(symbol string) (*ApiResponse, error) {
return as.Call(req)
}

// ObtainStopOrders represents an order.
func (as *ApiService) ObtainStopOrders(symbol string, page *PaginationParam) (*ApiResponse, error) {
p := map[string]string{}
if symbol != "" {
p["symbol"] = symbol
}
page.ReadParam(p)
req := NewRequest(http.MethodGet, "/api/v1/stopOrders", p)
return as.Call(req)
}

// An OrderModel represents an order.
type OrderModel struct {
Id string `json:"id"`
Expand Down Expand Up @@ -103,7 +114,10 @@ func (as *ApiService) OrderByClientOid(clientOid string) (*ApiResponse, error) {
}

// RecentDoneOrders returns the recent orders of the latest transactions within 24 hours.
func (as *ApiService) RecentDoneOrders() (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/recentDoneOrders", nil)
func (as *ApiService) RecentDoneOrders(symbol string) (*ApiResponse, error) {
p := map[string]string{
"symbol": symbol,
}
req := NewRequest(http.MethodGet, "/api/v1/recentDoneOrders", p)
return as.Call(req)
}
35 changes: 34 additions & 1 deletion order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestApiService_OrderByClientOid(t *testing.T) {

func TestApiService_RecentOrders(t *testing.T) {
s := NewApiServiceFromEnv()
rsp, err := s.RecentDoneOrders()
rsp, err := s.RecentDoneOrders("MATIC-USDT")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -208,3 +208,36 @@ func TestApiService_RecentOrders(t *testing.T) {
}
}
}

func TestApiService_StopOrders(t *testing.T) {
s := NewApiServiceFromEnv()
p := &PaginationParam{CurrentPage: 1, PageSize: 10}
rsp, err := s.ObtainStopOrders("EDU-USDT", p)
if err != nil {
t.Fatal(err)
}

os := OrdersModel{}
if _, err := rsp.ReadPaginationData(&os); err != nil {
t.Fatal(err)
}
for _, o := range os {
t.Log(ToJsonString(o))
switch {
case o.Id == "":
t.Error("Empty key 'id'")
case o.Symbol == "":
t.Error("Empty key 'symbol'")
case o.Type == "":
t.Error("Empty key 'type'")
case o.Side == "":
t.Error("Empty key 'side'")
case o.SettleCurrency == "":
t.Error("Empty key 'settleCurrency'")
case o.Status == "":
t.Error("Empty key 'status'")
case o.UpdatedAt == 0:
t.Error("Empty key 'UpdatedAt'")
}
}
}
10 changes: 8 additions & 2 deletions position.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import (
"net/http"
)

type PositionsModel []*PositionModel

// A PositionModel represents a position info.
type PositionModel struct {
UserId string `json:"userId"`
Id string `json:"id"`
Symbol string `json:"symbol"`
AutoDeposit bool `json:"autoDeposit"`
Expand Down Expand Up @@ -57,8 +60,11 @@ func (as *ApiService) Position(symbol string) (*ApiResponse, error) {
}

// Positions Get Position List.
func (as *ApiService) Positions() (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/positions", nil)
func (as *ApiService) Positions(currency string) (*ApiResponse, error) {
p := map[string]string{
"currency": currency,
}
req := NewRequest(http.MethodGet, "/api/v1/positions", p)
return as.Call(req)
}

Expand Down
33 changes: 17 additions & 16 deletions position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,29 @@ func TestApiService_Position(t *testing.T) {

func TestApiService_Positions(t *testing.T) {
t.SkipNow()

s := NewApiServiceFromEnv()
rsp, err := s.Positions()
rsp, err := s.Positions("USDT")
if err != nil {
t.Fatal(err)
}
o := &PositionModel{}
if err := rsp.ReadData(o); err != nil {
os := PositionsModel{}
if err := rsp.ReadData(&os); err != nil {
t.Fatal(err)
}
t.Log(ToJsonString(o))
switch {
case o.Id == "":
t.Error("Empty key 'id'")
case o.Symbol == "":
t.Error("Empty key 'symbol'")
case o.MarkPrice == "":
t.Error("Empty key 'markPrice'")
case o.MarkValue == "":
t.Error("Empty key 'markValue'")
case o.SettleCurrency == "":
t.Error("Empty key 'SettleCurrency'")
for _, o := range os {
t.Log(ToJsonString(o))
switch {
case o.Id == "":
t.Error("Empty key 'id'")
case o.Symbol == "":
t.Error("Empty key 'symbol'")
case o.MarkPrice == "":
t.Error("Empty key 'markPrice'")
case o.MarkValue == "":
t.Error("Empty key 'markValue'")
case o.SettleCurrency == "":
t.Error("Empty key 'SettleCurrency'")
}
}
}

Expand Down
Loading

0 comments on commit aa4478f

Please sign in to comment.