mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-05 23:16:53 +00:00
exchanges/qa: Add exchange wrapper testing suite (#1159)
* initial concept of a nice validation tester for exchanges * adds some datahandler design * expand testing * more tests and fixes * minor end of day fix for bithumb * fixes implementation issues * more test coverage and improvements, but not sure if i should continue * fix more wrapper implementations * adds error type, more fixes * changes signature, fixes implementations * fixes more wrapper implementations * one more bit * more cleanup * WOW things work? * lintle 1/1337 * mini bump * fixes all linting * neaten * GetOrderInfo+ asset pair fixes+improvements * adds new websocket test * expand ws testing * fix bug, expand tests, improve implementation * code coverage of a lot of new codes * fixes everything * reverts accidental changes * minor fixes from reviewing code * removes Bitfinex cancelBatchOrder implementation * fixes dumb baby typo for babies * mini nit fixes * so many nits to address * addresses all the nits * Titlecase * switcheroo * removes websocket testing for now * fix appveyor, minor test fix * fixes typo, re-kindles killed kode * skip binance wrapper tests when running CI * expired context, huobi okx fixes * kodespull * fix ordering * time fix because why not * fix exmo, others * hopefully this fixes all of my life's problems * last thing today * huobi, more like hypotrophy * golangci-lint, more like mypooroldknee-splint * fix huobi times by removing them * should fix okx currency issues * blocks the application * adds last little contingency for pairs * addresses most nits and new problems * lovely fixed before seeing why okx sucks * fixes issues with okx websocket * the classic receieieivaier * lintle * adds test and fixes existing tests * expands error handling messages during setup * fixes dumb okx bugs introduced * quick fix for lint and exmo * fixes nixes * fix exmo deposit issue * lint * fixes issue with extra asset runs missing * fix surprise race * all the lint and merge fixes * fixes surprise bugs in OKx * fixes issues with times and chains * fixing all the merge stuff * merge fix * rm logs and a panic potential * lovely lint lament * an easy demonstration of scenario, but not of initial purpose * put it in the bin * Revert "put it in the bin" This reverts commit 15c6490f713233d43f10957367fcbf18e3818bdd. * re-add after immediate error popup * fix mini poor test design * okx okay * merge fixes * fixes issues discovered in lovely test * I FORGOT TO COMMIT THIS * nit fixaroonaboo * forgoetten test fix * revert old okx asset intrument work * fixes * revert problems I didnt understand. update bybit * fix merge bugs * test cleanup * further improvements * reshuffle and lint * rm redundant CI_TEST by rm the CI_TEST field that is redundant * path fix * move to its own section, dont run on 32 bit + appveyor * lint * fix lbank * address nits * let it rip * fix failing test time range * niteroo boogaloo * mod tidy, use common.SimpleTimeFormat
This commit is contained in:
@@ -50,6 +50,7 @@ const (
|
||||
bybitFastCancelSpotOrder = "/spot/v1/order/fast"
|
||||
bybitBatchCancelSpotOrder = "/spot/order/batch-cancel"
|
||||
bybitFastBatchCancelSpotOrder = "/spot/order/batch-fast-cancel"
|
||||
bybitBatchCancelByIDs = "/spot/order/batch-cancel-by-ids"
|
||||
bybitOpenOrder = "/spot/v1/open-orders"
|
||||
bybitPastOrder = "/spot/v1/history-orders"
|
||||
bybitTradeHistory = "/spot/v1/myTrades"
|
||||
@@ -629,7 +630,7 @@ func (by *Bybit) BatchCancelOrderByIDs(ctx context.Context, orderIDs []string) (
|
||||
} `json:"result"`
|
||||
Error
|
||||
}{}
|
||||
return resp.Result.Success, by.SendAuthHTTPRequest(ctx, exchange.RestSpot, http.MethodDelete, bybitFastBatchCancelSpotOrder, params, nil, &resp, privateSpotRate)
|
||||
return resp.Result.Success, by.SendAuthHTTPRequest(ctx, exchange.RestSpot, http.MethodDelete, bybitBatchCancelByIDs, params, nil, &resp, privateSpotRate)
|
||||
}
|
||||
|
||||
// ListOpenOrders returns all open orders
|
||||
@@ -817,11 +818,11 @@ func (by *Bybit) SendHTTPRequest(ctx context.Context, ePath exchange.URL, path s
|
||||
Verbose: by.Verbose,
|
||||
HTTPDebugging: by.HTTPDebugging,
|
||||
HTTPRecording: by.HTTPRecording}, nil
|
||||
})
|
||||
}, request.UnauthenticatedRequest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result.GetError()
|
||||
return result.GetError(false)
|
||||
}
|
||||
|
||||
// SendAuthHTTPRequest sends an authenticated HTTP request
|
||||
@@ -895,15 +896,14 @@ func (by *Bybit) SendAuthHTTPRequest(ctx context.Context, ePath exchange.URL, me
|
||||
Headers: headers,
|
||||
Body: bytes.NewBuffer(payload),
|
||||
Result: &result,
|
||||
AuthRequest: true,
|
||||
Verbose: by.Verbose,
|
||||
HTTPDebugging: by.HTTPDebugging,
|
||||
HTTPRecording: by.HTTPRecording}, nil
|
||||
})
|
||||
}, request.AuthenticatedRequest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result.GetError()
|
||||
return result.GetError(true)
|
||||
}
|
||||
|
||||
// SendAuthHTTPRequestV5 sends an authenticated HTTP request
|
||||
@@ -941,16 +941,15 @@ func (by *Bybit) SendAuthHTTPRequestV5(ctx context.Context, ePath exchange.URL,
|
||||
Path: endpointPath + common.EncodeURLValues(path, params),
|
||||
Headers: headers,
|
||||
Result: &result,
|
||||
AuthRequest: true,
|
||||
Verbose: by.Verbose,
|
||||
HTTPDebugging: by.HTTPDebugging,
|
||||
HTTPRecording: by.HTTPRecording}, nil
|
||||
})
|
||||
}, request.AuthenticatedRequest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return result.GetError()
|
||||
return result.GetError(true)
|
||||
}
|
||||
|
||||
// Error defines all error information for each request
|
||||
@@ -964,14 +963,20 @@ type Error struct {
|
||||
}
|
||||
|
||||
// GetError checks and returns an error if it is supplied.
|
||||
func (e *Error) GetError() error {
|
||||
func (e *Error) GetError(isAuthRequest bool) error {
|
||||
if e.ReturnCode != 0 && e.ReturnMsg != "" {
|
||||
if isAuthRequest {
|
||||
return fmt.Errorf("%w %v", request.ErrAuthRequestFailed, e.ReturnMsg)
|
||||
}
|
||||
return errors.New(e.ReturnMsg)
|
||||
}
|
||||
if e.ReturnCodeV5 != 0 && e.ReturnMessageV5 != "" {
|
||||
return errors.New(e.ReturnMessageV5)
|
||||
}
|
||||
if e.ExtCode != "" && e.ExtMsg != "" {
|
||||
if isAuthRequest {
|
||||
return fmt.Errorf("%w %v", request.ErrAuthRequestFailed, e.ExtMsg)
|
||||
}
|
||||
return errors.New(e.ExtMsg)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -2699,7 +2699,7 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var getOrdersRequestSpot = order.GetOrdersRequest{
|
||||
var getOrdersRequestSpot = order.MultiOrderRequest{
|
||||
Pairs: currency.Pairs{pair},
|
||||
AssetType: asset.Spot,
|
||||
Side: order.AnySide,
|
||||
@@ -2711,7 +2711,7 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
var getOrdersRequestUMF = order.GetOrdersRequest{
|
||||
var getOrdersRequestUMF = order.MultiOrderRequest{
|
||||
Pairs: currency.Pairs{pair},
|
||||
AssetType: asset.USDTMarginedFutures,
|
||||
Side: order.AnySide,
|
||||
@@ -2728,7 +2728,7 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var getOrdersRequestCMF = order.GetOrdersRequest{
|
||||
var getOrdersRequestCMF = order.MultiOrderRequest{
|
||||
Pairs: currency.Pairs{pair1},
|
||||
AssetType: asset.CoinMarginedFutures,
|
||||
Side: order.AnySide,
|
||||
@@ -2745,7 +2745,7 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var getOrdersRequestFutures = order.GetOrdersRequest{
|
||||
var getOrdersRequestFutures = order.MultiOrderRequest{
|
||||
Pairs: currency.Pairs{pair2},
|
||||
AssetType: asset.Futures,
|
||||
Side: order.AnySide,
|
||||
@@ -2762,7 +2762,7 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var getOrdersRequestUSDC = order.GetOrdersRequest{
|
||||
var getOrdersRequestUSDC = order.MultiOrderRequest{
|
||||
Pairs: currency.Pairs{pair3},
|
||||
AssetType: asset.USDCMarginedFutures,
|
||||
Side: order.AnySide,
|
||||
@@ -2784,7 +2784,7 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var getOrdersRequestSpot = order.GetOrdersRequest{
|
||||
var getOrdersRequestSpot = order.MultiOrderRequest{
|
||||
Pairs: currency.Pairs{pair},
|
||||
AssetType: asset.Spot,
|
||||
Type: order.AnyType,
|
||||
@@ -2796,7 +2796,7 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
var getOrdersRequestUMF = order.GetOrdersRequest{
|
||||
var getOrdersRequestUMF = order.MultiOrderRequest{
|
||||
Pairs: currency.Pairs{pair},
|
||||
AssetType: asset.USDTMarginedFutures,
|
||||
Type: order.AnyType,
|
||||
@@ -2813,7 +2813,7 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var getOrdersRequestCMF = order.GetOrdersRequest{
|
||||
var getOrdersRequestCMF = order.MultiOrderRequest{
|
||||
Pairs: currency.Pairs{pair1},
|
||||
AssetType: asset.CoinMarginedFutures,
|
||||
Type: order.AnyType,
|
||||
@@ -2830,7 +2830,7 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var getOrdersRequestFutures = order.GetOrdersRequest{
|
||||
var getOrdersRequestFutures = order.MultiOrderRequest{
|
||||
Pairs: currency.Pairs{pair2},
|
||||
AssetType: asset.Futures,
|
||||
Type: order.AnyType,
|
||||
@@ -2847,7 +2847,7 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var getOrdersRequestUSDC = order.GetOrdersRequest{
|
||||
var getOrdersRequestUSDC = order.MultiOrderRequest{
|
||||
Pairs: currency.Pairs{pair3},
|
||||
AssetType: asset.USDCMarginedFutures,
|
||||
Type: order.AnyType,
|
||||
@@ -3333,6 +3333,21 @@ func TestGetUSDCPredictedFundingRate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelBatchOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, b, canManipulateRealOrders)
|
||||
_, err := b.CancelBatchOrders(context.Background(), []order.Cancel{
|
||||
{
|
||||
OrderID: "1234",
|
||||
AssetType: asset.Spot,
|
||||
Pair: currency.NewPair(currency.BTC, currency.USD),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateTickers(t *testing.T) {
|
||||
t.Parallel()
|
||||
supportedAssets := b.GetAssetTypes(false)
|
||||
|
||||
@@ -38,11 +38,10 @@ var (
|
||||
errStopOrderOrOrderLinkIDMissing = errors.New("at least one should be present among stopOrderID and orderLinkID")
|
||||
errOrderOrOrderLinkIDMissing = errors.New("at least one should be present among orderID and orderLinkID")
|
||||
|
||||
errSymbolMissing = errors.New("symbol missing")
|
||||
errUnsupportedOrderType = errors.New("unsupported order type")
|
||||
errEmptyOrderIDs = errors.New("orderIDs can't be empty")
|
||||
errMissingPrice = errors.New("price should be present for Limit and LimitMaker orders")
|
||||
errExpectedOneOrder = errors.New("expected one order")
|
||||
errSymbolMissing = errors.New("symbol missing")
|
||||
errEmptyOrderIDs = errors.New("orderIDs can't be empty")
|
||||
errMissingPrice = errors.New("price should be present for Limit and LimitMaker orders")
|
||||
errExpectedOneOrder = errors.New("expected one order")
|
||||
)
|
||||
|
||||
var validCategory = []string{"spot", "linear", "inverse", "option"}
|
||||
@@ -154,7 +153,7 @@ func (b bybitTimeNanoSec) Time() time.Time {
|
||||
|
||||
// UnmarshalTo acts as interface to exchange API response
|
||||
type UnmarshalTo interface {
|
||||
GetError() error
|
||||
GetError(isAuthRequest bool) error
|
||||
}
|
||||
|
||||
// PairData stores pair data
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -1063,7 +1064,7 @@ func (by *Bybit) SendUSDCAuthHTTPRequest(ctx context.Context, ePath exchange.URL
|
||||
if data != nil {
|
||||
d, ok := data.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, common.GetAssertError("map[string]interface{}", data)
|
||||
return nil, common.GetTypeAssertError("map[string]interface{}", data)
|
||||
}
|
||||
payload, err = json.Marshal(d)
|
||||
if err != nil {
|
||||
@@ -1090,15 +1091,14 @@ func (by *Bybit) SendUSDCAuthHTTPRequest(ctx context.Context, ePath exchange.URL
|
||||
Headers: headers,
|
||||
Body: bytes.NewBuffer(payload),
|
||||
Result: &result,
|
||||
AuthRequest: true,
|
||||
Verbose: by.Verbose,
|
||||
HTTPDebugging: by.HTTPDebugging,
|
||||
HTTPRecording: by.HTTPRecording}, nil
|
||||
})
|
||||
}, request.AuthenticatedRequest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return result.GetError()
|
||||
return result.GetError(true)
|
||||
}
|
||||
|
||||
// USDCError defines all error information for each USDC request
|
||||
@@ -1108,8 +1108,11 @@ type USDCError struct {
|
||||
}
|
||||
|
||||
// GetError checks and returns an error if it is supplied.
|
||||
func (e USDCError) GetError() error {
|
||||
func (e USDCError) GetError(isAuthRequest bool) error {
|
||||
if e.ReturnCode != 0 && e.ReturnMsg != "" {
|
||||
if isAuthRequest {
|
||||
return fmt.Errorf("%w %v", request.ErrAuthRequestFailed, e.ReturnMsg)
|
||||
}
|
||||
return errors.New(e.ReturnMsg)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -370,11 +370,11 @@ func (by *Bybit) wsHandleData(respRaw []byte) error {
|
||||
for i := range d {
|
||||
obj, ok := d[i].(map[string]interface{})
|
||||
if !ok {
|
||||
return common.GetAssertError("map[string]interface{}", d[i])
|
||||
return common.GetTypeAssertError("map[string]interface{}", d[i])
|
||||
}
|
||||
e, ok := obj["e"].(string)
|
||||
if !ok {
|
||||
return common.GetAssertError("string", obj["e"])
|
||||
return common.GetTypeAssertError("string", obj["e"])
|
||||
}
|
||||
|
||||
switch e {
|
||||
|
||||
@@ -285,7 +285,7 @@ func (by *Bybit) Run(ctx context.Context) {
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (by *Bybit) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
|
||||
if !by.SupportsAsset(a) {
|
||||
return nil, fmt.Errorf("asset type of %s is not supported by %s", a, by.Name)
|
||||
return nil, fmt.Errorf("%w %v", asset.ErrNotSupported, a)
|
||||
}
|
||||
|
||||
var pair currency.Pair
|
||||
@@ -411,7 +411,7 @@ func (by *Bybit) UpdateTradablePairs(ctx context.Context, forceUpdate bool) erro
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return by.EnsureOnePairEnabled()
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
@@ -465,7 +465,7 @@ func (by *Bybit) UpdateTickers(ctx context.Context, assetType asset.Item) error
|
||||
}
|
||||
}
|
||||
case asset.CoinMarginedFutures, asset.USDTMarginedFutures, asset.Futures:
|
||||
tick, err := by.GetFuturesSymbolPriceTicker(ctx, currency.Pair{})
|
||||
tick, err := by.GetFuturesSymbolPriceTicker(ctx, currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -656,6 +656,12 @@ func (by *Bybit) FetchOrderbook(ctx context.Context, currency currency.Pair, ass
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (by *Bybit) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
if p.IsEmpty() {
|
||||
return nil, currency.ErrCurrencyPairEmpty
|
||||
}
|
||||
if err := by.CurrencyPairs.IsAssetEnabled(assetType); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var orderbookNew *Orderbook
|
||||
var err error
|
||||
|
||||
@@ -796,10 +802,10 @@ func (by *Bybit) FetchAccountInfo(ctx context.Context, assetType asset.Item) (ac
|
||||
return acc, nil
|
||||
}
|
||||
|
||||
// GetFundingHistory returns funding history, deposits and
|
||||
// GetAccountFundingHistory returns funding history, deposits and
|
||||
// withdrawals
|
||||
func (by *Bybit) GetFundingHistory(_ context.Context) ([]exchange.FundHistory, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
func (by *Bybit) GetAccountFundingHistory(_ context.Context) ([]exchange.FundingHistory, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWithdrawalsHistory returns previous withdrawals data
|
||||
@@ -963,7 +969,7 @@ func (by *Bybit) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Submi
|
||||
case order.Limit:
|
||||
requestParamsOrderType = BybitRequestParamsOrderLimit
|
||||
default:
|
||||
return nil, errUnsupportedOrderType
|
||||
return nil, fmt.Errorf("%w %v", order.ErrUnsupportedOrderType, s.Type)
|
||||
}
|
||||
|
||||
var orderRequest = PlaceOrderRequest{
|
||||
@@ -989,12 +995,11 @@ func (by *Bybit) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Submi
|
||||
var oType string
|
||||
switch s.Type {
|
||||
case order.Market:
|
||||
timeInForce = ""
|
||||
oType = "Market"
|
||||
case order.Limit:
|
||||
oType = "Limit"
|
||||
default:
|
||||
return nil, errUnsupportedOrderType
|
||||
return nil, fmt.Errorf("%w %v", order.ErrUnsupportedOrderType, s.Type)
|
||||
}
|
||||
var o FuturesOrderDataResp
|
||||
o, err = by.CreateCoinFuturesOrder(ctx, formattedPair, sideType, oType, timeInForce,
|
||||
@@ -1009,12 +1014,11 @@ func (by *Bybit) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Submi
|
||||
var oType string
|
||||
switch s.Type {
|
||||
case order.Market:
|
||||
timeInForce = ""
|
||||
oType = "Market"
|
||||
case order.Limit:
|
||||
oType = "Limit"
|
||||
default:
|
||||
return nil, errUnsupportedOrderType
|
||||
return nil, fmt.Errorf("%w %v", order.ErrUnsupportedOrderType, s.Type)
|
||||
}
|
||||
var o FuturesOrderDataResp
|
||||
o, err = by.CreateUSDTFuturesOrder(ctx, formattedPair, sideType, oType, timeInForce,
|
||||
@@ -1029,12 +1033,11 @@ func (by *Bybit) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Submi
|
||||
var oType string
|
||||
switch s.Type {
|
||||
case order.Market:
|
||||
timeInForce = ""
|
||||
oType = "Market"
|
||||
case order.Limit:
|
||||
oType = "Limit"
|
||||
default:
|
||||
return nil, errUnsupportedOrderType
|
||||
return nil, fmt.Errorf("%w %v", order.ErrUnsupportedOrderType, s.Type)
|
||||
}
|
||||
var o FuturesOrderDataResp
|
||||
o, err = by.CreateFuturesOrder(ctx, 0, formattedPair, sideType, oType, timeInForce,
|
||||
@@ -1054,7 +1057,7 @@ func (by *Bybit) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Submi
|
||||
case order.Limit:
|
||||
oType = "Limit"
|
||||
default:
|
||||
return nil, errUnsupportedOrderType
|
||||
return nil, fmt.Errorf("%w %v", order.ErrUnsupportedOrderType, s.Type)
|
||||
}
|
||||
var o USDCCreateOrderResp
|
||||
o, err = by.PlaceUSDCOrder(ctx, formattedPair, oType, "Order", sideType, timeInForce,
|
||||
@@ -1136,8 +1139,32 @@ func (by *Bybit) CancelOrder(ctx context.Context, ord *order.Cancel) error {
|
||||
}
|
||||
|
||||
// CancelBatchOrders cancels orders by their corresponding ID numbers
|
||||
func (by *Bybit) CancelBatchOrders(_ context.Context, _ []order.Cancel) (order.CancelBatchResponse, error) {
|
||||
return order.CancelBatchResponse{}, common.ErrNotYetImplemented
|
||||
func (by *Bybit) CancelBatchOrders(ctx context.Context, o []order.Cancel) (*order.CancelBatchResponse, error) {
|
||||
if len(o) == 0 {
|
||||
return nil, order.ErrCancelOrderIsNil
|
||||
}
|
||||
ids := make([]string, 0, len(o))
|
||||
for i := range o {
|
||||
switch {
|
||||
case o[i].ClientOrderID != "":
|
||||
return nil, order.ErrClientOrderIDNotSupported
|
||||
case o[i].OrderID != "":
|
||||
ids = append(ids, o[i].OrderID)
|
||||
default:
|
||||
return nil, order.ErrOrderIDNotSet
|
||||
}
|
||||
}
|
||||
cancelledOrders, err := by.BatchCancelOrderByIDs(ctx, ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := &order.CancelBatchResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
for i := range ids {
|
||||
resp.Status[ids[i]] = strconv.FormatBool(cancelledOrders)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
@@ -1225,15 +1252,22 @@ func (by *Bybit) CancelAllOrders(ctx context.Context, orderCancellation *order.C
|
||||
}
|
||||
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (by *Bybit) GetOrderInfo(ctx context.Context, orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
func (by *Bybit) GetOrderInfo(ctx context.Context, orderID string, pair currency.Pair, assetType asset.Item) (*order.Detail, error) {
|
||||
if pair.IsEmpty() {
|
||||
return nil, currency.ErrCurrencyPairEmpty
|
||||
}
|
||||
if err := by.CurrencyPairs.IsAssetEnabled(assetType); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch assetType {
|
||||
case asset.Spot:
|
||||
resp, err := by.QueryOrder(ctx, orderID, "")
|
||||
if err != nil {
|
||||
return order.Detail{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return order.Detail{
|
||||
return &order.Detail{
|
||||
Amount: resp.Quantity.Float64(),
|
||||
Exchange: by.Name,
|
||||
OrderID: resp.OrderID,
|
||||
@@ -1253,14 +1287,14 @@ func (by *Bybit) GetOrderInfo(ctx context.Context, orderID string, pair currency
|
||||
case asset.CoinMarginedFutures:
|
||||
resp, err := by.GetActiveRealtimeCoinOrders(ctx, pair, orderID, "")
|
||||
if err != nil {
|
||||
return order.Detail{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(resp) != 1 {
|
||||
return order.Detail{}, fmt.Errorf("%w, received %v orders", errExpectedOneOrder, len(resp))
|
||||
return nil, fmt.Errorf("%w, received %v orders", errExpectedOneOrder, len(resp))
|
||||
}
|
||||
|
||||
return order.Detail{
|
||||
return &order.Detail{
|
||||
Amount: resp[0].Qty,
|
||||
Exchange: by.Name,
|
||||
OrderID: resp[0].OrderID,
|
||||
@@ -1280,14 +1314,14 @@ func (by *Bybit) GetOrderInfo(ctx context.Context, orderID string, pair currency
|
||||
case asset.USDTMarginedFutures:
|
||||
resp, err := by.GetActiveUSDTRealtimeOrders(ctx, pair, orderID, "")
|
||||
if err != nil {
|
||||
return order.Detail{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(resp) != 1 {
|
||||
return order.Detail{}, fmt.Errorf("%w, received %v orders", errExpectedOneOrder, len(resp))
|
||||
return nil, fmt.Errorf("%w, received %v orders", errExpectedOneOrder, len(resp))
|
||||
}
|
||||
|
||||
return order.Detail{
|
||||
return &order.Detail{
|
||||
Amount: resp[0].Qty,
|
||||
Exchange: by.Name,
|
||||
OrderID: resp[0].OrderID,
|
||||
@@ -1307,14 +1341,14 @@ func (by *Bybit) GetOrderInfo(ctx context.Context, orderID string, pair currency
|
||||
case asset.Futures:
|
||||
resp, err := by.GetActiveRealtimeOrders(ctx, pair, orderID, "")
|
||||
if err != nil {
|
||||
return order.Detail{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(resp) != 1 {
|
||||
return order.Detail{}, fmt.Errorf("%w, received %v orders", errExpectedOneOrder, len(resp))
|
||||
return nil, fmt.Errorf("%w, received %v orders", errExpectedOneOrder, len(resp))
|
||||
}
|
||||
|
||||
return order.Detail{
|
||||
return &order.Detail{
|
||||
Amount: resp[0].Qty,
|
||||
Exchange: by.Name,
|
||||
OrderID: resp[0].OrderID,
|
||||
@@ -1334,14 +1368,14 @@ func (by *Bybit) GetOrderInfo(ctx context.Context, orderID string, pair currency
|
||||
case asset.USDCMarginedFutures:
|
||||
resp, err := by.GetActiveUSDCOrder(ctx, pair, "PERPETUAL", orderID, "", "", "", "", 0)
|
||||
if err != nil {
|
||||
return order.Detail{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(resp) != 1 {
|
||||
return order.Detail{}, fmt.Errorf("%w, received %v orders", errExpectedOneOrder, len(resp))
|
||||
return nil, fmt.Errorf("%w, received %v orders", errExpectedOneOrder, len(resp))
|
||||
}
|
||||
|
||||
return order.Detail{
|
||||
return &order.Detail{
|
||||
Amount: resp[0].Qty.Float64(),
|
||||
Exchange: by.Name,
|
||||
OrderID: resp[0].ID,
|
||||
@@ -1358,7 +1392,7 @@ func (by *Bybit) GetOrderInfo(ctx context.Context, orderID string, pair currency
|
||||
}, nil
|
||||
|
||||
default:
|
||||
return order.Detail{}, fmt.Errorf("%s %w", assetType, asset.ErrNotSupported)
|
||||
return nil, fmt.Errorf("%s %w", assetType, asset.ErrNotSupported)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1378,7 +1412,7 @@ func (by *Bybit) GetDepositAddress(ctx context.Context, cryptocurrency currency.
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("deposit address not found for currency: %s chain: %s", cryptocurrency, chain)
|
||||
return nil, fmt.Errorf("%w for currency: %s chain: %s", deposit.ErrAddressNotFound, cryptocurrency, chain)
|
||||
}
|
||||
|
||||
// GetAvailableTransferChains returns the available transfer blockchains for the specific
|
||||
@@ -1430,7 +1464,7 @@ func (by *Bybit) WithdrawFiatFundsToInternationalBank(_ context.Context, _ *with
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (by *Bybit) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) (order.FilteredOrders, error) {
|
||||
func (by *Bybit) GetActiveOrders(ctx context.Context, req *order.MultiOrderRequest) (order.FilteredOrders, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1442,7 +1476,7 @@ func (by *Bybit) GetActiveOrders(ctx context.Context, req *order.GetOrdersReques
|
||||
|
||||
if len(req.Pairs) == 0 {
|
||||
// sending an empty currency pair retrieves data for all currencies
|
||||
req.Pairs = append(req.Pairs, currency.Pair{})
|
||||
req.Pairs = append(req.Pairs, currency.EMPTYPAIR)
|
||||
}
|
||||
|
||||
var orders []order.Detail
|
||||
@@ -1587,7 +1621,7 @@ func (by *Bybit) GetActiveOrders(ctx context.Context, req *order.GetOrdersReques
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (by *Bybit) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) (order.FilteredOrders, error) {
|
||||
func (by *Bybit) GetOrderHistory(ctx context.Context, req *order.MultiOrderRequest) (order.FilteredOrders, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1595,13 +1629,13 @@ func (by *Bybit) GetOrderHistory(ctx context.Context, req *order.GetOrdersReques
|
||||
var orders []order.Detail
|
||||
switch req.AssetType {
|
||||
case asset.Spot:
|
||||
resp, err := by.GetPastOrders(ctx, "", req.OrderID, 0, req.StartTime, req.EndTime)
|
||||
resp, err := by.GetPastOrders(ctx, "", req.FromOrderID, 0, req.StartTime, req.EndTime)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := range resp {
|
||||
// here, we are not using getSide because in sample response side's are in upper
|
||||
// here, we are not using getSide because in sample response's sides are in upper
|
||||
var side order.Side
|
||||
side, err = order.StringToOrderSide(resp[i].Side)
|
||||
if err != nil {
|
||||
@@ -1713,7 +1747,7 @@ func (by *Bybit) GetOrderHistory(ctx context.Context, req *order.GetOrdersReques
|
||||
}
|
||||
}
|
||||
case asset.USDCMarginedFutures:
|
||||
resp, err := by.GetUSDCOrderHistory(ctx, currency.EMPTYPAIR, "PERPETUAL", req.OrderID, "", "", "", "", 0)
|
||||
resp, err := by.GetUSDCOrderHistory(ctx, currency.EMPTYPAIR, "PERPETUAL", "", "", "", "", "", 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1759,7 +1793,9 @@ func (by *Bybit) GetOrderHistory(ctx context.Context, req *order.GetOrdersReques
|
||||
|
||||
// GetFeeByType returns an estimate of fee based on the type of transaction
|
||||
func (by *Bybit) GetFeeByType(_ context.Context, _ *exchange.FeeBuilder) (float64, error) {
|
||||
return 0, common.ErrNotYetImplemented
|
||||
// TODO: Upgrade from v1 spot API
|
||||
// TODO: give FeeBuilder asset property to distinguish between endpoints
|
||||
return 0, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// ValidateAPICredentials validates current credentials used for wrapper
|
||||
@@ -2064,7 +2100,7 @@ func (by *Bybit) GetServerTime(ctx context.Context, a asset.Item) (time.Time, er
|
||||
func (by *Bybit) extractCurrencyPair(symbol string, item asset.Item) (currency.Pair, error) {
|
||||
pairs, err := by.CurrencyPairs.GetPairs(item, true)
|
||||
if err != nil {
|
||||
return currency.Pair{}, err
|
||||
return currency.EMPTYPAIR, err
|
||||
}
|
||||
return pairs.DeriveFrom(symbol)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user