diff --git a/pkg/exchange/kucoin/kucoinapi/cancel_all_order_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/cancel_all_order_request_requestgen.go index 873cd7569..052a5fd06 100644 --- a/pkg/exchange/kucoin/kucoinapi/cancel_all_order_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/cancel_all_order_request_requestgen.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "net/url" + "regexp" ) func (r *CancelAllOrderRequest) Symbol(symbol string) *CancelAllOrderRequest { @@ -76,3 +77,33 @@ func (r *CancelAllOrderRequest) GetParametersJSON() ([]byte, error) { return json.Marshal(params) } + +// GetSlugParameters builds and checks the slug parameters and return the result in a map object +func (r *CancelAllOrderRequest) GetSlugParameters() (map[string]interface{}, error) { + var params = map[string]interface{}{} + + return params, nil +} + +func (r *CancelAllOrderRequest) applySlugsToUrl(url string, slugs map[string]string) string { + for k, v := range slugs { + needleRE := regexp.MustCompile(":" + k + "\\b") + url = needleRE.ReplaceAllString(url, v) + } + + return url +} + +func (r *CancelAllOrderRequest) GetSlugsMap() (map[string]string, error) { + slugs := map[string]string{} + params, err := r.GetSlugParameters() + if err != nil { + return slugs, nil + } + + for k, v := range params { + slugs[k] = fmt.Sprintf("%v", v) + } + + return slugs, nil +} diff --git a/pkg/exchange/kucoin/kucoinapi/cancel_order_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/cancel_order_request_requestgen.go index f405d148e..232567527 100644 --- a/pkg/exchange/kucoin/kucoinapi/cancel_order_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/cancel_order_request_requestgen.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "net/url" + "regexp" ) func (r *CancelOrderRequest) OrderID(orderID string) *CancelOrderRequest { @@ -76,3 +77,33 @@ func (r *CancelOrderRequest) GetParametersJSON() ([]byte, error) { return json.Marshal(params) } + +// GetSlugParameters builds and checks the slug parameters and return the result in a map object +func (r *CancelOrderRequest) GetSlugParameters() (map[string]interface{}, error) { + var params = map[string]interface{}{} + + return params, nil +} + +func (r *CancelOrderRequest) applySlugsToUrl(url string, slugs map[string]string) string { + for k, v := range slugs { + needleRE := regexp.MustCompile(":" + k + "\\b") + url = needleRE.ReplaceAllString(url, v) + } + + return url +} + +func (r *CancelOrderRequest) GetSlugsMap() (map[string]string, error) { + slugs := map[string]string{} + params, err := r.GetSlugParameters() + if err != nil { + return slugs, nil + } + + for k, v := range params { + slugs[k] = fmt.Sprintf("%v", v) + } + + return slugs, nil +} diff --git a/pkg/exchange/kucoin/kucoinapi/get_all_tickers_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/get_all_tickers_request_requestgen.go index 8f5b9dba9..f633ac0ad 100644 --- a/pkg/exchange/kucoin/kucoinapi/get_all_tickers_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/get_all_tickers_request_requestgen.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "net/url" + "regexp" ) // GetQueryParameters builds and checks the query parameters and returns url.Values @@ -54,13 +55,45 @@ func (g *GetAllTickersRequest) GetParametersJSON() ([]byte, error) { return json.Marshal(params) } +// GetSlugParameters builds and checks the slug parameters and return the result in a map object +func (g *GetAllTickersRequest) GetSlugParameters() (map[string]interface{}, error) { + var params = map[string]interface{}{} + + return params, nil +} + +func (g *GetAllTickersRequest) applySlugsToUrl(url string, slugs map[string]string) string { + for k, v := range slugs { + needleRE := regexp.MustCompile(":" + k + "\\b") + url = needleRE.ReplaceAllString(url, v) + } + + return url +} + +func (g *GetAllTickersRequest) GetSlugsMap() (map[string]string, error) { + slugs := map[string]string{} + params, err := g.GetSlugParameters() + if err != nil { + return slugs, nil + } + + for k, v := range params { + slugs[k] = fmt.Sprintf("%v", v) + } + + return slugs, nil +} + func (g *GetAllTickersRequest) Do(ctx context.Context) (*AllTickers, error) { // no body params var params interface{} query := url.Values{} - req, err := g.client.NewRequest(ctx, "GET", "/api/v1/market/allTickers", query, params) + apiURL := "/api/v1/market/allTickers" + + req, err := g.client.NewRequest(ctx, "GET", apiURL, query, params) if err != nil { return nil, err } diff --git a/pkg/exchange/kucoin/kucoinapi/get_fills_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/get_fills_request_requestgen.go index ef8f88d9d..12cbdb2e0 100644 --- a/pkg/exchange/kucoin/kucoinapi/get_fills_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/get_fills_request_requestgen.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "net/url" + "regexp" "strconv" "time" ) @@ -146,3 +147,33 @@ func (r *GetFillsRequest) GetParametersJSON() ([]byte, error) { return json.Marshal(params) } + +// GetSlugParameters builds and checks the slug parameters and return the result in a map object +func (r *GetFillsRequest) GetSlugParameters() (map[string]interface{}, error) { + var params = map[string]interface{}{} + + return params, nil +} + +func (r *GetFillsRequest) applySlugsToUrl(url string, slugs map[string]string) string { + for k, v := range slugs { + needleRE := regexp.MustCompile(":" + k + "\\b") + url = needleRE.ReplaceAllString(url, v) + } + + return url +} + +func (r *GetFillsRequest) GetSlugsMap() (map[string]string, error) { + slugs := map[string]string{} + params, err := r.GetSlugParameters() + if err != nil { + return slugs, nil + } + + for k, v := range params { + slugs[k] = fmt.Sprintf("%v", v) + } + + return slugs, nil +} diff --git a/pkg/exchange/kucoin/kucoinapi/get_k_lines_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/get_k_lines_request_requestgen.go index 41d3a2b31..839f2fa8f 100644 --- a/pkg/exchange/kucoin/kucoinapi/get_k_lines_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/get_k_lines_request_requestgen.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "net/url" + "regexp" "strconv" "time" ) @@ -109,3 +110,33 @@ func (r *GetKLinesRequest) GetParametersJSON() ([]byte, error) { return json.Marshal(params) } + +// GetSlugParameters builds and checks the slug parameters and return the result in a map object +func (r *GetKLinesRequest) GetSlugParameters() (map[string]interface{}, error) { + var params = map[string]interface{}{} + + return params, nil +} + +func (r *GetKLinesRequest) applySlugsToUrl(url string, slugs map[string]string) string { + for k, v := range slugs { + needleRE := regexp.MustCompile(":" + k + "\\b") + url = needleRE.ReplaceAllString(url, v) + } + + return url +} + +func (r *GetKLinesRequest) GetSlugsMap() (map[string]string, error) { + slugs := map[string]string{} + params, err := r.GetSlugParameters() + if err != nil { + return slugs, nil + } + + for k, v := range params { + slugs[k] = fmt.Sprintf("%v", v) + } + + return slugs, nil +} diff --git a/pkg/exchange/kucoin/kucoinapi/get_order_book_level_2_depth_100_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/get_order_book_level_2_depth_100_request_requestgen.go index 4a6f42cd0..7a770352f 100644 --- a/pkg/exchange/kucoin/kucoinapi/get_order_book_level_2_depth_100_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/get_order_book_level_2_depth_100_request_requestgen.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "net/url" + "regexp" ) func (g *GetOrderBookLevel2Depth100Request) Symbol(symbol string) *GetOrderBookLevel2Depth100Request { @@ -64,6 +65,36 @@ func (g *GetOrderBookLevel2Depth100Request) GetParametersJSON() ([]byte, error) return json.Marshal(params) } +// GetSlugParameters builds and checks the slug parameters and return the result in a map object +func (g *GetOrderBookLevel2Depth100Request) GetSlugParameters() (map[string]interface{}, error) { + var params = map[string]interface{}{} + + return params, nil +} + +func (g *GetOrderBookLevel2Depth100Request) applySlugsToUrl(url string, slugs map[string]string) string { + for k, v := range slugs { + needleRE := regexp.MustCompile(":" + k + "\\b") + url = needleRE.ReplaceAllString(url, v) + } + + return url +} + +func (g *GetOrderBookLevel2Depth100Request) GetSlugsMap() (map[string]string, error) { + slugs := map[string]string{} + params, err := g.GetSlugParameters() + if err != nil { + return slugs, nil + } + + for k, v := range params { + slugs[k] = fmt.Sprintf("%v", v) + } + + return slugs, nil +} + func (g *GetOrderBookLevel2Depth100Request) Do(ctx context.Context) (*OrderBook, error) { // no body params @@ -73,7 +104,9 @@ func (g *GetOrderBookLevel2Depth100Request) Do(ctx context.Context) (*OrderBook, return nil, err } - req, err := g.client.NewRequest(ctx, "GET", "/api/v1/market/orderbook/level2_100", query, params) + apiURL := "/api/v1/market/orderbook/level2_100" + + req, err := g.client.NewRequest(ctx, "GET", apiURL, query, params) if err != nil { return nil, err } diff --git a/pkg/exchange/kucoin/kucoinapi/get_order_book_level_2_depth_20_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/get_order_book_level_2_depth_20_request_requestgen.go index ce45dcfb8..871a89340 100644 --- a/pkg/exchange/kucoin/kucoinapi/get_order_book_level_2_depth_20_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/get_order_book_level_2_depth_20_request_requestgen.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "net/url" + "regexp" ) func (g *GetOrderBookLevel2Depth20Request) Symbol(symbol string) *GetOrderBookLevel2Depth20Request { @@ -64,6 +65,36 @@ func (g *GetOrderBookLevel2Depth20Request) GetParametersJSON() ([]byte, error) { return json.Marshal(params) } +// GetSlugParameters builds and checks the slug parameters and return the result in a map object +func (g *GetOrderBookLevel2Depth20Request) GetSlugParameters() (map[string]interface{}, error) { + var params = map[string]interface{}{} + + return params, nil +} + +func (g *GetOrderBookLevel2Depth20Request) applySlugsToUrl(url string, slugs map[string]string) string { + for k, v := range slugs { + needleRE := regexp.MustCompile(":" + k + "\\b") + url = needleRE.ReplaceAllString(url, v) + } + + return url +} + +func (g *GetOrderBookLevel2Depth20Request) GetSlugsMap() (map[string]string, error) { + slugs := map[string]string{} + params, err := g.GetSlugParameters() + if err != nil { + return slugs, nil + } + + for k, v := range params { + slugs[k] = fmt.Sprintf("%v", v) + } + + return slugs, nil +} + func (g *GetOrderBookLevel2Depth20Request) Do(ctx context.Context) (*OrderBook, error) { // no body params @@ -73,7 +104,9 @@ func (g *GetOrderBookLevel2Depth20Request) Do(ctx context.Context) (*OrderBook, return nil, err } - req, err := g.client.NewRequest(ctx, "GET", "/api/v1/market/orderbook/level2_20", query, params) + apiURL := "/api/v1/market/orderbook/level2_20" + + req, err := g.client.NewRequest(ctx, "GET", apiURL, query, params) if err != nil { return nil, err } diff --git a/pkg/exchange/kucoin/kucoinapi/get_order_book_level_2_depth_all_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/get_order_book_level_2_depth_all_request_requestgen.go index ed49e62c4..b71792b96 100644 --- a/pkg/exchange/kucoin/kucoinapi/get_order_book_level_2_depth_all_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/get_order_book_level_2_depth_all_request_requestgen.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "net/url" + "regexp" ) func (g *GetOrderBookLevel2DepthAllRequest) Symbol(symbol string) *GetOrderBookLevel2DepthAllRequest { @@ -64,6 +65,36 @@ func (g *GetOrderBookLevel2DepthAllRequest) GetParametersJSON() ([]byte, error) return json.Marshal(params) } +// GetSlugParameters builds and checks the slug parameters and return the result in a map object +func (g *GetOrderBookLevel2DepthAllRequest) GetSlugParameters() (map[string]interface{}, error) { + var params = map[string]interface{}{} + + return params, nil +} + +func (g *GetOrderBookLevel2DepthAllRequest) applySlugsToUrl(url string, slugs map[string]string) string { + for k, v := range slugs { + needleRE := regexp.MustCompile(":" + k + "\\b") + url = needleRE.ReplaceAllString(url, v) + } + + return url +} + +func (g *GetOrderBookLevel2DepthAllRequest) GetSlugsMap() (map[string]string, error) { + slugs := map[string]string{} + params, err := g.GetSlugParameters() + if err != nil { + return slugs, nil + } + + for k, v := range params { + slugs[k] = fmt.Sprintf("%v", v) + } + + return slugs, nil +} + func (g *GetOrderBookLevel2DepthAllRequest) Do(ctx context.Context) (*OrderBook, error) { // no body params @@ -73,7 +104,9 @@ func (g *GetOrderBookLevel2DepthAllRequest) Do(ctx context.Context) (*OrderBook, return nil, err } - req, err := g.client.NewAuthenticatedRequest(ctx, "GET", "/api/v3/market/orderbook/level2", query, params) + apiURL := "/api/v3/market/orderbook/level2" + + req, err := g.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params) if err != nil { return nil, err } diff --git a/pkg/exchange/kucoin/kucoinapi/get_private_bullet_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/get_private_bullet_request_requestgen.go index bfde85600..535d46ed8 100644 --- a/pkg/exchange/kucoin/kucoinapi/get_private_bullet_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/get_private_bullet_request_requestgen.go @@ -5,16 +5,95 @@ package kucoinapi import ( "context" "encoding/json" + "fmt" "net/url" + "regexp" ) +// GetQueryParameters builds and checks the query parameters and returns url.Values +func (g *GetPrivateBulletRequest) GetQueryParameters() (url.Values, error) { + var params = map[string]interface{}{} + + query := url.Values{} + for k, v := range params { + query.Add(k, fmt.Sprintf("%v", v)) + } + + return query, nil +} + +// GetParameters builds and checks the parameters and return the result in a map object +func (g *GetPrivateBulletRequest) GetParameters() (map[string]interface{}, error) { + var params = map[string]interface{}{} + + return params, nil +} + +// GetParametersQuery converts the parameters from GetParameters into the url.Values format +func (g *GetPrivateBulletRequest) GetParametersQuery() (url.Values, error) { + query := url.Values{} + + params, err := g.GetParameters() + if err != nil { + return query, err + } + + for k, v := range params { + query.Add(k, fmt.Sprintf("%v", v)) + } + + return query, nil +} + +// GetParametersJSON converts the parameters from GetParameters into the JSON format +func (g *GetPrivateBulletRequest) GetParametersJSON() ([]byte, error) { + params, err := g.GetParameters() + if err != nil { + return nil, err + } + + return json.Marshal(params) +} + +// GetSlugParameters builds and checks the slug parameters and return the result in a map object +func (g *GetPrivateBulletRequest) GetSlugParameters() (map[string]interface{}, error) { + var params = map[string]interface{}{} + + return params, nil +} + +func (g *GetPrivateBulletRequest) applySlugsToUrl(url string, slugs map[string]string) string { + for k, v := range slugs { + needleRE := regexp.MustCompile(":" + k + "\\b") + url = needleRE.ReplaceAllString(url, v) + } + + return url +} + +func (g *GetPrivateBulletRequest) GetSlugsMap() (map[string]string, error) { + slugs := map[string]string{} + params, err := g.GetSlugParameters() + if err != nil { + return slugs, nil + } + + for k, v := range params { + slugs[k] = fmt.Sprintf("%v", v) + } + + return slugs, nil +} + func (g *GetPrivateBulletRequest) Do(ctx context.Context) (*Bullet, error) { // no body params var params interface{} query := url.Values{} - req, err := g.client.NewAuthenticatedRequest(ctx, "POST", "/api/v1/bullet-private", query, params) + apiURL := "/api/v1/bullet-private" + + req, err := g.client.NewAuthenticatedRequest(ctx, "POST", apiURL, query, params) if err != nil { return nil, err } diff --git a/pkg/exchange/kucoin/kucoinapi/get_public_bullet_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/get_public_bullet_request_requestgen.go index c8a173d4c..c7b8aba98 100644 --- a/pkg/exchange/kucoin/kucoinapi/get_public_bullet_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/get_public_bullet_request_requestgen.go @@ -5,16 +5,95 @@ package kucoinapi import ( "context" "encoding/json" + "fmt" "net/url" + "regexp" ) +// GetQueryParameters builds and checks the query parameters and returns url.Values +func (g *GetPublicBulletRequest) GetQueryParameters() (url.Values, error) { + var params = map[string]interface{}{} + + query := url.Values{} + for k, v := range params { + query.Add(k, fmt.Sprintf("%v", v)) + } + + return query, nil +} + +// GetParameters builds and checks the parameters and return the result in a map object +func (g *GetPublicBulletRequest) GetParameters() (map[string]interface{}, error) { + var params = map[string]interface{}{} + + return params, nil +} + +// GetParametersQuery converts the parameters from GetParameters into the url.Values format +func (g *GetPublicBulletRequest) GetParametersQuery() (url.Values, error) { + query := url.Values{} + + params, err := g.GetParameters() + if err != nil { + return query, err + } + + for k, v := range params { + query.Add(k, fmt.Sprintf("%v", v)) + } + + return query, nil +} + +// GetParametersJSON converts the parameters from GetParameters into the JSON format +func (g *GetPublicBulletRequest) GetParametersJSON() ([]byte, error) { + params, err := g.GetParameters() + if err != nil { + return nil, err + } + + return json.Marshal(params) +} + +// GetSlugParameters builds and checks the slug parameters and return the result in a map object +func (g *GetPublicBulletRequest) GetSlugParameters() (map[string]interface{}, error) { + var params = map[string]interface{}{} + + return params, nil +} + +func (g *GetPublicBulletRequest) applySlugsToUrl(url string, slugs map[string]string) string { + for k, v := range slugs { + needleRE := regexp.MustCompile(":" + k + "\\b") + url = needleRE.ReplaceAllString(url, v) + } + + return url +} + +func (g *GetPublicBulletRequest) GetSlugsMap() (map[string]string, error) { + slugs := map[string]string{} + params, err := g.GetSlugParameters() + if err != nil { + return slugs, nil + } + + for k, v := range params { + slugs[k] = fmt.Sprintf("%v", v) + } + + return slugs, nil +} + func (g *GetPublicBulletRequest) Do(ctx context.Context) (*Bullet, error) { // no body params var params interface{} query := url.Values{} - req, err := g.client.NewRequest(ctx, "POST", "/api/v1/bullet-public", query, params) + apiURL := "/api/v1/bullet-public" + + req, err := g.client.NewRequest(ctx, "POST", apiURL, query, params) if err != nil { return nil, err } diff --git a/pkg/exchange/kucoin/kucoinapi/get_ticker_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/get_ticker_request_requestgen.go index 4b7a7d93d..761f725e8 100644 --- a/pkg/exchange/kucoin/kucoinapi/get_ticker_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/get_ticker_request_requestgen.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "net/url" + "regexp" ) func (g *GetTickerRequest) Symbol(symbol string) *GetTickerRequest { @@ -64,6 +65,36 @@ func (g *GetTickerRequest) GetParametersJSON() ([]byte, error) { return json.Marshal(params) } +// GetSlugParameters builds and checks the slug parameters and return the result in a map object +func (g *GetTickerRequest) GetSlugParameters() (map[string]interface{}, error) { + var params = map[string]interface{}{} + + return params, nil +} + +func (g *GetTickerRequest) applySlugsToUrl(url string, slugs map[string]string) string { + for k, v := range slugs { + needleRE := regexp.MustCompile(":" + k + "\\b") + url = needleRE.ReplaceAllString(url, v) + } + + return url +} + +func (g *GetTickerRequest) GetSlugsMap() (map[string]string, error) { + slugs := map[string]string{} + params, err := g.GetSlugParameters() + if err != nil { + return slugs, nil + } + + for k, v := range params { + slugs[k] = fmt.Sprintf("%v", v) + } + + return slugs, nil +} + func (g *GetTickerRequest) Do(ctx context.Context) (*Ticker, error) { // no body params @@ -73,7 +104,9 @@ func (g *GetTickerRequest) Do(ctx context.Context) (*Ticker, error) { return nil, err } - req, err := g.client.NewRequest(ctx, "GET", "/api/v1/market/orderbook/level1", query, params) + apiURL := "/api/v1/market/orderbook/level1" + + req, err := g.client.NewRequest(ctx, "GET", apiURL, query, params) if err != nil { return nil, err } diff --git a/pkg/exchange/kucoin/kucoinapi/list_orders_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/list_orders_request_requestgen.go index 2606246c6..565e4ec50 100644 --- a/pkg/exchange/kucoin/kucoinapi/list_orders_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/list_orders_request_requestgen.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "net/url" + "regexp" "strconv" "time" ) @@ -158,3 +159,33 @@ func (r *ListOrdersRequest) GetParametersJSON() ([]byte, error) { return json.Marshal(params) } + +// GetSlugParameters builds and checks the slug parameters and return the result in a map object +func (r *ListOrdersRequest) GetSlugParameters() (map[string]interface{}, error) { + var params = map[string]interface{}{} + + return params, nil +} + +func (r *ListOrdersRequest) applySlugsToUrl(url string, slugs map[string]string) string { + for k, v := range slugs { + needleRE := regexp.MustCompile(":" + k + "\\b") + url = needleRE.ReplaceAllString(url, v) + } + + return url +} + +func (r *ListOrdersRequest) GetSlugsMap() (map[string]string, error) { + slugs := map[string]string{} + params, err := r.GetSlugParameters() + if err != nil { + return slugs, nil + } + + for k, v := range params { + slugs[k] = fmt.Sprintf("%v", v) + } + + return slugs, nil +} diff --git a/pkg/exchange/kucoin/kucoinapi/list_symbols_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/list_symbols_request_requestgen.go index 766442e64..fa4675c1a 100644 --- a/pkg/exchange/kucoin/kucoinapi/list_symbols_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/list_symbols_request_requestgen.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "net/url" + "regexp" ) func (l *ListSymbolsRequest) Market(market string) *ListSymbolsRequest { @@ -66,13 +67,45 @@ func (l *ListSymbolsRequest) GetParametersJSON() ([]byte, error) { return json.Marshal(params) } +// GetSlugParameters builds and checks the slug parameters and return the result in a map object +func (l *ListSymbolsRequest) GetSlugParameters() (map[string]interface{}, error) { + var params = map[string]interface{}{} + + return params, nil +} + +func (l *ListSymbolsRequest) applySlugsToUrl(url string, slugs map[string]string) string { + for k, v := range slugs { + needleRE := regexp.MustCompile(":" + k + "\\b") + url = needleRE.ReplaceAllString(url, v) + } + + return url +} + +func (l *ListSymbolsRequest) GetSlugsMap() (map[string]string, error) { + slugs := map[string]string{} + params, err := l.GetSlugParameters() + if err != nil { + return slugs, nil + } + + for k, v := range params { + slugs[k] = fmt.Sprintf("%v", v) + } + + return slugs, nil +} + func (l *ListSymbolsRequest) Do(ctx context.Context) ([]Symbol, error) { // empty params for GET operation var params interface{} query := url.Values{} - req, err := l.client.NewRequest(ctx, "GET", "/api/v1/symbols", query, params) + apiURL := "/api/v1/symbols" + + req, err := l.client.NewRequest(ctx, "GET", apiURL, query, params) if err != nil { return nil, err } diff --git a/pkg/exchange/kucoin/kucoinapi/place_order_request_requestgen.go b/pkg/exchange/kucoin/kucoinapi/place_order_request_requestgen.go index 378597817..3d2813bc7 100644 --- a/pkg/exchange/kucoin/kucoinapi/place_order_request_requestgen.go +++ b/pkg/exchange/kucoin/kucoinapi/place_order_request_requestgen.go @@ -1,12 +1,14 @@ -// Code generated by "requestgen -type PlaceOrderRequest"; DO NOT EDIT. +// Code generated by "requestgen -method POST -responseType .APIResponse -responseDataField Data -url /api/v1/orders -type PlaceOrderRequest -responseDataType .OrderResponse"; DO NOT EDIT. package kucoinapi import ( + "context" "encoding/json" "fmt" "github.com/google/uuid" "net/url" + "regexp" ) func (r *PlaceOrderRequest) ClientOrderID(clientOrderID string) *PlaceOrderRequest { @@ -81,6 +83,7 @@ func (r *PlaceOrderRequest) GetParameters() (map[string]interface{}, error) { // assign parameter of clientOrderID params["clientOid"] = clientOrderID + } // check symbol field -> json key symbol symbol := r.symbol @@ -164,3 +167,64 @@ func (r *PlaceOrderRequest) GetParametersJSON() ([]byte, error) { return json.Marshal(params) } + +// GetSlugParameters builds and checks the slug parameters and return the result in a map object +func (r *PlaceOrderRequest) GetSlugParameters() (map[string]interface{}, error) { + var params = map[string]interface{}{} + + return params, nil +} + +func (r *PlaceOrderRequest) applySlugsToUrl(url string, slugs map[string]string) string { + for k, v := range slugs { + needleRE := regexp.MustCompile(":" + k + "\\b") + url = needleRE.ReplaceAllString(url, v) + } + + return url +} + +func (r *PlaceOrderRequest) GetSlugsMap() (map[string]string, error) { + slugs := map[string]string{} + params, err := r.GetSlugParameters() + if err != nil { + return slugs, nil + } + + for k, v := range params { + slugs[k] = fmt.Sprintf("%v", v) + } + + return slugs, nil +} + +func (r *PlaceOrderRequest) Do(ctx context.Context) (*OrderResponse, error) { + + params, err := r.GetParameters() + if err != nil { + return nil, err + } + query := url.Values{} + + apiURL := "/api/v1/orders" + + req, err := r.client.NewAuthenticatedRequest(ctx, "POST", apiURL, query, params) + if err != nil { + return nil, err + } + + response, err := r.client.SendRequest(req) + if err != nil { + return nil, err + } + + var apiResponse APIResponse + if err := response.DecodeJSON(&apiResponse); err != nil { + return nil, err + } + var data OrderResponse + if err := json.Unmarshal(apiResponse.Data, &data); err != nil { + return nil, err + } + return &data, nil +} diff --git a/pkg/exchange/kucoin/kucoinapi/trade.go b/pkg/exchange/kucoin/kucoinapi/trade.go index ed12dc629..7322d5d14 100644 --- a/pkg/exchange/kucoin/kucoinapi/trade.go +++ b/pkg/exchange/kucoin/kucoinapi/trade.go @@ -7,6 +7,7 @@ import ( "context" "time" + "github.com/c9s/requestgen" "github.com/pkg/errors" "github.com/c9s/bbgo/pkg/fixedpoint" @@ -229,9 +230,9 @@ func (c *TradeService) NewListOrdersRequest() *ListOrdersRequest { return &ListOrdersRequest{client: c.client} } -//go:generate requestgen -type PlaceOrderRequest +//go:generate PostRequest -url /api/v1/orders -type PlaceOrderRequest -responseDataType .OrderResponse type PlaceOrderRequest struct { - client *RestClient + client requestgen.AuthenticatedAPIClient // A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters. clientOrderID *string `param:"clientOid,required" defaultValuer:"uuid()"` @@ -254,39 +255,6 @@ type PlaceOrderRequest struct { timeInForce *TimeInForceType `param:"timeInForce,required"` } -func (r *PlaceOrderRequest) Do(ctx context.Context) (*OrderResponse, error) { - payload, err := r.GetParameters() - if err != nil { - return nil, err - } - - req, err := r.client.NewAuthenticatedRequest(ctx, "POST", "/api/v1/orders", nil, payload) - if err != nil { - return nil, err - } - - response, err := r.client.SendRequest(req) - if err != nil { - return nil, err - } - - var orderResponse struct { - Code string `json:"code"` - Message string `json:"msg"` - Data *OrderResponse `json:"data"` - } - - if err := response.DecodeJSON(&orderResponse); err != nil { - return nil, err - } - - if orderResponse.Data == nil { - return nil, errors.New("api error: [" + orderResponse.Code + "] " + orderResponse.Message) - } - - return orderResponse.Data, nil -} - //go:generate requestgen -type CancelOrderRequest type CancelOrderRequest struct { client *RestClient