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 #133 from Kucoin/dev
Browse files Browse the repository at this point in the history
Update API for July
  • Loading branch information
ISAAC-XXYYZZ authored Aug 2, 2024
2 parents 2e31783 + 6c9ec2d commit 8c223ec
Show file tree
Hide file tree
Showing 15 changed files with 1,936 additions and 143 deletions.
23 changes: 23 additions & 0 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,26 @@ func (as *ApiService) IsolatedAccountsV3(symbol, quoteCurrency, queryType string
req := NewRequest(http.MethodGet, "/api/v3/isolated/accounts", p)
return as.Call(req)
}

type UniversalTransferReq struct {
ClientOid string `json:"clientOid"`
Type string `json:"type"`
Currency string `json:"currency"`
Amount string `json:"amount"`
FromUserId string `json:"fromUserId,omitempty"`
FromAccountType string `json:"fromAccountType"`
FromAccountTag string `json:"fromAccountTag,omitempty"`
ToAccountType string `json:"toAccountType"`
ToUserId string `json:"toUserId,omitempty"`
ToAccountTag string `json:"toAccountTag,omitempty"`
}

type UniversalTransferRes struct {
OrderId string `json:"orderId"`
}

// UniversalTransfer FlexTransfer
func (as *ApiService) UniversalTransfer(p *UniversalTransferReq) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v3/accounts/universal-transfer", p)
return as.Call(req)
}
24 changes: 24 additions & 0 deletions account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,27 @@ func TestApiService_SubAccountsV2(t *testing.T) {
}
}
}

func TestApiService_UniversalTransfer(t *testing.T) {
p := &UniversalTransferReq{
ClientOid: IntToString(time.Now().Unix()),
Type: "INTERNAL",
Currency: "USDT",
Amount: "5",
FromAccountType: "TRADE",
ToAccountType: "CONTRACT",
}
s := NewApiServiceFromEnv()
rsp, err := s.UniversalTransfer(p)
if err != nil {
t.Fatal(err)
}
v := &UniversalTransferRes{}
if err := rsp.ReadData(v); err != nil {
t.Fatal(err)
}
t.Log(ToJsonString(v))
if v.OrderId == "" {
t.Error("Empty key 'orderId'")
}
}
38 changes: 38 additions & 0 deletions currency.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kucoin

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

Expand Down Expand Up @@ -89,3 +90,40 @@ func (as *ApiService) Prices(base, currencies string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/prices", params)
return as.Call(req)
}

type CurrenciesV3Model []*CurrencyV3Model

type CurrencyV3Model struct {
Currency string `json:"currency"`
Name string `json:"name"`
FullName string `json:"fullName"`
Precision int32 `json:"precision"`
Confirms int32 `json:"confirms"`
ContractAddress string `json:"contractAddress"`
IsMarginEnabled bool `json:"isMarginEnabled"`
IsDebitEnabled bool `json:"isDebitEnabled"`
Chains []struct {
ChainName string `json:"chainName"`
WithdrawalMinFee json.Number `json:"withdrawalMinFee"`
WithdrawalMinSize json.Number `json:"withdrawalMinSize"`
WithdrawFeeRate json.Number `json:"withdrawFeeRate"`
DepositMinSize json.Number `json:"depositMinSize"`
IsWithdrawEnabled bool `json:"isWithdrawEnabled"`
IsDepositEnabled bool `json:"isDepositEnabled"`
PreConfirms int32 `json:"preConfirms"`
ContractAddress string `json:"contractAddress"`
ChainId string `json:"chainId"`
Confirms int32 `json:"confirms"`
} `json:"chains"`
}

func (as *ApiService) CurrenciesV3() (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v3/currencies/", nil)
return as.Call(req)
}

// CurrencyInfoV3 Request via this endpoint to get the currency details of a specified currency
func (as *ApiService) CurrencyInfoV3(currency string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v3/currencies/"+currency, nil)
return as.Call(req)
}
26 changes: 26 additions & 0 deletions currency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,29 @@ func TestApiService_Prices(t *testing.T) {
}
t.Log(ToJsonString(p))
}

func TestApiServiceCurrenciesV3(t *testing.T) {
s := NewApiServiceFromEnv()
rsp, err := s.CurrenciesV3()
if err != nil {
t.Fatal(err)
}
p := CurrenciesV3Model{}
if err := rsp.ReadData(&p); err != nil {
t.Fatal(err)
}
t.Log(ToJsonString(p))
}

