mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 23:16:53 +00:00
exchanges/order: Add TimeInForce type (#1382)
* 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 * fix conflict with gateio timeInForce * Update order tests * Complete updating the order unit tests * update kucoin and deribit wrapper to match the time in force change * fix time-in-force related test errors * linter issue fix * 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 * 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 * updated order test unit tes functions * minor fixes on unit tests * nits fix based on feedback * update TestDeriveCancel unit test assert messages * update TestDeriveCancel unit test assert messages * update timeInForceFromString method to return formatted error and update functions using it * restructure and fix minor exchanges time-in-force handling issues * replaced unused getTypeFromTimeInForce with inline switch-based order type check * separated the repeated timeInForce conversion code to a function * update exchanges time-in-force handling based on review comments * limter fix * edded comment to validTimesInForce var * added comment to gateio's timeInForceString func * added goodTillCancel switch case to gateio timeInForceString func
This commit is contained in:
@@ -613,7 +613,7 @@ func (b *Binance) newOrder(ctx context.Context, api string, o *NewOrderRequest,
|
||||
params.Set("price", strconv.FormatFloat(o.Price, 'f', -1, 64))
|
||||
}
|
||||
if o.TimeInForce != "" {
|
||||
params.Set("timeInForce", string(o.TimeInForce))
|
||||
params.Set("timeInForce", o.TimeInForce)
|
||||
}
|
||||
|
||||
if o.NewClientOrderID != "" {
|
||||
|
||||
@@ -991,8 +991,8 @@ func (b *Binance) FuturesNewOrder(ctx context.Context, x *FuturesNewOrderRequest
|
||||
params.Set("positionSide", x.PositionSide)
|
||||
}
|
||||
params.Set("type", x.OrderType)
|
||||
if string(x.TimeInForce) != "" {
|
||||
params.Set("timeInForce", string(x.TimeInForce))
|
||||
if x.TimeInForce != "" {
|
||||
params.Set("timeInForce", x.TimeInForce)
|
||||
}
|
||||
if x.ReduceOnly {
|
||||
params.Set("reduceOnly", "true")
|
||||
|
||||
@@ -865,7 +865,7 @@ func TestFuturesNewOrder(t *testing.T) {
|
||||
Symbol: currency.NewPairWithDelimiter("BTCUSD", "PERP", "_"),
|
||||
Side: "BUY",
|
||||
OrderType: "LIMIT",
|
||||
TimeInForce: BinanceRequestParamsTimeGTC,
|
||||
TimeInForce: order.GoodTillCancel.String(),
|
||||
Quantity: 1,
|
||||
Price: 1,
|
||||
},
|
||||
@@ -1418,7 +1418,7 @@ func TestNewOrderTest(t *testing.T) {
|
||||
TradeType: BinanceRequestParamsOrderLimit,
|
||||
Price: 0.0025,
|
||||
Quantity: 100000,
|
||||
TimeInForce: BinanceRequestParamsTimeGTC,
|
||||
TimeInForce: order.GoodTillCancel.String(),
|
||||
}
|
||||
|
||||
err := b.NewOrderTest(t.Context(), req)
|
||||
|
||||
@@ -375,7 +375,7 @@ type NewOrderRequest struct {
|
||||
TradeType RequestParamsOrderType
|
||||
// TimeInForce specifies how long the order remains in effect.
|
||||
// Examples are (Good Till Cancel (GTC), Immediate or Cancel (IOC) and Fill Or Kill (FOK))
|
||||
TimeInForce RequestParamsTimeForceType
|
||||
TimeInForce string
|
||||
// Quantity is the total base qty spent or received in an order.
|
||||
Quantity float64
|
||||
// QuoteOrderQty is the total quote qty spent or received in a MARKET order.
|
||||
@@ -486,20 +486,6 @@ type MarginAccountAsset struct {
|
||||
NetAsset float64 `json:"netAsset,string"`
|
||||
}
|
||||
|
||||
// RequestParamsTimeForceType Time in force
|
||||
type RequestParamsTimeForceType string
|
||||
|
||||
var (
|
||||
// BinanceRequestParamsTimeGTC GTC
|
||||
BinanceRequestParamsTimeGTC = RequestParamsTimeForceType("GTC")
|
||||
|
||||
// BinanceRequestParamsTimeIOC IOC
|
||||
BinanceRequestParamsTimeIOC = RequestParamsTimeForceType("IOC")
|
||||
|
||||
// BinanceRequestParamsTimeFOK FOK
|
||||
BinanceRequestParamsTimeFOK = RequestParamsTimeForceType("FOK")
|
||||
)
|
||||
|
||||
// RequestParamsOrderType trade order type
|
||||
type RequestParamsOrderType string
|
||||
|
||||
|
||||
@@ -864,15 +864,15 @@ func (b *Binance) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Subm
|
||||
} else {
|
||||
sideType = order.Sell.String()
|
||||
}
|
||||
timeInForce := BinanceRequestParamsTimeGTC
|
||||
timeInForce := order.GoodTillCancel.String()
|
||||
var requestParamsOrderType RequestParamsOrderType
|
||||
switch s.Type {
|
||||
case order.Market:
|
||||
timeInForce = ""
|
||||
requestParamsOrderType = BinanceRequestParamsOrderMarket
|
||||
case order.Limit:
|
||||
if s.ImmediateOrCancel {
|
||||
timeInForce = BinanceRequestParamsTimeIOC
|
||||
if s.TimeInForce.Is(order.ImmediateOrCancel) {
|
||||
timeInForce = order.ImmediateOrCancel.String()
|
||||
}
|
||||
requestParamsOrderType = BinanceRequestParamsOrderLimit
|
||||
default:
|
||||
@@ -918,15 +918,11 @@ func (b *Binance) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Subm
|
||||
return nil, errors.New("invalid side")
|
||||
}
|
||||
|
||||
var (
|
||||
oType string
|
||||
timeInForce RequestParamsTimeForceType
|
||||
)
|
||||
|
||||
var oType, timeInForce string
|
||||
switch s.Type {
|
||||
case order.Limit:
|
||||
oType = cfuturesLimit
|
||||
timeInForce = BinanceRequestParamsTimeGTC
|
||||
timeInForce = order.GoodTillCancel.String()
|
||||
case order.Market:
|
||||
oType = cfuturesMarket
|
||||
case order.Stop:
|
||||
|
||||
@@ -213,7 +213,7 @@ type FuturesNewOrderRequest struct {
|
||||
Side string
|
||||
PositionSide string
|
||||
OrderType string
|
||||
TimeInForce RequestParamsTimeForceType
|
||||
TimeInForce string
|
||||
NewClientOrderID string
|
||||
ClosePosition string
|
||||
WorkingType string
|
||||
|
||||
Reference in New Issue
Block a user