From 88cb5d39e5d577ebe7fd95894efb9031e6520051 Mon Sep 17 00:00:00 2001 From: linstohu Date: Wed, 20 Dec 2023 11:30:36 +0800 Subject: [PATCH] feat: update --- binance/coinmfutures/utils/client.go | 5 ++++- binance/europeanoptions/utils/client.go | 5 ++++- binance/portfoliomargin/utils/client.go | 5 ++++- binance/portfoliomargin/utils/vars.go | 5 ----- binance/usdmfutures/utils/client.go | 5 ++++- binance/usdmfutures/utils/vars.go | 5 ----- htx/{rest/spot => spot/rest}/client.go | 6 +++--- htx/{rest/spot => spot/rest}/client_test.go | 4 ++-- htx/{rest/spot => spot/rest}/types/account.go | 0 htx/usdm/rest/client.go | 18 ++++++++++++++++++ htx/usdm/websocket/client.go | 18 ++++++++++++++++++ htx/{rest => }/utils/client.go | 1 - htx/{rest => }/utils/request.go | 0 htx/{rest => }/utils/response.go | 0 htx/{rest => }/utils/vars.go | 0 kucoin/rest/utils/client.go | 7 +++---- woox/rest/client.go | 4 +++- woox/rest/vars.go | 4 ---- 18 files changed, 63 insertions(+), 29 deletions(-) rename htx/{rest/spot => spot/rest}/client.go (95%) rename htx/{rest/spot => spot/rest}/client_test.go (95%) rename htx/{rest/spot => spot/rest}/types/account.go (100%) create mode 100644 htx/usdm/rest/client.go create mode 100644 htx/usdm/websocket/client.go rename htx/{rest => }/utils/client.go (99%) rename htx/{rest => }/utils/request.go (100%) rename htx/{rest => }/utils/response.go (100%) rename htx/{rest => }/utils/vars.go (100%) diff --git a/binance/coinmfutures/utils/client.go b/binance/coinmfutures/utils/client.go index d9a58c6..e2b7aad 100644 --- a/binance/coinmfutures/utils/client.go +++ b/binance/coinmfutures/utils/client.go @@ -102,7 +102,10 @@ func (u *CoinMarginedClient) GetRecvWindow() int { } func (u *CoinMarginedClient) GenHeaders(t usdmutils.SecurityType) (map[string]string, error) { - headers := usdmutils.DefaultContentType + headers := map[string]string{ + "Content-Type": "application/x-www-form-urlencoded", + "Accept": "application/json", + } // SecurityType each endpoint has a security type that determines how you will interact with it // docs: https://binance-docs.github.io/apidocs/delivery/en/#endpoint-security-type diff --git a/binance/europeanoptions/utils/client.go b/binance/europeanoptions/utils/client.go index 48dacf7..8339e80 100644 --- a/binance/europeanoptions/utils/client.go +++ b/binance/europeanoptions/utils/client.go @@ -102,7 +102,10 @@ func (o *OptionsClient) GetRecvWindow() int { } func (o *OptionsClient) GenHeaders(t usdmutils.SecurityType) (map[string]string, error) { - headers := usdmutils.DefaultContentType + headers := map[string]string{ + "Content-Type": "application/x-www-form-urlencoded", + "Accept": "application/json", + } // SecurityType each endpoint has a security type that determines how you will interact with it // docs: https://binance-docs.github.io/apidocs/voptions/en/#endpoint-security-type diff --git a/binance/portfoliomargin/utils/client.go b/binance/portfoliomargin/utils/client.go index 2c0ab77..e81dfdc 100644 --- a/binance/portfoliomargin/utils/client.go +++ b/binance/portfoliomargin/utils/client.go @@ -101,7 +101,10 @@ func (p *PortfolioMarginClient) GetRecvWindow() int { } func (p *PortfolioMarginClient) GenHeaders(t SecurityType) (map[string]string, error) { - headers := DefaultContentType + headers := map[string]string{ + "Content-Type": "application/x-www-form-urlencoded", + "Accept": "application/json", + } // SecurityType each endpoint has a security type that determines how you will interact with it // docs: https://binance-docs.github.io/apidocs/pm/en/#endpoint-security-type diff --git a/binance/portfoliomargin/utils/vars.go b/binance/portfoliomargin/utils/vars.go index a6136ec..33d06d4 100644 --- a/binance/portfoliomargin/utils/vars.go +++ b/binance/portfoliomargin/utils/vars.go @@ -29,8 +29,3 @@ var ( USER_DATA SecurityType = "USER_DATA" USER_STREAM SecurityType = "USER_STREAM" ) - -var DefaultContentType = map[string]string{ - "Content-Type": "application/x-www-form-urlencoded", - "Accept": "application/json", -} diff --git a/binance/usdmfutures/utils/client.go b/binance/usdmfutures/utils/client.go index fd4bceb..46cce87 100644 --- a/binance/usdmfutures/utils/client.go +++ b/binance/usdmfutures/utils/client.go @@ -101,7 +101,10 @@ func (u *USDMarginedClient) GetRecvWindow() int { } func (u *USDMarginedClient) GenHeaders(t SecurityType) (map[string]string, error) { - headers := DefaultContentType + headers := map[string]string{ + "Content-Type": "application/x-www-form-urlencoded", + "Accept": "application/json", + } // SecurityType each endpoint has a security type that determines how you will interact with it // docs: https://binance-docs.github.io/apidocs/futures/en/#endpoint-security-type diff --git a/binance/usdmfutures/utils/vars.go b/binance/usdmfutures/utils/vars.go index 3ed9164..7caab17 100644 --- a/binance/usdmfutures/utils/vars.go +++ b/binance/usdmfutures/utils/vars.go @@ -31,11 +31,6 @@ var ( MARKET_DATA SecurityType = "MARKET_DATA" ) -var DefaultContentType = map[string]string{ - "Content-Type": "application/x-www-form-urlencoded", - "Accept": "application/json", -} - type ContractType = string var ( diff --git a/htx/rest/spot/client.go b/htx/spot/rest/client.go similarity index 95% rename from htx/rest/spot/client.go rename to htx/spot/rest/client.go index 804ed64..944811a 100644 --- a/htx/rest/spot/client.go +++ b/htx/spot/rest/client.go @@ -15,7 +15,7 @@ * limitations under the License. */ -package spot +package rest import ( "context" @@ -24,8 +24,8 @@ import ( "net/http" "github.com/go-playground/validator" - "github.com/linstohu/nexapi/htx/rest/spot/types" - "github.com/linstohu/nexapi/htx/rest/utils" + "github.com/linstohu/nexapi/htx/spot/rest/types" + "github.com/linstohu/nexapi/htx/utils" ) type SpotClient struct { diff --git a/htx/rest/spot/client_test.go b/htx/spot/rest/client_test.go similarity index 95% rename from htx/rest/spot/client_test.go rename to htx/spot/rest/client_test.go index 0aae1d4..42ba6e7 100644 --- a/htx/rest/spot/client_test.go +++ b/htx/spot/rest/client_test.go @@ -15,14 +15,14 @@ * limitations under the License. */ -package spot +package rest import ( "context" "os" "testing" - "github.com/linstohu/nexapi/htx/rest/utils" + "github.com/linstohu/nexapi/htx/utils" "github.com/stretchr/testify/assert" ) diff --git a/htx/rest/spot/types/account.go b/htx/spot/rest/types/account.go similarity index 100% rename from htx/rest/spot/types/account.go rename to htx/spot/rest/types/account.go diff --git a/htx/usdm/rest/client.go b/htx/usdm/rest/client.go new file mode 100644 index 0000000..3c71972 --- /dev/null +++ b/htx/usdm/rest/client.go @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023, LinstoHu + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rest diff --git a/htx/usdm/websocket/client.go b/htx/usdm/websocket/client.go new file mode 100644 index 0000000..d783d40 --- /dev/null +++ b/htx/usdm/websocket/client.go @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023, LinstoHu + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package websocket diff --git a/htx/rest/utils/client.go b/htx/utils/client.go similarity index 99% rename from htx/rest/utils/client.go rename to htx/utils/client.go index 1f6783b..f159450 100644 --- a/htx/rest/utils/client.go +++ b/htx/utils/client.go @@ -196,7 +196,6 @@ func (htx *HTXClient) SendHTTPRequest(ctx context.Context, req HTTPRequest) (*HT if err != nil { return nil, err } - defer resp.Body.Close() if htx.GetDebug() { dump, err := httputil.DumpResponse(resp, true) diff --git a/htx/rest/utils/request.go b/htx/utils/request.go similarity index 100% rename from htx/rest/utils/request.go rename to htx/utils/request.go diff --git a/htx/rest/utils/response.go b/htx/utils/response.go similarity index 100% rename from htx/rest/utils/response.go rename to htx/utils/response.go diff --git a/htx/rest/utils/vars.go b/htx/utils/vars.go similarity index 100% rename from htx/rest/utils/vars.go rename to htx/utils/vars.go diff --git a/kucoin/rest/utils/client.go b/kucoin/rest/utils/client.go index aa99e79..c76bedb 100644 --- a/kucoin/rest/utils/client.go +++ b/kucoin/rest/utils/client.go @@ -23,13 +23,13 @@ import ( "crypto/hmac" "crypto/sha256" "encoding/base64" + "encoding/json" "fmt" "io" "log/slog" "net/http" "net/http/httputil" "net/url" - "strings" "time" "github.com/go-playground/validator" @@ -149,11 +149,11 @@ func (s *KucoinClient) SendHTTPRequest(ctx context.Context, req HTTPRequest) (*H var body io.Reader if req.Body != nil { - formData, err := query.Values(req.Body) + jsonBody, err := json.Marshal(req.Body) if err != nil { return nil, err } - body = strings.NewReader(formData.Encode()) + body = bytes.NewReader(jsonBody) } url, err := url.Parse(req.BaseURL + req.Path) @@ -191,7 +191,6 @@ func (s *KucoinClient) SendHTTPRequest(ctx context.Context, req HTTPRequest) (*H if err != nil { return nil, err } - defer resp.Body.Close() if s.GetDebug() { dump, err := httputil.DumpResponse(resp, true) diff --git a/woox/rest/client.go b/woox/rest/client.go index 82e5ffb..8de7e94 100644 --- a/woox/rest/client.go +++ b/woox/rest/client.go @@ -213,7 +213,9 @@ func (w *WooXRestClient) GenV3APIAuthHeaders(req types.HTTPRequest) (map[string] return nil, fmt.Errorf("key and secret needed when init client") } - headers := V3DefaultContentType + headers := map[string]string{ + "Content-Type": "application/json", + } strBody := "" if req.Body != nil { diff --git a/woox/rest/vars.go b/woox/rest/vars.go index 17a0434..d265c1a 100644 --- a/woox/rest/vars.go +++ b/woox/rest/vars.go @@ -26,10 +26,6 @@ var ( V1DefaultContentType = map[string]string{ "Content-Type": "application/x-www-form-urlencoded", } - - V3DefaultContentType = map[string]string{ - "Content-Type": "application/json", - } ) const (