func TestApiService_CurrencyInfoV3(t *testing.T) {
s := NewApiServiceFromEnv()
rsp, err := s.CurrencyInfoV3("BTC")
if err != nil {
t.Fatal(err)
}
p := CurrencyV3Model{}
if err := rsp.ReadData(&p); err != nil {
t.Fatal(err)
}
t.Log(ToJsonString(p))
}
215 changes: 215 additions & 0 deletions earn.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
package kucoin

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

type CreateEarnOrderReq struct {
ProductId string `json:"productId"`
Amount string `json:"amount"`
AccountType string `json:"accountType"`
}

type CreateEarnOrderRes struct {
OrderId string `json:"orderId"`
OrderTxId string `json:"orderTxId"`
}

// CreateEarnOrder subscribing to fixed income products. If the subscription fails, it returns the corresponding error code.
func (as *ApiService) CreateEarnOrder(createEarnOrderReq *CreateEarnOrderReq) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v1/earn/orders", createEarnOrderReq)
return as.Call(req)
}

type DeleteEarnOrderRes struct {
OrderTxId string `json:"orderTxId"`
DeliverTime int64 `json:"deliverTime"`
Status string `json:"status"`
Amount string `json:"amount"`
}

// DeleteEarnOrder initiating redemption by holding ID.
func (as *ApiService) DeleteEarnOrder(orderId, amount, fromAccountType, confirmPunishRedeem string) (*ApiResponse, error) {
p := map[string]string{
"orderId": orderId,
"fromAccountType": fromAccountType,
"confirmPunishRedeem": confirmPunishRedeem,
"amount": amount,
}
req := NewRequest(http.MethodDelete, "/api/v1/earn/orders", p)
return as.Call(req)
}

type RedeemPreviewModel struct {
Currency string `json:"currency"`
RedeemAmount json.Number `json:"redeemAmount"`
PenaltyInterestAmount json.Number `json:"penaltyInterestAmount"`
RedeemPeriod int32 `json:"redeemPeriod"`
DeliverTime int64 `json:"deliverTime"`
ManualRedeemable bool `json:"manualRedeemable"`
RedeemAll bool `json:"redeemAll"`
}

// RedeemPreview retrieves redemption preview information by holding ID
func (as *ApiService) RedeemPreview(orderId, fromAccountType string) (*ApiResponse, error) {
p := map[string]string{
"orderId": orderId,
"fromAccountType": fromAccountType,
}
req := NewRequest(http.MethodGet, "/api/v1/earn/redeem-preview", p)
return as.Call(req)
}

// QuerySavingProducts retrieves savings products.
func (as *ApiService) QuerySavingProducts(currency string) (*ApiResponse, error) {
p := map[string]string{
"currency": currency,
}
req := NewRequest(http.MethodGet, "/api/v1/earn/saving/products", p)
return as.Call(req)
}

type HoldAssetsRes []*HoldAssetModel

type HoldAssetModel struct {
OrderId string `json:"orderId"`
ProductId string `json:"productId"`
ProductCategory string `json:"productCategory"`
ProductType string `json:"productType"`
Currency string `json:"currency"`
IncomeCurrency string `json:"incomeCurrency"`
ReturnRate json.Number `json:"returnRate"`
HoldAmount json.Number `json:"holdAmount"`
RedeemedAmount json.Number `json:"redeemedAmount"`
RedeemingAmount json.Number `json:"redeemingAmount"`
LockStartTime int64 `json:"lockStartTime"`
LockEndTime int64 `json:"lockEndTime"`
PurchaseTime int64 `json:"purchaseTime"`
RedeemPeriod int32 `json:"redeemPeriod"`
Status string `json:"status"`
EarlyRedeemSupported int32 `json:"earlyRedeemSupported"`
}

// QueryHoldAssets retrieves current holding assets of fixed income products
func (as *ApiService) QueryHoldAssets(productId, productCategory, currency string, pagination *PaginationParam) (*ApiResponse, error) {
p := map[string]string{
"productId": productId,
"productCategory": productCategory,
"currency": currency,
}
pagination.ReadParam(p)
req := NewRequest(http.MethodGet, "/api/v1/earn/hold-assets", p)
return as.Call(req)
}

