kucoin: generate PlaceOrderRequest with requestgen

This commit is contained in:
c9s 2021-12-31 01:43:31 +08:00
parent af19875e2e
commit 6addd503aa
15 changed files with 587 additions and 44 deletions

View File

@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/url" "net/url"
"regexp"
) )
func (r *CancelAllOrderRequest) Symbol(symbol string) *CancelAllOrderRequest { func (r *CancelAllOrderRequest) Symbol(symbol string) *CancelAllOrderRequest {
@ -76,3 +77,33 @@ func (r *CancelAllOrderRequest) GetParametersJSON() ([]byte, error) {
return json.Marshal(params) 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
}

View File

@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/url" "net/url"
"regexp"
) )
func (r *CancelOrderRequest) OrderID(orderID string) *CancelOrderRequest { func (r *CancelOrderRequest) OrderID(orderID string) *CancelOrderRequest {
@ -76,3 +77,33 @@ func (r *CancelOrderRequest) GetParametersJSON() ([]byte, error) {
return json.Marshal(params) 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
}

View File

@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/url" "net/url"
"regexp"
) )
// GetQueryParameters builds and checks the query parameters and returns url.Values // 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) 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) { func (g *GetAllTickersRequest) Do(ctx context.Context) (*AllTickers, error) {
// no body params // no body params
var params interface{} var params interface{}
query := url.Values{} 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/url" "net/url"
"regexp"
"strconv" "strconv"
"time" "time"
) )
@ -146,3 +147,33 @@ func (r *GetFillsRequest) GetParametersJSON() ([]byte, error) {
return json.Marshal(params) 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
}

View File

@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/url" "net/url"
"regexp"
"strconv" "strconv"
"time" "time"
) )
@ -109,3 +110,33 @@ func (r *GetKLinesRequest) GetParametersJSON() ([]byte, error) {
return json.Marshal(params) 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
}

View File

