mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-30 23:16:52 +00:00
gctrpc/ordermanager/binance: Add new getManagedOrders command and various improvements (#712)
* first draft of getmanaged orders RPC call * - ClientIDs for binance, especially spot asset - applied old ClientOrderId for cancelled orders - added clientOrderId to GCTRPC * added tests for Matchfilter and GetManagedOrders * smaller fixes * comment fix added getFilteredOrders to store changed store mutex to RWMutex smaller fixes * fixed bug in Detail Copy and added test * fixes for Scotts review * processSubmittedOrder was missing clientOrderId * changed: TestGetOrdersFiltered expanded fixed: warning, where variable name collided with package name fixed: used req.AssetType in binance_wrapper.go Co-authored-by: Mark Dzulko <81071907+Mark-numus@users.noreply.github.com>
This commit is contained in:
@@ -526,7 +526,7 @@ func (b *Binance) newOrder(api string, o *NewOrderRequest, resp *NewOrderRespons
|
||||
}
|
||||
|
||||
if o.NewClientOrderID != "" {
|
||||
params.Set("newClientOrderID", o.NewClientOrderID)
|
||||
params.Set("newClientOrderId", o.NewClientOrderID)
|
||||
}
|
||||
|
||||
if o.StopPrice != 0 {
|
||||
|
||||
@@ -2498,7 +2498,7 @@ func TestWsOrderExecutionReport(t *testing.T) {
|
||||
Amount: 0.00028400,
|
||||
Exchange: "Binance",
|
||||
ID: "5340845958",
|
||||
ClientID: "c4wyKsIhoAaittTYlIVLqk",
|
||||
ClientOrderID: "c4wyKsIhoAaittTYlIVLqk",
|
||||
Side: order.Buy,
|
||||
Type: order.Limit,
|
||||
Status: order.New,
|
||||
|
||||
@@ -240,6 +240,10 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
clientOrderID := data.Data.ClientOrderID
|
||||
if oStatus == order.Cancelled {
|
||||
clientOrderID = data.Data.CancelledClientOrderID
|
||||
}
|
||||
b.Websocket.DataHandler <- &order.Detail{
|
||||
Price: data.Data.Price,
|
||||
Amount: data.Data.Quantity,
|
||||
@@ -253,7 +257,7 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
AssetType: a,
|
||||
Date: data.Data.OrderCreationTime,
|
||||
Pair: p,
|
||||
ClientID: data.Data.ClientOrderID,
|
||||
ClientOrderID: clientOrderID,
|
||||
}
|
||||
return nil
|
||||
case "listStatus":
|
||||
|
||||
@@ -805,12 +805,13 @@ func (b *Binance) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
}
|
||||
|
||||
var orderRequest = NewOrderRequest{
|
||||
Symbol: s.Pair,
|
||||
Side: sideType,
|
||||
Price: s.Price,
|
||||
Quantity: s.Amount,
|
||||
TradeType: requestParamsOrderType,
|
||||
TimeInForce: timeInForce,
|
||||
Symbol: s.Pair,
|
||||
Side: sideType,
|
||||
Price: s.Price,
|
||||
Quantity: s.Amount,
|
||||
TradeType: requestParamsOrderType,
|
||||
TimeInForce: timeInForce,
|
||||
NewClientOrderID: s.ClientOrderID,
|
||||
}
|
||||
response, err := b.NewOrder(&orderRequest)
|
||||
if err != nil {
|
||||
@@ -864,14 +865,14 @@ func (b *Binance) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
default:
|
||||
return submitOrderResponse, errors.New("invalid type, check api docs for updates")
|
||||
}
|
||||
order, err := b.FuturesNewOrder(s.Pair, reqSide,
|
||||
o, err := b.FuturesNewOrder(s.Pair, reqSide,
|
||||
"", oType, "GTC", "",
|
||||
s.ClientOrderID, "", "",
|
||||
s.Amount, s.Price, 0, 0, 0, s.ReduceOnly)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(order.OrderID, 10)
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(o.OrderID, 10)
|
||||
submitOrderResponse.IsOrderPlaced = true
|
||||
case asset.USDTMarginedFutures:
|
||||
var reqSide string
|
||||
@@ -1050,6 +1051,7 @@ func (b *Binance) GetOrderInfo(orderID string, pair currency.Pair, assetType ass
|
||||
Amount: resp.OrigQty,
|
||||
Exchange: b.Name,
|
||||
ID: strconv.FormatInt(resp.OrderID, 10),
|
||||
ClientOrderID: resp.ClientOrderID,
|
||||
Side: orderSide,
|
||||
Type: orderType,
|
||||
Pair: pair,
|
||||
@@ -1191,17 +1193,18 @@ func (b *Binance) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
orderSide := order.Side(strings.ToUpper(resp[x].Side))
|
||||
orderType := order.Type(strings.ToUpper(resp[x].Type))
|
||||
orders = append(orders, order.Detail{
|
||||
Amount: resp[x].OrigQty,
|
||||
Date: resp[x].Time,
|
||||
Exchange: b.Name,
|
||||
ID: strconv.FormatInt(resp[x].OrderID, 10),
|
||||
Side: orderSide,
|
||||
Type: orderType,
|
||||
Price: resp[x].Price,
|
||||
Status: order.Status(resp[x].Status),
|
||||
Pair: req.Pairs[i],
|
||||
AssetType: asset.Spot,
|
||||
LastUpdated: resp[x].UpdateTime,
|
||||
Amount: resp[x].OrigQty,
|
||||
Date: resp[x].Time,
|
||||
Exchange: b.Name,
|
||||
ID: strconv.FormatInt(resp[x].OrderID, 10),
|
||||
ClientOrderID: resp[x].ClientOrderID,
|
||||
Side: orderSide,
|
||||
Type: orderType,
|
||||
Price: resp[x].Price,
|
||||
Status: order.Status(resp[x].Status),
|
||||
Pair: req.Pairs[i],
|
||||
AssetType: req.AssetType,
|
||||
LastUpdated: resp[x].UpdateTime,
|
||||
})
|
||||
}
|
||||
case asset.CoinMarginedFutures:
|
||||
|
||||
Reference in New Issue
Block a user