diff --git a/exchanges/coinbasepro/coinbasepro.go b/exchanges/coinbasepro/coinbasepro.go index 9bdf976b..0042ef6e 100644 --- a/exchanges/coinbasepro/coinbasepro.go +++ b/exchanges/coinbasepro/coinbasepro.go @@ -334,7 +334,7 @@ func (c *CoinbasePro) GetHolds(ctx context.Context, accountID string) ([]Account // timeInforce - [optional] GTC, GTT, IOC, or FOK (default is GTC) // cancelAfter - [optional] min, hour, day * Requires time_in_force to be GTT // postOnly - [optional] Post only flag Invalid when time_in_force is IOC or FOK -func (c *CoinbasePro) PlaceLimitOrder(ctx context.Context, clientRef string, price, amount float64, side, timeInforce, cancelAfter, productID, stp string, postOnly bool) (string, error) { +func (c *CoinbasePro) PlaceLimitOrder(ctx context.Context, clientRef string, price, amount float64, side string, timeInforce RequestParamsTimeForceType, cancelAfter, productID, stp string, postOnly bool) (string, error) { resp := GeneralizedOrderResponse{} req := make(map[string]interface{}) req["type"] = order.Limit.Lower() @@ -347,7 +347,7 @@ func (c *CoinbasePro) PlaceLimitOrder(ctx context.Context, clientRef string, pri req["cancel_after"] = cancelAfter } if timeInforce != "" { - req["time_in_foce"] = timeInforce + req["time_in_force"] = timeInforce } if clientRef != "" { req["client_oid"] = clientRef diff --git a/exchanges/coinbasepro/coinbasepro_types.go b/exchanges/coinbasepro/coinbasepro_types.go index 17e4b473..6aa841f3 100644 --- a/exchanges/coinbasepro/coinbasepro_types.go +++ b/exchanges/coinbasepro/coinbasepro_types.go @@ -477,3 +477,14 @@ type wsStatus struct { } `json:"products"` Type string `json:"type"` } + +// RequestParamsTimeForceType Time in force +type RequestParamsTimeForceType string + +var ( + // CoinbaseRequestParamsTimeGTC GTC + CoinbaseRequestParamsTimeGTC = RequestParamsTimeForceType("GTC") + + // CoinbaseRequestParamsTimeIOC IOC + CoinbaseRequestParamsTimeIOC = RequestParamsTimeForceType("IOC") +) diff --git a/exchanges/coinbasepro/coinbasepro_wrapper.go b/exchanges/coinbasepro/coinbasepro_wrapper.go index 87ee52a9..51d941e2 100644 --- a/exchanges/coinbasepro/coinbasepro_wrapper.go +++ b/exchanges/coinbasepro/coinbasepro_wrapper.go @@ -554,12 +554,16 @@ func (c *CoinbasePro) SubmitOrder(ctx context.Context, s *order.Submit) (*order. fpair.String(), "") case order.Limit: + timeInForce := CoinbaseRequestParamsTimeGTC + if s.ImmediateOrCancel { + timeInForce = CoinbaseRequestParamsTimeIOC + } orderID, err = c.PlaceLimitOrder(ctx, "", s.Price, s.Amount, s.Side.Lower(), - "", + timeInForce, "", fpair.String(), "", diff --git a/exchanges/kraken/kraken.go b/exchanges/kraken/kraken.go index a7e9b3d8..179439e0 100644 --- a/exchanges/kraken/kraken.go +++ b/exchanges/kraken/kraken.go @@ -952,6 +952,10 @@ func (k *Kraken) AddOrder(ctx context.Context, symbol currency.Pair, side, order params.Set("validate", "true") } + if args.TimeInForce != "" { + params.Set("timeinforce", string(args.TimeInForce)) + } + if err := k.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, krakenOrderPlace, params, &response); err != nil { return response.Result, err } diff --git a/exchanges/kraken/kraken_types.go b/exchanges/kraken/kraken_types.go index 21abfa20..10141f33 100644 --- a/exchanges/kraken/kraken_types.go +++ b/exchanges/kraken/kraken_types.go @@ -409,6 +409,7 @@ type AddOrderOptions struct { ClosePrice float64 ClosePrice2 float64 Validate bool + TimeInForce RequestParamsTimeForceType } // CancelOrderResponse type @@ -654,24 +655,25 @@ type WsOpenOrderDescription struct { // WsAddOrderRequest request type for ws adding order type WsAddOrderRequest struct { - Event string `json:"event"` - Token string `json:"token"` - RequestID int64 `json:"reqid,omitempty"` // Optional, client originated ID reflected in response message. - OrderType string `json:"ordertype"` - OrderSide string `json:"type"` - Pair string `json:"pair"` - Price float64 `json:"price,string,omitempty"` // optional - Price2 float64 `json:"price2,string,omitempty"` // optional - Volume float64 `json:"volume,string,omitempty"` - Leverage float64 `json:"leverage,omitempty"` // optional - OFlags string `json:"oflags,omitempty"` // optional - StartTime string `json:"starttm,omitempty"` // optional - ExpireTime string `json:"expiretm,omitempty"` // optional - UserReferenceID string `json:"userref,omitempty"` // optional - Validate string `json:"validate,omitempty"` // optional - CloseOrderType string `json:"close[ordertype],omitempty"` // optional - ClosePrice float64 `json:"close[price],omitempty"` // optional - ClosePrice2 float64 `json:"close[price2],omitempty"` // optional + Event string `json:"event"` + Token string `json:"token"` + RequestID int64 `json:"reqid,omitempty"` // Optional, client originated ID reflected in response message. + OrderType string `json:"ordertype"` + OrderSide string `json:"type"` + Pair string `json:"pair"` + Price float64 `json:"price,string,omitempty"` // optional + Price2 float64 `json:"price2,string,omitempty"` // optional + Volume float64 `json:"volume,string,omitempty"` + Leverage float64 `json:"leverage,omitempty"` // optional + OFlags string `json:"oflags,omitempty"` // optional + StartTime string `json:"starttm,omitempty"` // optional + ExpireTime string `json:"expiretm,omitempty"` // optional + UserReferenceID string `json:"userref,omitempty"` // optional + Validate string `json:"validate,omitempty"` // optional + CloseOrderType string `json:"close[ordertype],omitempty"` // optional + ClosePrice float64 `json:"close[price],omitempty"` // optional + ClosePrice2 float64 `json:"close[price2],omitempty"` // optional + TimeInForce RequestParamsTimeForceType `json:"timeinforce,omitempty"` // optional } // WsAddOrderResponse response data for ws order @@ -708,3 +710,14 @@ type OrderVars struct { OrderType order.Type Fee float64 } + +// RequestParamsTimeForceType Time in force +type RequestParamsTimeForceType string + +var ( + // KrakenRequestParamsTimeGTC GTC + KrakenRequestParamsTimeGTC = RequestParamsTimeForceType("GTC") + + // KrakenRequestParamsTimeIOC IOC + KrakenRequestParamsTimeIOC = RequestParamsTimeForceType("IOC") +) diff --git a/exchanges/kraken/kraken_wrapper.go b/exchanges/kraken/kraken_wrapper.go index 73f25708..d5f23f4e 100644 --- a/exchanges/kraken/kraken_wrapper.go +++ b/exchanges/kraken/kraken_wrapper.go @@ -726,14 +726,19 @@ func (k *Kraken) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Submi status := order.New switch s.AssetType { case asset.Spot: + timeInForce := KrakenRequestParamsTimeGTC + if s.ImmediateOrCancel { + timeInForce = KrakenRequestParamsTimeIOC + } if k.Websocket.CanUseAuthenticatedWebsocketForWrapper() { s.Pair.Delimiter = "/" // required pair format: ISO 4217-A3 orderID, err = k.wsAddOrder(&WsAddOrderRequest{ - OrderType: s.Type.Lower(), - OrderSide: s.Side.Lower(), - Pair: s.Pair.String(), - Price: s.Price, - Volume: s.Amount, + OrderType: s.Type.Lower(), + OrderSide: s.Side.Lower(), + Pair: s.Pair.String(), + Price: s.Price, + Volume: s.Amount, + TimeInForce: timeInForce, }) if err != nil { return nil, err @@ -748,7 +753,9 @@ func (k *Kraken) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Submi s.Price, 0, 0, - &AddOrderOptions{}) + &AddOrderOptions{ + TimeInForce: timeInForce, + }) if err != nil { return nil, err }