type EarnProductsRes []*EarnProductModel

type EarnProductModel struct {
Id string `json:"id"`
Currency string `json:"currency"`
Category string `json:"category"`
Type string `json:"type"`
Precision int32 `json:"precision"`
ProductUpperLimit string `json:"productUpperLimit"`
UserUpperLimit string `json:"userUpperLimit"`
UserLowerLimit string `json:"userLowerLimit"`
RedeemPeriod int `json:"redeemPeriod"`
LockStartTime int64 `json:"lockStartTime"`
LockEndTime int64 `json:"lockEndTime"`
ApplyStartTime int64 `json:"applyStartTime"`
ApplyEndTime int64 `json:"applyEndTime"`
ReturnRate json.Number `json:"returnRate"`
IncomeCurrency string `json:"incomeCurrency"`
EarlyRedeemSupported int32 `json:"earlyRedeemSupported"`
ProductRemainAmount json.Number `json:"productRemainAmount"`
Status string `json:"status"`
RedeemType string `json:"redeemType"`
IncomeReleaseType string `json:"incomeReleaseType"`
InterestDate int64 `json:"interestDate"`
Duration int32 `json:"duration"`
NewUserOnly int32 `json:"newUserOnly"`
}

// QueryPromotionProducts retrieves limited-time promotion products
func (as *ApiService) QueryPromotionProducts(currency string) (*ApiResponse, error) {
p := map[string]string{
"currency": currency,
}
req := NewRequest(http.MethodGet, "/api/v1/earn/promotion/products", p)
return as.Call(req)
}

// QueryKCSStakingProducts retrieves KCS Staking products
func (as *ApiService) QueryKCSStakingProducts(currency string) (*ApiResponse, error) {
p := map[string]string{
"currency": currency,
}
req := NewRequest(http.MethodGet, "/api/v1/earn/kcs-staking/products", p)
return as.Call(req)
}

// QueryStakingProducts retrieves Staking products
func (as *ApiService) QueryStakingProducts(currency string) (*ApiResponse, error) {
p := map[string]string{
"currency": currency,
}
req := NewRequest(http.MethodGet, "/api/v1/earn/staking/products", p)
return as.Call(req)
}

// QueryETHProducts retrieves ETH Staking products
func (as *ApiService) QueryETHProducts(currency string) (*ApiResponse, error) {
p := map[string]string{
"currency": currency,
}
req := NewRequest(http.MethodGet, "/api/v1/earn/eth-staking/products", p)
return as.Call(req)
}

type OTCLoanModel struct {
ParentUid string `json:"parentUid"`
Orders []struct {
OrderId string `json:"orderId"`
Currency string `json:"currency"`
Principal json.Number `json:"principal"`
Interest json.Number `json:"interest"`
} `json:"orders"`
Ltv struct {
TransferLtv json.Number `json:"transferLtv"`
OnlyClosePosLtv json.Number `json:"onlyClosePosLtv"`
DelayedLiquidationLtv json.Number `json:"delayedLiquidationLtv"`
InstantLiquidationLtv json.Number `json:"instantLiquidationLtv"`
CurrentLtv json.Number `json:"currentLtv"`
} `json:"ltv"`
TotalMarginAmount json.Number `json:"totalMarginAmount"`
TransferMarginAmount json.Number `json:"transferMarginAmount"`
Margins []struct {
MarginCcy string `json:"marginCcy"`
MarginQty json.Number `json:"marginQty"`
MarginFactor json.Number `json:"marginFactor"`
} `json:"margins"`
}

// QueryOTCLoanInfo querying accounts that are currently involved in loans.
func (as *ApiService) QueryOTCLoanInfo() (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/otc-loan/loan", nil)
return as.Call(req)
}

type OTCAccountsModel []*OTCAccountModel

type OTCAccountModel struct {
Uid string `json:"uid"`
MarginCcy string `json:"marginCcy"`
MarginQty string `json:"marginQty"`
MarginFactor string `json:"marginFactor"`
AccountType string `json:"accountType"`
IsParent bool `json:"isParent"`
}

// QueryOTCLoanAccountsInfo querying accounts that are currently involved in off-exchange funding and loans.
func (as *ApiService) QueryOTCLoanAccountsInfo() (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/otc-loan/accounts", nil)
return as.Call(req)
}
Loading

0 comments on commit 8c223ec

Please sign in to comment.