@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/url" "net/url"
"regexp"
) )
func (g *GetOrderBookLevel2Depth100Request) Symbol(symbol string) *GetOrderBookLevel2Depth100Request { func (g *GetOrderBookLevel2Depth100Request) Symbol(symbol string) *GetOrderBookLevel2Depth100Request {
@ -64,6 +65,36 @@ func (g *GetOrderBookLevel2Depth100Request) GetParametersJSON() ([]byte, error)
return json.Marshal(params) 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) { func (g *GetOrderBookLevel2Depth100Request) Do(ctx context.Context) (*OrderBook, error) {
// no body params // no body params
@ -73,7 +104,9 @@ func (g *GetOrderBookLevel2Depth100Request) Do(ctx context.Context) (*OrderBook,
return nil, err 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/url" "net/url"
"regexp"
) )
func (g *GetOrderBookLevel2Depth20Request) Symbol(symbol string) *GetOrderBookLevel2Depth20Request { func (g *GetOrderBookLevel2Depth20Request) Symbol(symbol string) *GetOrderBookLevel2Depth20Request {
@ -64,6 +65,36 @@ func (g *GetOrderBookLevel2Depth20Request) GetParametersJSON() ([]byte, error) {
return json.Marshal(params) 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) { func (g *GetOrderBookLevel2Depth20Request) Do(ctx context.Context) (*OrderBook, error) {
// no body params // no body params
@ -73,7 +104,9 @@ func (g *GetOrderBookLevel2Depth20Request) Do(ctx context.Context) (*OrderBook,
return nil, err 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/url" "net/url"
"regexp"
) )
func (g *GetOrderBookLevel2DepthAllRequest) Symbol(symbol string) *GetOrderBookLevel2DepthAllRequest { func (g *GetOrderBookLevel2DepthAllRequest) Symbol(symbol string) *GetOrderBookLevel2DepthAllRequest {
@ -64,6 +65,36 @@ func (g *GetOrderBookLevel2DepthAllRequest) GetParametersJSON() ([]byte, error)
return json.Marshal(params) 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) { func (g *GetOrderBookLevel2DepthAllRequest) Do(ctx context.Context) (*OrderBook, error) {
// no body params // no body params
@ -73,7 +104,9 @@ func (g *GetOrderBookLevel2DepthAllRequest) Do(ctx context.Context) (*OrderBook,
return nil, err 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -5,16 +5,95 @@ package kucoinapi
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/url" "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) { func (g *GetPrivateBulletRequest) Do(ctx context.Context) (*Bullet, error) {
// no body params // no body params
var params interface{} var params interface{}
query := url.Values{} 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -5,16 +5,95 @@ package kucoinapi
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/url" "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) { func (g *GetPublicBulletRequest) Do(ctx context.Context) (*Bullet, error) {
// no body params // no body params
var params interface{} var params interface{}
query := url.Values{} 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/url" "net/url"
"regexp"
) )
func (g *GetTickerRequest) Symbol(symbol string) *GetTickerRequest { func (g *GetTickerRequest) Symbol(symbol string) *GetTickerRequest {
@ -64,6 +65,36 @@ func (g *GetTickerRequest) GetParametersJSON() ([]byte, error) {
return json.Marshal(params) 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) { func (g *GetTickerRequest) Do(ctx context.Context) (*Ticker, error) {
// no body params // no body params
@ -73,7 +104,9 @@ func (g *GetTickerRequest) Do(ctx context.Context) (*Ticker, error) {
return nil, err 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/url" "net/url"
"regexp"
"strconv" "strconv"
"time" "time"
) )
@ -158,3 +159,33 @@ func (r *ListOrdersRequest) GetParametersJSON() ([]byte, error) {
return json.Marshal(params) 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
}

View File

@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/url" "net/url"
"regexp"
) )
func (l *ListSymbolsRequest) Market(market string) *ListSymbolsRequest { func (l *ListSymbolsRequest) Market(market string) *ListSymbolsRequest {
@ -66,13 +67,45 @@ func (l *ListSymbolsRequest) GetParametersJSON() ([]byte, error) {
return json.Marshal(params) 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) { func (l *ListSymbolsRequest) Do(ctx context.Context) ([]Symbol, error) {
// empty params for GET operation // empty params for GET operation
var params interface{} var params interface{}
query := url.Values{} 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -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 package kucoinapi
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/google/uuid" "github.com/google/uuid"
"net/url" "net/url"
"regexp"
) )
func (r *PlaceOrderRequest) ClientOrderID(clientOrderID string) *PlaceOrderRequest { func (r *PlaceOrderRequest) ClientOrderID(clientOrderID string) *PlaceOrderRequest {
@ -81,6 +83,7 @@ func (r *PlaceOrderRequest) GetParameters() (map[string]interface{}, error) {
// assign parameter of clientOrderID // assign parameter of clientOrderID
params["clientOid"] = clientOrderID params["clientOid"] = clientOrderID
} }
// check symbol field -> json key symbol // check symbol field -> json key symbol
symbol := r.symbol symbol := r.symbol
@ -164,3 +167,64 @@ func (r *PlaceOrderRequest) GetParametersJSON() ([]byte, error) {
return json.Marshal(params) 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
}

View File

@ -7,6 +7,7 @@ import (
"context" "context"
"time" "time"
"github.com/c9s/requestgen"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/fixedpoint"
@ -229,9 +230,9 @@ func (c *TradeService) NewListOrdersRequest() *ListOrdersRequest {
return &ListOrdersRequest{client: c.client} return &ListOrdersRequest{client: c.client}
} }
//go:generate requestgen -type PlaceOrderRequest //go:generate PostRequest -url /api/v1/orders -type PlaceOrderRequest -responseDataType .OrderResponse
type PlaceOrderRequest struct { type PlaceOrderRequest struct {
client *RestClient client requestgen.AuthenticatedAPIClient
// A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters. // A combination of case-sensitive alphanumerics, all numbers, or all letters of up to 32 characters.
clientOrderID *string `param:"clientOid,required" defaultValuer:"uuid()"` clientOrderID *string `param:"clientOid,required" defaultValuer:"uuid()"`
@ -254,39 +255,6 @@ type PlaceOrderRequest struct {
timeInForce *TimeInForceType `param:"timeInForce,required"` 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 //go:generate requestgen -type CancelOrderRequest
type CancelOrderRequest struct { type CancelOrderRequest struct {
client *RestClient client *RestClient