From 16a93b49a4ec3ebf3b776ee7317383354e670ec7 Mon Sep 17 00:00:00 2001 From: Ryan O'Hara-Reid Date: Mon, 16 May 2022 10:55:23 +1000 Subject: [PATCH] btcm: add modify order functionality, change return to pointer (#940) * btcm: add modify order functionality, change return to pointer * glorious: nits * glorious: nits * btcm: Adjust function name * thrasher: nits * thrasher: nits cont... --- README.md | 10 ++-- cmd/exchange_template/wrapper_file.tmpl | 4 +- engine/order_manager.go | 2 +- engine/order_manager_test.go | 4 +- exchanges/binance/binance_wrapper.go | 4 +- exchanges/bitfinex/bitfinex_wrapper.go | 15 +++--- exchanges/bitflyer/bitflyer_wrapper.go | 4 +- exchanges/bithumb/bithumb_wrapper.go | 16 +++--- exchanges/bitmex/bitmex_wrapper.go | 15 +++--- exchanges/bitstamp/bitstamp_wrapper.go | 4 +- exchanges/bittrex/bittrex_wrapper.go | 4 +- exchanges/btcmarkets/btcmarkets.go | 39 +++++++++++++- exchanges/btcmarkets/btcmarkets_test.go | 54 +++++++++++++++++++ exchanges/btcmarkets/btcmarkets_wrapper.go | 38 ++++++++++++- exchanges/btse/btse_wrapper.go | 4 +- exchanges/coinbasepro/coinbasepro_wrapper.go | 4 +- exchanges/coinut/coinut_wrapper.go | 4 +- exchanges/exmo/exmo_wrapper.go | 4 +- exchanges/ftx/ftx_wrapper.go | 28 +++++----- exchanges/gateio/gateio_wrapper.go | 4 +- exchanges/gemini/gemini_wrapper.go | 4 +- exchanges/hitbtc/hitbtc_wrapper.go | 4 +- exchanges/huobi/huobi_wrapper.go | 4 +- exchanges/interfaces.go | 24 ++++++--- exchanges/itbit/itbit_wrapper.go | 4 +- exchanges/kraken/kraken_wrapper.go | 4 +- exchanges/lbank/lbank_wrapper.go | 4 +- .../localbitcoins/localbitcoins_wrapper.go | 4 +- exchanges/okgroup/okgroup_wrapper.go | 4 +- exchanges/order/order_test.go | 3 ++ exchanges/order/orders.go | 4 +- exchanges/poloniex/poloniex_wrapper.go | 19 ++++--- exchanges/sharedtestvalues/customex.go | 4 +- exchanges/yobit/yobit_wrapper.go | 4 +- exchanges/zb/zb_wrapper.go | 4 +- 35 files changed, 241 insertions(+), 114 deletions(-) diff --git a/README.md b/README.md index 42c441cf..8b4b909d 100644 --- a/README.md +++ b/README.md @@ -143,11 +143,11 @@ Binaries will be published once the codebase reaches a stable condition. |User|Contribution Amount| |--|--| -| [thrasher-](https://github.com/thrasher-) | 664 | -| [shazbert](https://github.com/shazbert) | 232 | -| [gloriousCode](https://github.com/gloriousCode) | 194 | +| [thrasher-](https://github.com/thrasher-) | 666 | +| [shazbert](https://github.com/shazbert) | 248 | +| [gloriousCode](https://github.com/gloriousCode) | 195 | | [dependabot-preview[bot]](https://github.com/apps/dependabot-preview) | 88 | -| [dependabot[bot]](https://github.com/apps/dependabot) | 57 | +| [dependabot[bot]](https://github.com/apps/dependabot) | 73 | | [xtda](https://github.com/xtda) | 47 | | [lrascao](https://github.com/lrascao) | 27 | | [Rots](https://github.com/Rots) | 15 | @@ -160,7 +160,7 @@ Binaries will be published once the codebase reaches a stable condition. | [marcofranssen](https://github.com/marcofranssen) | 8 | | [dackroyd](https://github.com/dackroyd) | 5 | | [cranktakular](https://github.com/cranktakular) | 5 | -| [khcchiu](https://github.com/khcchiu) | 4 | +| [khcchiu](https://github.com/khcchiu) | 5 | | [woshidama323](https://github.com/woshidama323) | 3 | | [yangrq1018](https://github.com/yangrq1018) | 3 | | [TaltaM](https://github.com/TaltaM) | 3 | diff --git a/cmd/exchange_template/wrapper_file.tmpl b/cmd/exchange_template/wrapper_file.tmpl index 15814ed2..0c723628 100644 --- a/cmd/exchange_template/wrapper_file.tmpl +++ b/cmd/exchange_template/wrapper_file.tmpl @@ -403,11 +403,11 @@ func ({{.Variable}} *{{.CapitalName}}) SubmitOrder(ctx context.Context, s *order // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func ({{.Variable}} *{{.CapitalName}}) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { +func ({{.Variable}} *{{.CapitalName}}) ModifyOrder(ctx context.Context, action *order.Modify) (*order.Modify, error) { // if err := action.Validate(); err != nil { // return "", err // } - return order.Modify{}, common.ErrNotYetImplemented + return nil, common.ErrNotYetImplemented } // CancelOrder cancels an order by its corresponding ID number diff --git a/engine/order_manager.go b/engine/order_manager.go index 5e90bc93..f2cc024f 100644 --- a/engine/order_manager.go +++ b/engine/order_manager.go @@ -401,7 +401,7 @@ func (m *OrderManager) Modify(ctx context.Context, mod *order.Modify) (*order.Mo // // XXX: This comes with a race condition, because [request -> changes] are not // atomic. - err = m.orderStore.modifyExisting(mod.ID, &res) + err = m.orderStore.modifyExisting(mod.ID, res) // Notify observers. var message string diff --git a/engine/order_manager_test.go b/engine/order_manager_test.go index 755ec584..618fdf31 100644 --- a/engine/order_manager_test.go +++ b/engine/order_manager_test.go @@ -84,10 +84,10 @@ func (f omfExchange) GetActiveOrders(ctx context.Context, req *order.GetOrdersRe }}, nil } -func (f omfExchange) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { +func (f omfExchange) ModifyOrder(ctx context.Context, action *order.Modify) (*order.Modify, error) { ans := *action ans.ID = "modified_order_id" - return ans, nil + return &ans, nil } func TestSetupOrderManager(t *testing.T) { diff --git a/exchanges/binance/binance_wrapper.go b/exchanges/binance/binance_wrapper.go index 076ed547..9270a2ec 100644 --- a/exchanges/binance/binance_wrapper.go +++ b/exchanges/binance/binance_wrapper.go @@ -1063,8 +1063,8 @@ func (b *Binance) SubmitOrder(ctx context.Context, s *order.Submit) (order.Submi // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (b *Binance) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (b *Binance) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/bitfinex/bitfinex_wrapper.go b/exchanges/bitfinex/bitfinex_wrapper.go index a608603f..1a3fb87a 100644 --- a/exchanges/bitfinex/bitfinex_wrapper.go +++ b/exchanges/bitfinex/bitfinex_wrapper.go @@ -675,14 +675,14 @@ func (b *Bitfinex) SubmitOrder(ctx context.Context, o *order.Submit) (order.Subm // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (b *Bitfinex) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { +func (b *Bitfinex) ModifyOrder(ctx context.Context, action *order.Modify) (*order.Modify, error) { if err := action.Validate(); err != nil { - return order.Modify{}, err + return nil, err } orderIDInt, err := strconv.ParseInt(action.ID, 10, 64) if err != nil { - return order.Modify{ID: action.ID}, err + return &order.Modify{ID: action.ID}, err } if b.Websocket.CanUseAuthenticatedWebsocketForWrapper() { request := WsUpdateOrderRequest{ @@ -694,17 +694,16 @@ func (b *Bitfinex) ModifyOrder(ctx context.Context, action *order.Modify) (order request.Amount *= -1 } err = b.WsModifyOrder(&request) - return order.Modify{ + return &order.Modify{ Exchange: action.Exchange, AssetType: action.AssetType, Pair: action.Pair, ID: action.ID, - - Price: action.Price, - Amount: action.Amount, + Price: action.Price, + Amount: action.Amount, }, err } - return order.Modify{}, common.ErrNotYetImplemented + return nil, common.ErrNotYetImplemented } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/bitflyer/bitflyer_wrapper.go b/exchanges/bitflyer/bitflyer_wrapper.go index 1a6022d7..0758accf 100644 --- a/exchanges/bitflyer/bitflyer_wrapper.go +++ b/exchanges/bitflyer/bitflyer_wrapper.go @@ -395,8 +395,8 @@ func (b *Bitflyer) SubmitOrder(_ context.Context, _ *order.Submit) (order.Submit // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (b *Bitflyer) ModifyOrder(_ context.Context, _ *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (b *Bitflyer) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/bithumb/bithumb_wrapper.go b/exchanges/bithumb/bithumb_wrapper.go index 4ac1dc60..beede051 100644 --- a/exchanges/bithumb/bithumb_wrapper.go +++ b/exchanges/bithumb/bithumb_wrapper.go @@ -512,9 +512,9 @@ func (b *Bithumb) SubmitOrder(ctx context.Context, s *order.Submit) (order.Submi // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (b *Bithumb) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { +func (b *Bithumb) ModifyOrder(ctx context.Context, action *order.Modify) (*order.Modify, error) { if err := action.Validate(); err != nil { - return order.Modify{}, err + return nil, err } o, err := b.ModifyTrade(ctx, @@ -523,20 +523,18 @@ func (b *Bithumb) ModifyOrder(ctx context.Context, action *order.Modify) (order. action.Side.Lower(), action.Amount, int64(action.Price)) - if err != nil { - return order.Modify{}, err + return nil, err } - return order.Modify{ + 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, + Price: float64(int64(action.Price)), + Amount: action.Amount, + Side: action.Side, }, nil } diff --git a/exchanges/bitmex/bitmex_wrapper.go b/exchanges/bitmex/bitmex_wrapper.go index 00efcfc6..f470258a 100644 --- a/exchanges/bitmex/bitmex_wrapper.go +++ b/exchanges/bitmex/bitmex_wrapper.go @@ -609,15 +609,15 @@ func (b *Bitmex) SubmitOrder(ctx context.Context, s *order.Submit) (order.Submit // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (b *Bitmex) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { +func (b *Bitmex) ModifyOrder(ctx context.Context, action *order.Modify) (*order.Modify, error) { if err := action.Validate(); err != nil { - return order.Modify{}, err + return nil, err } var params OrderAmendParams if math.Mod(action.Amount, 1) != 0 { - return order.Modify{}, errors.New("contract amount can not have decimals") + return nil, errors.New("contract amount can not have decimals") } params.OrderID = action.ID @@ -626,17 +626,16 @@ func (b *Bitmex) ModifyOrder(ctx context.Context, action *order.Modify) (order.M o, err := b.AmendOrder(ctx, ¶ms) if err != nil { - return order.Modify{}, err + return nil, err } - return order.Modify{ + return &order.Modify{ Exchange: action.Exchange, AssetType: action.AssetType, Pair: action.Pair, ID: o.OrderID, - - Price: action.Price, - Amount: float64(params.OrderQty), + Price: action.Price, + Amount: float64(params.OrderQty), }, nil } diff --git a/exchanges/bitstamp/bitstamp_wrapper.go b/exchanges/bitstamp/bitstamp_wrapper.go index 1cf3fbeb..638921a8 100644 --- a/exchanges/bitstamp/bitstamp_wrapper.go +++ b/exchanges/bitstamp/bitstamp_wrapper.go @@ -561,8 +561,8 @@ func (b *Bitstamp) SubmitOrder(ctx context.Context, s *order.Submit) (order.Subm // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (b *Bitstamp) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (b *Bitstamp) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/bittrex/bittrex_wrapper.go b/exchanges/bittrex/bittrex_wrapper.go index a0f4a0bb..0315d172 100644 --- a/exchanges/bittrex/bittrex_wrapper.go +++ b/exchanges/bittrex/bittrex_wrapper.go @@ -587,8 +587,8 @@ func (b *Bittrex) SubmitOrder(ctx context.Context, s *order.Submit) (order.Submi // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (b *Bittrex) ModifyOrder(_ context.Context, _ *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (b *Bittrex) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/btcmarkets/btcmarkets.go b/exchanges/btcmarkets/btcmarkets.go index 036b8ee9..7866e58e 100644 --- a/exchanges/btcmarkets/btcmarkets.go +++ b/exchanges/btcmarkets/btcmarkets.go @@ -21,6 +21,11 @@ import ( "github.com/thrasher-corp/gocryptotrader/exchanges/request" ) +var ( + errInvalidAmount = errors.New("cannot be less than or equal to zero") + errIDRequired = errors.New("id is required") +) + const ( btcMarketsAPIURL = "https://api.btcmarkets.net" btcMarketsAPIVersion = "/v3" @@ -464,8 +469,8 @@ func (b *BTCMarkets) CancelAllOpenOrdersByPairs(ctx context.Context, marketIDs [ } // FetchOrder finds order based on the provided id -func (b *BTCMarkets) FetchOrder(ctx context.Context, id string) (OrderData, error) { - var resp OrderData +func (b *BTCMarkets) FetchOrder(ctx context.Context, id string) (*OrderData, error) { + var resp *OrderData return resp, b.SendAuthenticatedRequest(ctx, http.MethodGet, btcMarketsOrders+"/"+id, nil, @@ -483,6 +488,36 @@ func (b *BTCMarkets) RemoveOrder(ctx context.Context, id string) (CancelOrderRes request.Auth) } +// ReplaceOrder cancels an order and then places a new order. +func (b *BTCMarkets) ReplaceOrder(ctx context.Context, id, clientOrderID string, price, amount float64) (*OrderData, error) { + if price <= 0 { + return nil, fmt.Errorf("price %w", errInvalidAmount) + } + + if amount <= 0 { + return nil, fmt.Errorf("amount %w", errInvalidAmount) + } + + if id == "" { + return nil, errIDRequired + } + + req := make(map[string]interface{}, 3) + req["price"] = strconv.FormatFloat(price, 'f', -1, 64) + req["amount"] = strconv.FormatFloat(amount, 'f', -1, 64) + if clientOrderID != "" { + req["clientOrderId"] = clientOrderID + } + + var resp *OrderData + return resp, b.SendAuthenticatedRequest(ctx, + http.MethodPut, + btcMarketsOrders+"/"+id, + req, + &resp, + request.Auth) +} + // ListWithdrawals lists the withdrawal history func (b *BTCMarkets) ListWithdrawals(ctx context.Context, before, after, limit int64) ([]TransferData, error) { if (before > 0) && (after >= 0) { diff --git a/exchanges/btcmarkets/btcmarkets_test.go b/exchanges/btcmarkets/btcmarkets_test.go index fc5e3571..a2c9506a 100644 --- a/exchanges/btcmarkets/btcmarkets_test.go +++ b/exchanges/btcmarkets/btcmarkets_test.go @@ -1041,6 +1041,60 @@ func TestGetTimeInForce(t *testing.T) { } } +func TestReplaceOrder(t *testing.T) { + t.Parallel() + _, err := b.ReplaceOrder(context.Background(), "", "bro", 0, 0) + if !errors.Is(err, errInvalidAmount) { + t.Fatalf("received: '%v' but expected: '%v'", err, errInvalidAmount) + } + + _, err = b.ReplaceOrder(context.Background(), "", "bro", 1, 0) + if !errors.Is(err, errInvalidAmount) { + t.Fatalf("received: '%v' but expected: '%v'", err, errInvalidAmount) + } + + _, err = b.ReplaceOrder(context.Background(), "", "bro", 1, 1) + if !errors.Is(err, errIDRequired) { + t.Fatalf("received: '%v' but expected: '%v'", err, errIDRequired) + } + + if !areTestAPIKeysSet() || !canManipulateRealOrders { + t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly") + } + + _, err = b.ReplaceOrder(context.Background(), "8207096301", "bruh", 100000, 0.001) + if !errors.Is(err, nil) { + t.Fatalf("received: '%v' but expected: '%v'", err, nil) + } +} + +func TestWrapperModifyOrder(t *testing.T) { + t.Parallel() + _, err := b.ModifyOrder(context.Background(), &order.Modify{}) + if !errors.Is(err, order.ErrPairIsEmpty) { + t.Fatalf("received: '%v' but expected: '%v'", err, order.ErrPairIsEmpty) + } + + if !areTestAPIKeysSet() || !canManipulateRealOrders { + t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly") + } + mo, err := b.ModifyOrder(context.Background(), &order.Modify{ + Pair: currency.NewPair(currency.BTC, currency.AUD), + AssetType: asset.Spot, + Price: 100000, + Amount: 0.001, + ID: "8207123461", + ClientOrderID: "bruh3", + }) + if !errors.Is(err, nil) { + t.Fatalf("received: '%v' but expected: '%v'", err, nil) + } + + if mo == nil { + t.Fatal("expected data return") + } +} + func TestUpdateOrderExecutionLimits(t *testing.T) { t.Parallel() err := b.UpdateOrderExecutionLimits(context.Background(), asset.Empty) diff --git a/exchanges/btcmarkets/btcmarkets_wrapper.go b/exchanges/btcmarkets/btcmarkets_wrapper.go index b6ebcf96..31a98900 100644 --- a/exchanges/btcmarkets/btcmarkets_wrapper.go +++ b/exchanges/btcmarkets/btcmarkets_wrapper.go @@ -90,6 +90,7 @@ func (b *BTCMarkets) SetDefaults() { TradeFee: true, FiatWithdrawalFee: true, CryptoWithdrawalFee: true, + ModifyOrder: true, }, WebsocketCapabilities: protocol.Features{ TickerFetching: true, @@ -579,8 +580,41 @@ func (b *BTCMarkets) SubmitOrder(ctx context.Context, s *order.Submit) (order.Su // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (b *BTCMarkets) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (b *BTCMarkets) ModifyOrder(ctx context.Context, action *order.Modify) (*order.Modify, error) { + if err := action.Validate(); err != nil { + return nil, err + } + resp, err := b.ReplaceOrder(ctx, action.ID, action.ClientOrderID, action.Price, action.Amount) + if err != nil { + return nil, err + } + pair, err := currency.NewPairFromString(resp.MarketID) + if err != nil { + return nil, err + } + side, err := order.StringToOrderSide(resp.Side) + if err != nil { + return nil, err + } + orderT, err := order.StringToOrderType(resp.Type) + if err != nil { + return nil, err + } + status, err := order.StringToOrderStatus(resp.Status) + if err != nil { + return nil, err + } + return &order.Modify{ + ID: resp.OrderID, + Pair: pair, + Side: side, + Type: orderT, + Date: resp.CreationTime, + Price: resp.Price, + Amount: resp.Amount, + RemainingAmount: resp.OpenAmount, + Status: status, + }, nil } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/btse/btse_wrapper.go b/exchanges/btse/btse_wrapper.go index a7101041..44896ab5 100644 --- a/exchanges/btse/btse_wrapper.go +++ b/exchanges/btse/btse_wrapper.go @@ -551,8 +551,8 @@ func (b *BTSE) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitRe // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (b *BTSE) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (b *BTSE) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/coinbasepro/coinbasepro_wrapper.go b/exchanges/coinbasepro/coinbasepro_wrapper.go index 4292fa1c..557bb89b 100644 --- a/exchanges/coinbasepro/coinbasepro_wrapper.go +++ b/exchanges/coinbasepro/coinbasepro_wrapper.go @@ -578,8 +578,8 @@ func (c *CoinbasePro) SubmitOrder(ctx context.Context, s *order.Submit) (order.S // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (c *CoinbasePro) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (c *CoinbasePro) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/coinut/coinut_wrapper.go b/exchanges/coinut/coinut_wrapper.go index 38bad2c7..87a51f4f 100644 --- a/exchanges/coinut/coinut_wrapper.go +++ b/exchanges/coinut/coinut_wrapper.go @@ -679,8 +679,8 @@ func (c *COINUT) SubmitOrder(ctx context.Context, o *order.Submit) (order.Submit // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (c *COINUT) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (c *COINUT) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/exmo/exmo_wrapper.go b/exchanges/exmo/exmo_wrapper.go index 05313733..44c4d43d 100644 --- a/exchanges/exmo/exmo_wrapper.go +++ b/exchanges/exmo/exmo_wrapper.go @@ -500,8 +500,8 @@ func (e *EXMO) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitRe // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (e *EXMO) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (e *EXMO) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/ftx/ftx_wrapper.go b/exchanges/ftx/ftx_wrapper.go index 2b1031cd..78ef1731 100644 --- a/exchanges/ftx/ftx_wrapper.go +++ b/exchanges/ftx/ftx_wrapper.go @@ -682,9 +682,9 @@ func (f *FTX) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitRes // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (f *FTX) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { +func (f *FTX) ModifyOrder(ctx context.Context, action *order.Modify) (*order.Modify, error) { if err := action.Validate(); err != nil { - return order.Modify{}, err + return nil, err } if action.TriggerPrice != 0 { @@ -696,14 +696,13 @@ func (f *FTX) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modi action.Price, 0) if err != nil { - return order.Modify{}, err + return nil, err } - return order.Modify{ - Exchange: action.Exchange, - AssetType: action.AssetType, - Pair: action.Pair, - ID: strconv.FormatInt(a.ID, 10), - + return &order.Modify{ + Exchange: action.Exchange, + AssetType: action.AssetType, + Pair: action.Pair, + ID: strconv.FormatInt(a.ID, 10), Price: action.Price, Amount: action.Amount, TriggerPrice: action.TriggerPrice, @@ -719,7 +718,7 @@ func (f *FTX) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modi action.Price, action.Amount) if err != nil { - return order.Modify{}, err + return nil, err } } else { o, err = f.ModifyPlacedOrder(ctx, @@ -728,17 +727,16 @@ func (f *FTX) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modi action.Price, action.Amount) if err != nil { - return order.Modify{}, err + return nil, err } } - return order.Modify{ + return &order.Modify{ Exchange: action.Exchange, AssetType: action.AssetType, Pair: action.Pair, ID: strconv.FormatInt(o.ID, 10), - - Price: action.Price, - Amount: action.Amount, + Price: action.Price, + Amount: action.Amount, }, err } diff --git a/exchanges/gateio/gateio_wrapper.go b/exchanges/gateio/gateio_wrapper.go index 1b2e6fcf..0cb5ce82 100644 --- a/exchanges/gateio/gateio_wrapper.go +++ b/exchanges/gateio/gateio_wrapper.go @@ -544,8 +544,8 @@ func (g *Gateio) SubmitOrder(ctx context.Context, s *order.Submit) (order.Submit // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (g *Gateio) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (g *Gateio) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/gemini/gemini_wrapper.go b/exchanges/gemini/gemini_wrapper.go index b92b5bf4..e76a87ca 100644 --- a/exchanges/gemini/gemini_wrapper.go +++ b/exchanges/gemini/gemini_wrapper.go @@ -573,8 +573,8 @@ func (g *Gemini) SubmitOrder(ctx context.Context, s *order.Submit) (order.Submit // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (g *Gemini) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (g *Gemini) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/hitbtc/hitbtc_wrapper.go b/exchanges/hitbtc/hitbtc_wrapper.go index d1aaa6e3..ffaae397 100644 --- a/exchanges/hitbtc/hitbtc_wrapper.go +++ b/exchanges/hitbtc/hitbtc_wrapper.go @@ -602,8 +602,8 @@ func (h *HitBTC) SubmitOrder(ctx context.Context, o *order.Submit) (order.Submit // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (h *HitBTC) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (h *HitBTC) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/huobi/huobi_wrapper.go b/exchanges/huobi/huobi_wrapper.go index 4b78cb33..7068cb9e 100644 --- a/exchanges/huobi/huobi_wrapper.go +++ b/exchanges/huobi/huobi_wrapper.go @@ -999,8 +999,8 @@ func (h *HUOBI) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitR // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (h *HUOBI) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (h *HUOBI) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/interfaces.go b/exchanges/interfaces.go index c8c23bb1..1c060ac7 100644 --- a/exchanges/interfaces.go +++ b/exchanges/interfaces.go @@ -52,17 +52,13 @@ type IBotExchange interface { FormatWithdrawPermissions() string SupportsWithdrawPermissions(permissions uint32) bool GetFundingHistory(ctx context.Context) ([]FundHistory, error) - SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitResponse, error) - ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) - CancelOrder(ctx context.Context, o *order.Cancel) error - CancelBatchOrders(ctx context.Context, o []order.Cancel) (order.CancelBatchResponse, error) - CancelAllOrders(ctx context.Context, orders *order.Cancel) (order.CancelAllResponse, error) - GetOrderInfo(ctx context.Context, orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) + + OrderManagement + GetDepositAddress(ctx context.Context, cryptocurrency currency.Code, accountID, chain string) (*deposit.Address, error) GetAvailableTransferChains(ctx context.Context, cryptocurrency currency.Code) ([]string, error) - GetOrderHistory(ctx context.Context, getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) GetWithdrawalsHistory(ctx context.Context, code currency.Code) ([]WithdrawalHistory, error) - GetActiveOrders(ctx context.Context, getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) + WithdrawCryptocurrencyFunds(ctx context.Context, withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) WithdrawFiatFunds(ctx context.Context, withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) WithdrawFiatFundsToInternationalBank(ctx context.Context, withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) @@ -101,6 +97,18 @@ type IBotExchange interface { AccountManagement } +// OrderManagement defines functionality for order management +type OrderManagement interface { + SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitResponse, error) + ModifyOrder(ctx context.Context, action *order.Modify) (*order.Modify, error) + CancelOrder(ctx context.Context, o *order.Cancel) error + CancelBatchOrders(ctx context.Context, o []order.Cancel) (order.CancelBatchResponse, error) + CancelAllOrders(ctx context.Context, orders *order.Cancel) (order.CancelAllResponse, error) + GetOrderInfo(ctx context.Context, orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) + GetActiveOrders(ctx context.Context, getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) + GetOrderHistory(ctx context.Context, getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) +} + // CurrencyStateManagement defines functionality for currency state management type CurrencyStateManagement interface { GetCurrencyStateSnapshot() ([]currencystate.Snapshot, error) diff --git a/exchanges/itbit/itbit_wrapper.go b/exchanges/itbit/itbit_wrapper.go index 4ce4196a..87de8ad3 100644 --- a/exchanges/itbit/itbit_wrapper.go +++ b/exchanges/itbit/itbit_wrapper.go @@ -431,8 +431,8 @@ func (i *ItBit) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitR // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (i *ItBit) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (i *ItBit) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/kraken/kraken_wrapper.go b/exchanges/kraken/kraken_wrapper.go index 46705ccb..4fdd9c04 100644 --- a/exchanges/kraken/kraken_wrapper.go +++ b/exchanges/kraken/kraken_wrapper.go @@ -786,8 +786,8 @@ func (k *Kraken) SubmitOrder(ctx context.Context, s *order.Submit) (order.Submit // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (k *Kraken) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (k *Kraken) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/lbank/lbank_wrapper.go b/exchanges/lbank/lbank_wrapper.go index 1b8893e0..a6ba9247 100644 --- a/exchanges/lbank/lbank_wrapper.go +++ b/exchanges/lbank/lbank_wrapper.go @@ -485,8 +485,8 @@ func (l *Lbank) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitR // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (l *Lbank) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (l *Lbank) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/localbitcoins/localbitcoins_wrapper.go b/exchanges/localbitcoins/localbitcoins_wrapper.go index 8f0f25eb..1853594f 100644 --- a/exchanges/localbitcoins/localbitcoins_wrapper.go +++ b/exchanges/localbitcoins/localbitcoins_wrapper.go @@ -445,8 +445,8 @@ func (l *LocalBitcoins) SubmitOrder(ctx context.Context, s *order.Submit) (order // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (l *LocalBitcoins) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (l *LocalBitcoins) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/okgroup/okgroup_wrapper.go b/exchanges/okgroup/okgroup_wrapper.go index 29cd0f58..6d16adb1 100644 --- a/exchanges/okgroup/okgroup_wrapper.go +++ b/exchanges/okgroup/okgroup_wrapper.go @@ -316,8 +316,8 @@ func (o *OKGroup) SubmitOrder(ctx context.Context, s *order.Submit) (order.Submi // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (o *OKGroup) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (o *OKGroup) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/order/order_test.go b/exchanges/order/order_test.go index 2dbadf9e..3b8710fe 100644 --- a/exchanges/order/order_test.go +++ b/exchanges/order/order_test.go @@ -812,6 +812,9 @@ var stringsToOrderStatus = []struct { {"cLosEd", Closed, nil}, {"cancellinG", Cancelling, nil}, {"woahMan", UnknownStatus, errUnrecognisedOrderStatus}, + {"PLAcED", New, nil}, + {"ACCePTED", New, nil}, + {"FAILeD", Rejected, nil}, } func TestStringToOrderStatus(t *testing.T) { diff --git a/exchanges/order/orders.go b/exchanges/order/orders.go index 26e355d6..ae0c3406 100644 --- a/exchanges/order/orders.go +++ b/exchanges/order/orders.go @@ -919,7 +919,7 @@ func StringToOrderStatus(status string) (Status, error) { switch status { case AnyStatus.String(): return AnyStatus, nil - case New.String(), "PLACED": + case New.String(), "PLACED", "ACCEPTED": return New, nil case Active.String(), "STATUS_ACTIVE": return Active, nil @@ -937,7 +937,7 @@ func StringToOrderStatus(status string) (Status, error) { return Cancelled, nil case PendingCancel.String(), "PENDING CANCEL", "PENDING CANCELLATION": return PendingCancel, nil - case Rejected.String(): + case Rejected.String(), "FAILED": return Rejected, nil case Expired.String(): return Expired, nil diff --git a/exchanges/poloniex/poloniex_wrapper.go b/exchanges/poloniex/poloniex_wrapper.go index 93481f21..a1ff81b6 100644 --- a/exchanges/poloniex/poloniex_wrapper.go +++ b/exchanges/poloniex/poloniex_wrapper.go @@ -567,14 +567,14 @@ func (p *Poloniex) SubmitOrder(ctx context.Context, s *order.Submit) (order.Subm // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (p *Poloniex) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { +func (p *Poloniex) ModifyOrder(ctx context.Context, action *order.Modify) (*order.Modify, error) { if err := action.Validate(); err != nil { - return order.Modify{}, err + return nil, err } oID, err := strconv.ParseInt(action.ID, 10, 64) if err != nil { - return order.Modify{}, err + return nil, err } resp, err := p.MoveOrder(ctx, @@ -584,15 +584,14 @@ func (p *Poloniex) ModifyOrder(ctx context.Context, action *order.Modify) (order action.PostOnly, action.ImmediateOrCancel) if err != nil { - return order.Modify{}, err + return nil, err } - return order.Modify{ - Exchange: action.Exchange, - AssetType: action.AssetType, - Pair: action.Pair, - ID: strconv.FormatInt(resp.OrderNumber, 10), - + return &order.Modify{ + Exchange: action.Exchange, + AssetType: action.AssetType, + Pair: action.Pair, + ID: strconv.FormatInt(resp.OrderNumber, 10), Price: action.Price, Amount: action.Amount, PostOnly: action.PostOnly, diff --git a/exchanges/sharedtestvalues/customex.go b/exchanges/sharedtestvalues/customex.go index 7ea2cb22..25286add 100644 --- a/exchanges/sharedtestvalues/customex.go +++ b/exchanges/sharedtestvalues/customex.go @@ -150,8 +150,8 @@ func (c *CustomEx) SubmitOrder(ctx context.Context, s *order.Submit) (order.Subm return order.SubmitResponse{}, nil } -func (c *CustomEx) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, nil +func (c *CustomEx) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, nil } func (c *CustomEx) CancelOrder(ctx context.Context, o *order.Cancel) error { diff --git a/exchanges/yobit/yobit_wrapper.go b/exchanges/yobit/yobit_wrapper.go index b54a1017..05105d0a 100644 --- a/exchanges/yobit/yobit_wrapper.go +++ b/exchanges/yobit/yobit_wrapper.go @@ -439,8 +439,8 @@ func (y *Yobit) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitR // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (y *Yobit) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (y *Yobit) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number diff --git a/exchanges/zb/zb_wrapper.go b/exchanges/zb/zb_wrapper.go index b9616218..6dbf7b85 100644 --- a/exchanges/zb/zb_wrapper.go +++ b/exchanges/zb/zb_wrapper.go @@ -528,8 +528,8 @@ func (z *ZB) SubmitOrder(ctx context.Context, o *order.Submit) (order.SubmitResp // ModifyOrder will allow of changing orderbook placement and limit to // market conversion -func (z *ZB) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) { - return order.Modify{}, common.ErrFunctionNotSupported +func (z *ZB) ModifyOrder(_ context.Context, _ *order.Modify) (*order.Modify, error) { + return nil, common.ErrFunctionNotSupported } // CancelOrder cancels an order by its corresponding ID number