mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +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:
@@ -585,7 +585,7 @@ func (d *Deribit) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Subm
|
||||
return nil, err
|
||||
}
|
||||
timeInForce := ""
|
||||
if s.ImmediateOrCancel {
|
||||
if s.TimeInForce.Is(order.ImmediateOrCancel) {
|
||||
timeInForce = "immediate_or_cancel"
|
||||
}
|
||||
var data *PrivateTradeData
|
||||
@@ -597,7 +597,7 @@ func (d *Deribit) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Subm
|
||||
Amount: s.Amount,
|
||||
Price: s.Price,
|
||||
TriggerPrice: s.TriggerPrice,
|
||||
PostOnly: s.PostOnly,
|
||||
PostOnly: s.TimeInForce.Is(order.PostOnly),
|
||||
ReduceOnly: s.ReduceOnly,
|
||||
}
|
||||
switch {
|
||||
@@ -649,7 +649,7 @@ func (d *Deribit) ModifyOrder(ctx context.Context, action *order.Modify) (*order
|
||||
var err error
|
||||
reqParam := &OrderBuyAndSellParams{
|
||||
TriggerPrice: action.TriggerPrice,
|
||||
PostOnly: action.PostOnly,
|
||||
PostOnly: action.TimeInForce.Is(order.PostOnly),
|
||||
Amount: action.Amount,
|
||||
OrderID: action.OrderID,
|
||||
Price: action.Price,
|
||||
@@ -773,10 +773,15 @@ func (d *Deribit) GetOrderInfo(ctx context.Context, orderID string, _ currency.P
|
||||
return nil, fmt.Errorf("%v: orderStatus %s not supported", d.Name, orderInfo.OrderState)
|
||||
}
|
||||
}
|
||||
var tif order.TimeInForce
|
||||
tif, err = timeInForceFromString(orderInfo.TimeInForce, orderInfo.PostOnly)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &order.Detail{
|
||||
AssetType: assetType,
|
||||
Exchange: d.Name,
|
||||
PostOnly: orderInfo.PostOnly,
|
||||
TimeInForce: tif,
|
||||
Price: orderInfo.Price,
|
||||
Amount: orderInfo.Amount,
|
||||
ExecutedAmount: orderInfo.FilledAmount,
|
||||
@@ -894,10 +899,15 @@ func (d *Deribit) GetActiveOrders(ctx context.Context, getOrdersRequest *order.M
|
||||
if ordersData[y].OrderState != "open" {
|
||||
continue
|
||||
}
|
||||
|
||||
var tif order.TimeInForce
|
||||
tif, err = timeInForceFromString(ordersData[y].TimeInForce, ordersData[y].PostOnly)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp = append(resp, order.Detail{
|
||||
AssetType: getOrdersRequest.AssetType,
|
||||
Exchange: d.Name,
|
||||
PostOnly: ordersData[y].PostOnly,
|
||||
Price: ordersData[y].Price,
|
||||
Amount: ordersData[y].Amount,
|
||||
ExecutedAmount: ordersData[y].FilledAmount,
|
||||
@@ -909,6 +919,7 @@ func (d *Deribit) GetActiveOrders(ctx context.Context, getOrdersRequest *order.M
|
||||
Side: orderSide,
|
||||
Type: orderType,
|
||||
Status: orderStatus,
|
||||
TimeInForce: tif,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -963,10 +974,15 @@ func (d *Deribit) GetOrderHistory(ctx context.Context, getOrdersRequest *order.M
|
||||
return resp, fmt.Errorf("%v: orderStatus %s not supported", d.Name, ordersData[y].OrderState)
|
||||
}
|
||||
}
|
||||
|
||||
var tif order.TimeInForce
|
||||
tif, err = timeInForceFromString(ordersData[y].TimeInForce, ordersData[y].PostOnly)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp = append(resp, order.Detail{
|
||||
AssetType: getOrdersRequest.AssetType,
|
||||
Exchange: d.Name,
|
||||
PostOnly: ordersData[y].PostOnly,
|
||||
Price: ordersData[y].Price,
|
||||
Amount: ordersData[y].Amount,
|
||||
ExecutedAmount: ordersData[y].FilledAmount,
|
||||
@@ -978,6 +994,7 @@ func (d *Deribit) GetOrderHistory(ctx context.Context, getOrdersRequest *order.M
|
||||
Side: orderSide,
|
||||
Type: orderType,
|
||||
Status: orderStatus,
|
||||
TimeInForce: tif,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1555,3 +1572,14 @@ func (d *Deribit) formatPairString(assetType asset.Item, pair currency.Pair) str
|
||||
}
|
||||
return pair.String()
|
||||
}
|
||||
|
||||
func timeInForceFromString(timeInForceString string, postOnly bool) (order.TimeInForce, error) {
|
||||
tif, err := order.StringToTimeInForce(timeInForceString)
|
||||
if err != nil {
|
||||
return order.UnknownTIF, err
|
||||
}
|
||||
if postOnly {
|
||||
tif |= order.PostOnly
|
||||
}
|
||||
return tif, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user