mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-14 02:53:50 +00:00
kucoin: export ApiClient interface methods
This commit is contained in:
parent
c390bbc31d
commit
4303342841
|
@ -14,12 +14,12 @@ type SubAccount struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AccountService) QuerySubAccounts() ([]SubAccount, error) {
|
func (s *AccountService) QuerySubAccounts() ([]SubAccount, error) {
|
||||||
req, err := s.client.newAuthenticatedRequest("GET", "/api/v1/sub/user", nil, nil)
|
req, err := s.client.NewAuthenticatedRequest("GET", "/api/v1/sub/user", nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := s.client.sendRequest(req)
|
response, err := s.client.SendRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -47,12 +47,12 @@ type Account struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AccountService) ListAccounts() ([]Account, error) {
|
func (s *AccountService) ListAccounts() ([]Account, error) {
|
||||||
req, err := s.client.newAuthenticatedRequest("GET", "/api/v1/accounts", nil, nil)
|
req, err := s.client.NewAuthenticatedRequest("GET", "/api/v1/accounts", nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := s.client.sendRequest(req)
|
response, err := s.client.SendRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -71,12 +71,12 @@ func (s *AccountService) ListAccounts() ([]Account, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AccountService) GetAccount(accountID string) (*Account, error) {
|
func (s *AccountService) GetAccount(accountID string) (*Account, error) {
|
||||||
req, err := s.client.newAuthenticatedRequest("GET", "/api/v1/accounts/"+accountID, nil, nil)
|
req, err := s.client.NewAuthenticatedRequest("GET", "/api/v1/accounts/"+accountID, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := s.client.sendRequest(req)
|
response, err := s.client.SendRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,14 @@ import (
|
||||||
|
|
||||||
// ApiClient defines the request builder method and request method for the API service
|
// ApiClient defines the request builder method and request method for the API service
|
||||||
type ApiClient interface {
|
type ApiClient interface {
|
||||||
// newAuthenticatedRequest builds up the http request for authentication-required endpoints
|
// NewAuthenticatedRequest builds up the http request for authentication-required endpoints
|
||||||
newAuthenticatedRequest(method, refURL string, params url.Values, payload interface{}) (*http.Request, error)
|
NewAuthenticatedRequest(method, refURL string, params url.Values, payload interface{}) (*http.Request, error)
|
||||||
|
|
||||||
// newRequest builds up the http request for public endpoints
|
// NewRequest builds up the http request for public endpoints
|
||||||
newRequest(method, refURL string, params url.Values, body []byte) (*http.Request, error)
|
NewRequest(method, refURL string, params url.Values, body []byte) (*http.Request, error)
|
||||||
|
|
||||||
// sendRequest sends the request object to the api gateway
|
// SendRequest sends the request object to the api gateway
|
||||||
sendRequest(req *http.Request) (*util.Response, error)
|
SendRequest(req *http.Request) (*util.Response, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type BulletService struct {
|
type BulletService struct {
|
||||||
|
@ -49,12 +49,12 @@ type Bullet struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *GetPublicBulletRequest) Do(ctx context.Context) (*Bullet, error) {
|
func (r *GetPublicBulletRequest) Do(ctx context.Context) (*Bullet, error) {
|
||||||
req, err := r.client.newRequest("POST", "/api/v1/bullet-public", nil, nil)
|
req, err := r.client.NewRequest("POST", "/api/v1/bullet-public", nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := r.client.sendRequest(req)
|
response, err := r.client.SendRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -78,12 +78,12 @@ type GetPrivateBulletRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *GetPrivateBulletRequest) Do(ctx context.Context) (*Bullet, error) {
|
func (r *GetPrivateBulletRequest) Do(ctx context.Context) (*Bullet, error) {
|
||||||
req, err := r.client.newAuthenticatedRequest("POST", "/api/v1/bullet-private", nil, nil)
|
req, err := r.client.NewAuthenticatedRequest("POST", "/api/v1/bullet-private", nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := r.client.sendRequest(req)
|
response, err := r.client.SendRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ func (c *RestClient) Auth(key, secret, passphrase string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRequest create new API request. Relative url can be provided in refURL.
|
// NewRequest create new API request. Relative url can be provided in refURL.
|
||||||
func (c *RestClient) newRequest(method, refURL string, params url.Values, body []byte) (*http.Request, error) {
|
func (c *RestClient) NewRequest(method, refURL string, params url.Values, body []byte) (*http.Request, error) {
|
||||||
rel, err := url.Parse(refURL)
|
rel, err := url.Parse(refURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -77,7 +77,7 @@ func (c *RestClient) newRequest(method, refURL string, params url.Values, body [
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendRequest sends the request to the API server and handle the response
|
// sendRequest sends the request to the API server and handle the response
|
||||||
func (c *RestClient) sendRequest(req *http.Request) (*util.Response, error) {
|
func (c *RestClient) SendRequest(req *http.Request) (*util.Response, error) {
|
||||||
resp, err := c.client.Do(req)
|
resp, err := c.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -98,7 +98,7 @@ func (c *RestClient) sendRequest(req *http.Request) (*util.Response, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// newAuthenticatedRequest creates new http request for authenticated routes.
|
// newAuthenticatedRequest creates new http request for authenticated routes.
|
||||||
func (c *RestClient) newAuthenticatedRequest(method, refURL string, params url.Values, payload interface{}) (*http.Request, error) {
|
func (c *RestClient) NewAuthenticatedRequest(method, refURL string, params url.Values, payload interface{}) (*http.Request, error) {
|
||||||
if len(c.Key) == 0 {
|
if len(c.Key) == 0 {
|
||||||
return nil, errors.New("empty api key")
|
return nil, errors.New("empty api key")
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,12 +41,12 @@ func (s *MarketDataService) ListSymbols(market ...string) ([]Symbol, error) {
|
||||||
return nil, errors.New("symbols api only supports one market parameter")
|
return nil, errors.New("symbols api only supports one market parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := s.client.newRequest("GET", "/api/v1/symbols", params, nil)
|
req, err := s.client.NewRequest("GET", "/api/v1/symbols", params, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := s.client.sendRequest(req)
|
response, err := s.client.SendRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -91,12 +91,12 @@ func (s *MarketDataService) GetTicker(symbol string) (*Ticker, error) {
|
||||||
var params = url.Values{}
|
var params = url.Values{}
|
||||||
params["symbol"] = []string{symbol}
|
params["symbol"] = []string{symbol}
|
||||||
|
|
||||||
req, err := s.client.newRequest("GET", "/api/v1/market/orderbook/level1", params, nil)
|
req, err := s.client.NewRequest("GET", "/api/v1/market/orderbook/level1", params, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := s.client.sendRequest(req)
|
response, err := s.client.SendRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -169,12 +169,12 @@ type AllTickers struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MarketDataService) ListTickers() (*AllTickers, error) {
|
func (s *MarketDataService) ListTickers() (*AllTickers, error) {
|
||||||
req, err := s.client.newRequest("GET", "/api/v1/market/allTickers", nil, nil)
|
req, err := s.client.NewRequest("GET", "/api/v1/market/allTickers", nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := s.client.sendRequest(req)
|
response, err := s.client.SendRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -196,12 +196,12 @@ func (s *MarketDataService) GetTicker24HStat(symbol string) (*Ticker24H, error)
|
||||||
var params = url.Values{}
|
var params = url.Values{}
|
||||||
params.Add("symbol", symbol)
|
params.Add("symbol", symbol)
|
||||||
|
|
||||||
req, err := s.client.newRequest("GET", "/api/v1/market/stats", params, nil)
|
req, err := s.client.NewRequest("GET", "/api/v1/market/stats", params, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := s.client.sendRequest(req)
|
response, err := s.client.SendRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -246,14 +246,14 @@ func (s *MarketDataService) GetOrderBook(symbol string, depth int) (*OrderBook,
|
||||||
switch depth {
|
switch depth {
|
||||||
case 20, 100:
|
case 20, 100:
|
||||||
refURL := "/api/v1/market/orderbook/level2_" + strconv.Itoa(depth)
|
refURL := "/api/v1/market/orderbook/level2_" + strconv.Itoa(depth)
|
||||||
req, err = s.client.newRequest("GET", refURL, params, nil)
|
req, err = s.client.NewRequest("GET", refURL, params, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
refURL := "/api/v3/market/orderbook/level2"
|
refURL := "/api/v3/market/orderbook/level2"
|
||||||
req, err = s.client.newAuthenticatedRequest("GET", refURL, params, nil)
|
req, err = s.client.NewAuthenticatedRequest("GET", refURL, params, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ func (s *MarketDataService) GetOrderBook(symbol string, depth int) (*OrderBook,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := s.client.sendRequest(req)
|
response, err := s.client.SendRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,12 +100,12 @@ func (r *GetFillsRequest) Do(ctx context.Context) (*FillListPage, error) {
|
||||||
params.Add("tradeType", "TRADE")
|
params.Add("tradeType", "TRADE")
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := r.client.newAuthenticatedRequest("GET", "/api/v1/fills", params, nil)
|
req, err := r.client.NewAuthenticatedRequest("GET", "/api/v1/fills", params, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := r.client.sendRequest(req)
|
response, err := r.client.SendRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -192,12 +192,12 @@ func (r *ListOrdersRequest) Do(ctx context.Context) (*OrderListPage, error) {
|
||||||
params.Add("tradeType", "TRADE")
|
params.Add("tradeType", "TRADE")
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := r.client.newAuthenticatedRequest("GET", "/api/v1/orders", params, nil)
|
req, err := r.client.NewAuthenticatedRequest("GET", "/api/v1/orders", params, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := r.client.sendRequest(req)
|
response, err := r.client.SendRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -254,12 +254,12 @@ func (r *PlaceOrderRequest) Do(ctx context.Context) (*OrderResponse, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := r.client.newAuthenticatedRequest("POST", "/api/v1/orders", nil, payload)
|
req, err := r.client.NewAuthenticatedRequest("POST", "/api/v1/orders", nil, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := r.client.sendRequest(req)
|
response, err := r.client.SendRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -310,12 +310,12 @@ func (r *CancelOrderRequest) Do(ctx context.Context) (*CancelOrderResponse, erro
|
||||||
refURL = "/api/v1/order/client-order/" + *r.clientOrderID
|
refURL = "/api/v1/order/client-order/" + *r.clientOrderID
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := r.client.newAuthenticatedRequest("DELETE", refURL, nil, nil)
|
req, err := r.client.NewAuthenticatedRequest("DELETE", refURL, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := r.client.sendRequest(req)
|
response, err := r.client.SendRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -350,12 +350,12 @@ func (r *CancelAllOrderRequest) Do(ctx context.Context) (*CancelOrderResponse, e
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := r.client.newAuthenticatedRequest("DELETE", "/api/v1/orders", params, nil)
|
req, err := r.client.NewAuthenticatedRequest("DELETE", "/api/v1/orders", params, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := r.client.sendRequest(req)
|
response, err := r.client.SendRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -413,12 +413,12 @@ func (r *BatchPlaceOrderRequest) Do(ctx context.Context) ([]OrderResponse, error
|
||||||
"orderList": orderList,
|
"orderList": orderList,
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := r.client.newAuthenticatedRequest("POST", "/api/v1/orders/multi", nil, payload)
|
req, err := r.client.NewAuthenticatedRequest("POST", "/api/v1/orders/multi", nil, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := r.client.sendRequest(req)
|
response, err := r.client.SendRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user