mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-01 15:10:44 +00:00
gctrpc/order manager: Add ModifyOrder endpoint (#724)
* gctcli: modifyorder stubs * gctcli: add ModifyOrderRequest and ModifyOrderResponse in rpc.proto * gctcli: regenerate rpc.pb.go after the addition of ModifyOrder structs * gctrpc: add ModifyOrder() and regenerate dependent files * gctcli: modifyorder command now uses newly generated ModifyOrder() RPC * exchanges/order/orders.go: use time.Time.Equal() instead of == * gctrpc: update ModifyOrderRequest and ModifyResponse and regenerate gRPC * gctcli/commands: rework modifyorder * engine: implement RPCServer.ModifyOrder * engine: commit an initial version OrderManager.Modify(), still does not update state of managed orders * engine: OrderManager.Modify now updates the inner state of managed orders, but introduces race conditions, needs fixes * engine/order_manager.go: comply with golangci-lint * gctcli: fix getOrderCommand.ArgsUsage * gctcli: fix getModifyOrderCommand args and ArgsUsage * engine: OrderManager.Modify() now correctly updates price of modified order * engine: RPCServer.ModifyOrder now uses checkParams() as advised * exchanges: (1) IBotExchange.ModifyOrder now returns a Modify struct, (2) all exchanges are updated to comply with that change * exchanges/order: Detail.UpdateOrderFromModify also updates the ID * engine/order_manager: add store.modifyExisting() and use it in OrderManager.Modify to update (on success) the state of the modified order * exchanges: Bitfinex.ModifyOrder() now returns the ID in case of an error * engine: OrdetManager.Modify() now emits an order event * exchanges/bithumb: proper order.payment_currency key * engine/order_manager: populate more Modify fields as they are needed by (some) exchanges, add comments * engine: test OrderManager.Modify() * engine: test store.modifyExisting() * engine: write a docstring for store.modifyExisting * engine: OrderManager.Modify() now also sets Modify.Price and Modify.Amount in case of zero values * engine: TestOrderManager_Modify() now verify the effects of price and/or amount set to 0 * engine: OrderManger.Modify() now uses the commsManager to let observers know of errors * engine: TestOrderManager_Modify() uses t.Fatal() * engine: TestOrderManager_Modify() and TestStore_modifyOrder() supply t.Error() with proper messages * exchanges/order_manager_test: fix a golangci-lint complaint * engine/order_manager: fix an error comparison bug and simplify * gctcli/commands: check if either price or amount is set, otherwise we would waste an API call
This commit is contained in:
@@ -314,7 +314,7 @@ func (b *Bithumb) PlaceTrade(orderCurrency, transactionType string, units float6
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("order_currency", strings.ToUpper(orderCurrency))
|
||||
params.Set("Payment_currency", "KRW")
|
||||
params.Set("payment_currency", "KRW")
|
||||
params.Set("type", strings.ToUpper(transactionType))
|
||||
params.Set("units", strconv.FormatFloat(units, 'f', -1, 64))
|
||||
params.Set("price", strconv.FormatInt(price, 10))
|
||||
@@ -329,7 +329,7 @@ func (b *Bithumb) ModifyTrade(orderID, orderCurrency, transactionType string, un
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("order_currency", strings.ToUpper(orderCurrency))
|
||||
params.Set("Payment_currency", "KRW")
|
||||
params.Set("payment_currency", "KRW")
|
||||
params.Set("type", strings.ToUpper(transactionType))
|
||||
params.Set("units", strconv.FormatFloat(units, 'f', -1, 64))
|
||||
params.Set("price", strconv.FormatInt(price, 10))
|
||||
|
||||
@@ -438,22 +438,31 @@ func (b *Bithumb) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (b *Bithumb) ModifyOrder(action *order.Modify) (string, error) {
|
||||
func (b *Bithumb) ModifyOrder(action *order.Modify) (order.Modify, error) {
|
||||
if err := action.Validate(); err != nil {
|
||||
return "", err
|
||||
return order.Modify{}, err
|
||||
}
|
||||
|
||||
order, err := b.ModifyTrade(action.ID,
|
||||
o, err := b.ModifyTrade(action.ID,
|
||||
action.Pair.Base.String(),
|
||||
action.Side.Lower(),
|
||||
action.Amount,
|
||||
int64(action.Price))
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
return order.Modify{}, err
|
||||
}
|
||||
|
||||
return order.Data[0].ContID, nil
|
||||
return order.Modify{
|
||||
Exchange: action.Exchange,
|
||||
AssetType: action.AssetType,
|
||||
Pair: action.Pair,
|
||||
ID: o.Data[0].ContID,
|
||||
|
||||
Price: float64(int64(action.Price)),
|
||||
Amount: action.Amount,
|
||||
Side: action.Side,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
|
||||
Reference in New Issue
Block a user