Skip to content

Commit

Permalink
Replace http methods to constants (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoman4eg committed Oct 7, 2021
1 parent baffa0c commit 13013b3
Show file tree
Hide file tree
Showing 45 changed files with 174 additions and 132 deletions.
5 changes: 3 additions & 2 deletions v2/account_service.go
Expand Up @@ -3,6 +3,7 @@ package binance
import (
"context"
"encoding/json"
"net/http"
)

// GetAccountService get account info
Expand All @@ -13,7 +14,7 @@ type GetAccountService struct {
// Do send request
func (s *GetAccountService) Do(ctx context.Context, opts ...RequestOption) (res *Account, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/api/v3/account",
secType: secTypeSigned,
}
Expand Down Expand Up @@ -87,7 +88,7 @@ func (s *GetAccountSnapshotService) Limit(limit int) *GetAccountSnapshotService
// Do send request
func (s *GetAccountSnapshotService) Do(ctx context.Context, opts ...RequestOption) (res *Snapshot, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/sapi/v1/accountSnapshot",
secType: secTypeSigned,
}
Expand Down
3 changes: 2 additions & 1 deletion v2/asset_detail_service.go
Expand Up @@ -3,6 +3,7 @@ package binance
import (
"context"
"encoding/json"
"net/http"
)

// GetAssetDetailService fetches all asset detail.
Expand All @@ -22,7 +23,7 @@ func (s *GetAssetDetailService) Asset(asset string) *GetAssetDetailService {
// Do sends the request.
func (s *GetAssetDetailService) Do(ctx context.Context) (res map[string]AssetDetail, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/sapi/v1/asset/assetDetail",
secType: secTypeSigned,
}
Expand Down
3 changes: 2 additions & 1 deletion v2/asset_dividend_service.go
Expand Up @@ -3,6 +3,7 @@ package binance
import (
"context"
"encoding/json"
"net/http"
)

// AssetDividendService fetches the saving purchases
Expand Down Expand Up @@ -43,7 +44,7 @@ func (s *AssetDividendService) EndTime(endTime int64) *AssetDividendService {
// Do sends the request.
func (s *AssetDividendService) Do(ctx context.Context) (*DividendResponseWrapper, error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/sapi/v1/asset/assetDividend",
secType: secTypeSigned,
}
Expand Down
2 changes: 1 addition & 1 deletion v2/client.go
Expand Up @@ -317,7 +317,7 @@ func (c *Client) callAPI(ctx context.Context, r *request, opts ...RequestOption)
c.debug("response body: %s", string(data))
c.debug("response status code: %d", res.StatusCode)

if res.StatusCode >= 400 {
if res.StatusCode >= http.StatusBadRequest {
apiErr := new(common.APIError)
e := json.Unmarshal(data, apiErr)
if e != nil {
Expand Down
5 changes: 3 additions & 2 deletions v2/delivery/account_service.go
Expand Up @@ -3,6 +3,7 @@ package delivery
import (
"context"
"encoding/json"
"net/http"
)

// GetBalanceService get account balance
Expand All @@ -13,7 +14,7 @@ type GetBalanceService struct {
// Do send request
func (s *GetBalanceService) Do(ctx context.Context, opts ...RequestOption) (res []*Balance, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/dapi/v1/balance",
secType: secTypeSigned,
}
Expand Down Expand Up @@ -49,7 +50,7 @@ type GetAccountService struct {
// Do send request
func (s *GetAccountService) Do(ctx context.Context, opts ...RequestOption) (res *Account, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/dapi/v1/account",
secType: secTypeSigned,
}
Expand Down
2 changes: 1 addition & 1 deletion v2/delivery/client.go
Expand Up @@ -311,7 +311,7 @@ func (c *Client) callAPI(ctx context.Context, r *request, opts ...RequestOption)
c.debug("response body: %s", string(data))
c.debug("response status code: %d", res.StatusCode)

if res.StatusCode >= 400 {
if res.StatusCode >= http.StatusBadRequest {
apiErr := new(common.APIError)
e := json.Unmarshal(data, apiErr)
if e != nil {
Expand Down
3 changes: 2 additions & 1 deletion v2/delivery/exchange_info_service.go
Expand Up @@ -3,6 +3,7 @@ package delivery
import (
"context"
"encoding/json"
"net/http"
)

// ExchangeInfoService exchange info service
Expand All @@ -13,7 +14,7 @@ type ExchangeInfoService struct {
// Do send request
func (s *ExchangeInfoService) Do(ctx context.Context, opts ...RequestOption) (res *ExchangeInfo, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/dapi/v1/exchangeInfo",
secType: secTypeNone,
}
Expand Down
3 changes: 2 additions & 1 deletion v2/delivery/kline_service.go
Expand Up @@ -3,6 +3,7 @@ package delivery
import (
"context"
"fmt"
"net/http"
)

// KlinesService list klines
Expand Down Expand Up @@ -48,7 +49,7 @@ func (s *KlinesService) EndTime(endTime int64) *KlinesService {
// Do send request
func (s *KlinesService) Do(ctx context.Context, opts ...RequestOption) (res []*Kline, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/dapi/v1/klines",
}
r.setParam("symbol", s.symbol)
Expand Down
15 changes: 8 additions & 7 deletions v2/delivery/order_service.go
Expand Up @@ -3,6 +3,7 @@ package delivery
import (
"context"
"encoding/json"
"net/http"
)

// CreateOrderService create order
Expand Down Expand Up @@ -124,7 +125,7 @@ func (s *CreateOrderService) ClosePosition(closePosition bool) *CreateOrderServi

func (s *CreateOrderService) createOrder(ctx context.Context, endpoint string, opts ...RequestOption) (data []byte, err error) {
r := &request{
method: "POST",
method: http.MethodPost,
endpoint: endpoint,
secType: secTypeSigned,
}
Expand Down Expand Up @@ -240,7 +241,7 @@ func (s *ListOpenOrdersService) Pair(pair string) *ListOpenOrdersService {
// Do send request
func (s *ListOpenOrdersService) Do(ctx context.Context, opts ...RequestOption) (res []*Order, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/dapi/v1/openOrders",
secType: secTypeSigned,
}
Expand Down Expand Up @@ -291,7 +292,7 @@ func (s *GetOrderService) OrigClientOrderID(origClientOrderID string) *GetOrderS
// Do send request
func (s *GetOrderService) Do(ctx context.Context, opts ...RequestOption) (res *Order, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/dapi/v1/order",
secType: secTypeSigned,
}
Expand Down Expand Up @@ -392,7 +393,7 @@ func (s *ListOrdersService) Limit(limit int) *ListOrdersService {
// Do send request
func (s *ListOrdersService) Do(ctx context.Context, opts ...RequestOption) (res []*Order, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/dapi/v1/allOrders",
secType: secTypeSigned,
}
Expand Down Expand Up @@ -455,7 +456,7 @@ func (s *CancelOrderService) OrigClientOrderID(origClientOrderID string) *Cancel
// Do send request
func (s *CancelOrderService) Do(ctx context.Context, opts ...RequestOption) (res *CancelOrderResponse, err error) {
r := &request{
method: "DELETE",
method: http.MethodDelete,
endpoint: "/dapi/v1/order",
secType: secTypeSigned,
}
Expand Down Expand Up @@ -521,7 +522,7 @@ func (s *CancelAllOpenOrdersService) Symbol(symbol string) *CancelAllOpenOrdersS
// Do send request
func (s *CancelAllOpenOrdersService) Do(ctx context.Context, opts ...RequestOption) (err error) {
r := &request{
method: "DELETE",
method: http.MethodDelete,
endpoint: "/dapi/v1/allOpenOrders",
secType: secTypeSigned,
}
Expand Down Expand Up @@ -576,7 +577,7 @@ func (s *ListLiquidationOrdersService) Limit(limit int) *ListLiquidationOrdersSe
// Do send request
func (s *ListLiquidationOrdersService) Do(ctx context.Context, opts ...RequestOption) (res []*LiquidationOrder, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/dapi/v1/allForceOrders",
secType: secTypeNone,
}
Expand Down
3 changes: 2 additions & 1 deletion v2/delivery/position_risk.go
Expand Up @@ -3,6 +3,7 @@ package delivery
import (
"context"
"encoding/json"
"net/http"
)

// GetPositionRiskService get account balance
Expand All @@ -27,7 +28,7 @@ func (s *GetPositionRiskService) Pair(pair string) *GetPositionRiskService {
// Do send request
func (s *GetPositionRiskService) Do(ctx context.Context, opts ...RequestOption) (res []*PositionRisk, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/dapi/v1/positionRisk",
secType: secTypeSigned,
}
Expand Down
11 changes: 6 additions & 5 deletions v2/delivery/position_service.go
Expand Up @@ -3,6 +3,7 @@ package delivery
import (
"context"
"encoding/json"
"net/http"
)

// ChangeLeverageService change user's initial leverage of specific symbol market
Expand All @@ -27,7 +28,7 @@ func (s *ChangeLeverageService) Leverage(leverage int) *ChangeLeverageService {
// Do send request
func (s *ChangeLeverageService) Do(ctx context.Context, opts ...RequestOption) (res *SymbolLeverage, err error) {
r := &request{
method: "POST",
method: http.MethodPost,
endpoint: "/dapi/v1/leverage",
secType: secTypeSigned,
}
Expand Down Expand Up @@ -76,7 +77,7 @@ func (s *ChangeMarginTypeService) MarginType(marginType MarginType) *ChangeMargi
// Do send request
func (s *ChangeMarginTypeService) Do(ctx context.Context, opts ...RequestOption) (err error) {
r := &request{
method: "POST",
method: http.MethodPost,
endpoint: "/dapi/v1/marginType",
secType: secTypeSigned,
}
Expand Down Expand Up @@ -127,7 +128,7 @@ func (s *UpdatePositionMarginService) Type(actionType int) *UpdatePositionMargin
// Do send request
func (s *UpdatePositionMarginService) Do(ctx context.Context, opts ...RequestOption) (err error) {
r := &request{
method: "POST",
method: http.MethodPost,
endpoint: "/dapi/v1/positionMargin",
secType: secTypeSigned,
}
Expand Down Expand Up @@ -167,7 +168,7 @@ func (s *ChangePositionModeService) DualSide(dualSide bool) *ChangePositionModeS
// Do send request
func (s *ChangePositionModeService) Do(ctx context.Context, opts ...RequestOption) (err error) {
r := &request{
method: "POST",
method: http.MethodPost,
endpoint: "/dapi/v1/positionSide/dual",
secType: secTypeSigned,
}
Expand All @@ -194,7 +195,7 @@ type PositionMode struct {
// Do send request
func (s *GetPositionModeService) Do(ctx context.Context, opts ...RequestOption) (res *PositionMode, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/dapi/v1/positionSide/dual",
secType: secTypeSigned,
}
Expand Down
5 changes: 3 additions & 2 deletions v2/delivery/server_service.go
Expand Up @@ -2,6 +2,7 @@ package delivery

import (
"context"
"net/http"
)

// PingService ping server
Expand All @@ -12,7 +13,7 @@ type PingService struct {
// Do send request
func (s *PingService) Do(ctx context.Context, opts ...RequestOption) (err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/dapi/v1/ping",
}
_, err = s.c.callAPI(ctx, r, opts...)
Expand All @@ -27,7 +28,7 @@ type ServerTimeService struct {
// Do send request
func (s *ServerTimeService) Do(ctx context.Context, opts ...RequestOption) (serverTime int64, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/dapi/v1/time",
}
data, err := s.c.callAPI(ctx, r, opts...)
Expand Down
7 changes: 4 additions & 3 deletions v2/delivery/ticker_service.go
Expand Up @@ -3,6 +3,7 @@ package delivery
import (
"context"
"encoding/json"
"net/http"
)

// ListBookTickersService list best price/qty on the order book for a symbol or symbols.
Expand All @@ -27,7 +28,7 @@ func (s *ListBookTickersService) Pair(pair string) *ListBookTickersService {
// Do send request.
func (s *ListBookTickersService) Do(ctx context.Context, opts ...RequestOption) (res []*BookTicker, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/dapi/v1/ticker/bookTicker",
}
if s.symbol != nil {
Expand Down Expand Up @@ -81,7 +82,7 @@ func (s *ListPricesService) Pair(pair string) *ListPricesService {
// Do send request.
func (s *ListPricesService) Do(ctx context.Context, opts ...RequestOption) (res []*SymbolPrice, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/dapi/v1/ticker/price",
}
if s.symbol != nil {
Expand Down Expand Up @@ -132,7 +133,7 @@ func (s *ListPriceChangeStatsService) Pair(pair string) *ListPriceChangeStatsSer
// Do send request.
func (s *ListPriceChangeStatsService) Do(ctx context.Context, opts ...RequestOption) (res []*PriceChangeStats, err error) {
r := &request{
method: "GET",
method: http.MethodGet,
endpoint: "/dapi/v1/ticker/24hr",
}
if s.symbol != nil {
Expand Down
7 changes: 4 additions & 3 deletions v2/delivery/user_stream_service.go
Expand Up @@ -2,6 +2,7 @@ package delivery

import (
"context"
"net/http"
)

// StartUserStreamService create listen key for user stream service
Expand All @@ -12,7 +13,7 @@ type StartUserStreamService struct {
// Do send request
func (s *StartUserStreamService) Do(ctx context.Context, opts ...RequestOption) (listenKey string, err error) {
r := &request{
method: "POST",
method: http.MethodPost,
endpoint: "/dapi/v1/listenKey",
secType: secTypeSigned,
}
Expand Down Expand Up @@ -43,7 +44,7 @@ func (s *KeepaliveUserStreamService) ListenKey(listenKey string) *KeepaliveUserS
// Do send request
func (s *KeepaliveUserStreamService) Do(ctx context.Context, opts ...RequestOption) (err error) {
r := &request{
method: "PUT",
method: http.MethodPut,
endpoint: "/dapi/v1/listenKey",
secType: secTypeSigned,
}
Expand All @@ -67,7 +68,7 @@ func (s *CloseUserStreamService) ListenKey(listenKey string) *CloseUserStreamSer
// Do send request
func (s *CloseUserStreamService) Do(ctx context.Context, opts ...RequestOption) (err error) {
r := &request{
method: "DELETE",
method: http.MethodDelete,
endpoint: "/dapi/v1/listenKey",
secType: secTypeSigned,
}
Expand Down

0 comments on commit 13013b3

Please sign in to comment.