mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
* Added TimeInForce type and updated related files * Linter issue fix and minor coinbasepro type update * Bitrex consts update * added unit test and minor changes in bittrex * Unit tests update * Fix minor linter issues * Update TestStringToTimeInForce unit test * Exchange test template change * A different approach * fix conflict with gateio timeInForce * minor exchange template update * Minor fix to test_files template * Update order tests * Complete updating the order unit tests * Updating exchange wrapper and test template files * update kucoin and deribit wrapper to match the time in force change * minor comment update * fix time-in-force related test errors * linter issue fix * ADD_NEW_EXCHANGE documentation update * time in force constants, functions and unit tests update * shift tif policies to TimeInForce * Update time-in-force, related functions, and unit tests * fix linter issue and time-in-force processing * added a good till crossing tif value * order type fix and fix related tim-in-force entries * update time-in-force unmarshaling and unit test * consistency guideline added * fix time-in-force error in gateio * linter issue fix * update based on review comments * add unit test and fix missing issues * minor fix and added benchmark unit test * change GTT to GTC for limit * fix linter issue * added time-in-force value to place order param * fix minor issues based on review comment and move tif code to separate files * update on exchanges linked to time-in-force * resolve missing review comments * minor linter issues fix * added time-in-force handler and update timeInForce parametered endpoint * minor fixes based on review * nits fix * update based on review * linter fix * rm getTimeInForce func and minor change to time-in-force * minor change * update based on review comments * wrappers and time-in-force calling approach * minor change * update gateio string to timeInForce conversion and unit test * update exchange template * update wrapper template file * policy comments, and template files update * rename all exchange types name to Exchange * update on template files and template generation * templates and generation code and other updates * linter issue fix * added subscriptions and websocket templates * update ADD_NEW_EXCHANGE.md with recent binance functions and implementations * rename template files and update unit tests * minor template and unit test fix * rename templates and fix on unit tests * update on template files and documentation * removed unnecessary tag fix and update templates * fix Add_NEW_EXCHANGE.md doc file * formatting, comments, and error checks update on template files * rename exchange receivers to e and ex for consistency * rename unit test exchange receiver and minor updates * linter issues fix * fix deribit issue and minor style update * fix test issues caused by receiver change * raname local variables exchange declaration variables * update templates comments * update templates and related comments * renamed ex to e * update template comments * toggle WS to false to improve coverage * template comments update * added test coverage to Ws enabled and minor changes --------- Co-authored-by: Samuel Reid <43227667+cranktakular@users.noreply.github.com>
207 lines
7.2 KiB
Go
207 lines
7.2 KiB
Go
package gateio
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/thrasher-corp/gocryptotrader/common"
|
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
|
)
|
|
|
|
var (
|
|
BTCUSDT = currency.NewPairWithDelimiter("BTC", "USDT", "_")
|
|
BTCUSD = currency.NewPairWithDelimiter("BTC", "USD", "_")
|
|
)
|
|
|
|
func TestWebsocketFuturesSubmitOrder(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := e.WebsocketFuturesSubmitOrder(t.Context(), asset.USDTMarginedFutures, &ContractOrderCreateParams{})
|
|
require.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)
|
|
out := &ContractOrderCreateParams{Contract: BTCUSDT}
|
|
_, err = e.WebsocketFuturesSubmitOrder(t.Context(), asset.USDTMarginedFutures, out)
|
|
require.ErrorIs(t, err, errInvalidPrice)
|
|
out.Price = "40000"
|
|
_, err = e.WebsocketFuturesSubmitOrder(t.Context(), asset.USDTMarginedFutures, out)
|
|
require.ErrorIs(t, err, errInvalidAmount)
|
|
out.Size = 1 // 1 lovely long contract
|
|
out.AutoSize = "silly_billies"
|
|
_, err = e.WebsocketFuturesSubmitOrder(t.Context(), asset.USDTMarginedFutures, out)
|
|
require.ErrorIs(t, err, errInvalidAutoSize)
|
|
|
|
sharedtestvalues.SkipTestIfCredentialsUnset(t, e, canManipulateRealOrders)
|
|
|
|
g := newExchangeWithWebsocket(t, asset.Futures)
|
|
out.AutoSize = ""
|
|
|
|
got, err := g.WebsocketFuturesSubmitOrder(t.Context(), asset.USDTMarginedFutures, out)
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, got)
|
|
}
|
|
|
|
func TestWebsocketFuturesSubmitOrders(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := e.WebsocketFuturesSubmitOrders(t.Context(), asset.USDTMarginedFutures)
|
|
require.ErrorIs(t, err, errOrdersEmpty)
|
|
|
|
out := &ContractOrderCreateParams{}
|
|
_, err = e.WebsocketFuturesSubmitOrders(t.Context(), asset.USDTMarginedFutures, out)
|
|
require.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)
|
|
|
|
out.Contract = BTCUSDT
|
|
|
|
_, err = e.WebsocketFuturesSubmitOrders(t.Context(), asset.USDTMarginedFutures, out)
|
|
require.ErrorIs(t, err, errInvalidPrice)
|
|
|
|
out.Price = "40000"
|
|
_, err = e.WebsocketFuturesSubmitOrders(t.Context(), asset.USDTMarginedFutures, out)
|
|
require.ErrorIs(t, err, errInvalidAmount)
|
|
|
|
out.Size = 1 // 1 lovely long contract
|
|
out.AutoSize = "silly_billies"
|
|
_, err = e.WebsocketFuturesSubmitOrders(t.Context(), asset.USDTMarginedFutures, out)
|
|
require.ErrorIs(t, err, errInvalidAutoSize)
|
|
|
|
out.AutoSize = "close_long"
|
|
_, err = e.WebsocketFuturesSubmitOrders(t.Context(), asset.USDTMarginedFutures, out)
|
|
require.ErrorIs(t, err, errInvalidAmount)
|
|
|
|
out.AutoSize = ""
|
|
|
|
sharedtestvalues.SkipTestIfCredentialsUnset(t, e, canManipulateRealOrders)
|
|
|
|
g := newExchangeWithWebsocket(t, asset.Futures)
|
|
|
|
// test single order
|
|
got, err := g.WebsocketFuturesSubmitOrders(t.Context(), asset.CoinMarginedFutures, out)
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, got)
|
|
|
|
// test batch orders
|
|
got, err = g.WebsocketFuturesSubmitOrders(t.Context(), asset.CoinMarginedFutures, out, out)
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, got)
|
|
}
|
|
|
|
func TestWebsocketFuturesCancelOrder(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := e.WebsocketFuturesCancelOrder(t.Context(), "", currency.EMPTYPAIR, asset.Empty)
|
|
require.ErrorIs(t, err, order.ErrOrderIDNotSet)
|
|
|
|
_, err = e.WebsocketFuturesCancelOrder(t.Context(), "42069", currency.EMPTYPAIR, asset.Empty)
|
|
require.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)
|
|
|
|
_, err = e.WebsocketFuturesCancelOrder(t.Context(), "42069", BTCUSDT, asset.Empty)
|
|
require.ErrorIs(t, err, asset.ErrNotSupported)
|
|
|
|
sharedtestvalues.SkipTestIfCredentialsUnset(t, e, canManipulateRealOrders)
|
|
|
|
g := newExchangeWithWebsocket(t, asset.Futures)
|
|
|
|
got, err := g.WebsocketFuturesCancelOrder(t.Context(), "513160761072", BTCUSDT, asset.USDTMarginedFutures)
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, got)
|
|
}
|
|
|
|
func TestWebsocketFuturesCancelAllOpenFuturesOrders(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := e.WebsocketFuturesCancelAllOpenFuturesOrders(t.Context(), currency.EMPTYPAIR, asset.Empty, "")
|
|
require.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)
|
|
|
|
_, err = e.WebsocketFuturesCancelAllOpenFuturesOrders(t.Context(), BTCUSDT, asset.Empty, "bruh")
|
|
require.ErrorIs(t, err, asset.ErrNotSupported)
|
|
|
|
_, err = e.WebsocketFuturesCancelAllOpenFuturesOrders(t.Context(), BTCUSDT, asset.USDTMarginedFutures, "bruh")
|
|
require.ErrorIs(t, err, order.ErrSideIsInvalid)
|
|
|
|
sharedtestvalues.SkipTestIfCredentialsUnset(t, e, canManipulateRealOrders)
|
|
|
|
g := newExchangeWithWebsocket(t, asset.Futures)
|
|
|
|
got, err := g.WebsocketFuturesCancelAllOpenFuturesOrders(t.Context(), BTCUSDT, asset.USDTMarginedFutures, "bid")
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, got)
|
|
}
|
|
|
|
func TestWebsocketFuturesAmendOrder(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := e.WebsocketFuturesAmendOrder(t.Context(), nil)
|
|
require.ErrorIs(t, err, common.ErrNilPointer)
|
|
|
|
amend := &WebsocketFuturesAmendOrder{}
|
|
_, err = e.WebsocketFuturesAmendOrder(t.Context(), amend)
|
|
require.ErrorIs(t, err, order.ErrOrderIDNotSet)
|
|
|
|
amend.OrderID = "1337"
|
|
_, err = e.WebsocketFuturesAmendOrder(t.Context(), amend)
|
|
require.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)
|
|
|
|
amend.Contract = BTCUSDT
|
|
_, err = e.WebsocketFuturesAmendOrder(t.Context(), amend)
|
|
require.ErrorIs(t, err, asset.ErrNotSupported)
|
|
|
|
amend.Asset = asset.USDTMarginedFutures
|
|
_, err = e.WebsocketFuturesAmendOrder(t.Context(), amend)
|
|
require.ErrorIs(t, err, errInvalidAmount)
|
|
|
|
amend.Size = 2
|
|
|
|
sharedtestvalues.SkipTestIfCredentialsUnset(t, e, canManipulateRealOrders)
|
|
|
|
g := newExchangeWithWebsocket(t, asset.Futures)
|
|
|
|
amend.OrderID = "513170215869"
|
|
got, err := g.WebsocketFuturesAmendOrder(t.Context(), amend)
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, got)
|
|
}
|
|
|
|
func TestWebsocketFuturesOrderList(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := e.WebsocketFuturesOrderList(t.Context(), nil)
|
|
require.ErrorIs(t, err, common.ErrNilPointer)
|
|
|
|
list := &WebsocketFutureOrdersList{}
|
|
_, err = e.WebsocketFuturesOrderList(t.Context(), list)
|
|
require.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)
|
|
|
|
list.Contract = BTCUSDT
|
|
_, err = e.WebsocketFuturesOrderList(t.Context(), list)
|
|
require.ErrorIs(t, err, asset.ErrNotSupported)
|
|
|
|
list.Asset = asset.USDTMarginedFutures
|
|
_, err = e.WebsocketFuturesOrderList(t.Context(), list)
|
|
require.ErrorIs(t, err, errStatusNotSet)
|
|
|
|
sharedtestvalues.SkipTestIfCredentialsUnset(t, e, canManipulateRealOrders)
|
|
|
|
g := newExchangeWithWebsocket(t, asset.Futures)
|
|
|
|
list.Status = statusOpen
|
|
got, err := g.WebsocketFuturesOrderList(t.Context(), list)
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, got)
|
|
}
|
|
|
|
func TestWebsocketFuturesGetOrderStatus(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := e.WebsocketFuturesGetOrderStatus(t.Context(), currency.EMPTYPAIR, asset.Empty, "")
|
|
require.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)
|
|
|
|
_, err = e.WebsocketFuturesGetOrderStatus(t.Context(), BTCUSDT, asset.Empty, "")
|
|
require.ErrorIs(t, err, asset.ErrNotSupported)
|
|
|
|
_, err = e.WebsocketFuturesGetOrderStatus(t.Context(), BTCUSDT, asset.USDTMarginedFutures, "")
|
|
require.ErrorIs(t, err, order.ErrOrderIDNotSet)
|
|
|
|
sharedtestvalues.SkipTestIfCredentialsUnset(t, e, canManipulateRealOrders)
|
|
|
|
g := newExchangeWithWebsocket(t, asset.Futures)
|
|
|
|
got, err := g.WebsocketFuturesGetOrderStatus(t.Context(), BTCUSDT, asset.USDTMarginedFutures, "513170215869")
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, got)
|
|
}
|