mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
coinbase/kraken: Add IOC support to SubmitOrder wrappers (#1025)
* add IOC support to coinbase and kraken wrappers * fix lint * use explicit TimeInForce type * fix kraken param * fix fmt * fix time_in_force
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
)
|
||||
|
||||
@@ -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(),
|
||||
"",
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user