protocol/order: adds additional fields for trading requirements (#1552)

* Add in initial handling for quote/base currency deployment requirements

* include client order ID checking

* glorious: suggestions

* spell and fix

* linter/context/test

* rework tests and order side specific requirements

* linter

* mend panic at the disco

* mending more panics at the disco

* anudda fix brudda

* glorious: NITTTTTT BOOOOOMB

* leftover things and stuff

* whoops

* tie in gateio

* glorious: nit fixes life and everything.

* thrasher: nits

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
Ryan O'Hara-Reid
2024-07-03 16:07:23 +10:00
committed by GitHub
parent b7a2f617d9
commit 48349bc3bb
35 changed files with 210 additions and 77 deletions

View File

@@ -55,6 +55,10 @@ func (g *Gateio) SetDefaults() {
}
g.Features = exchange.Features{
TradingRequirements: protocol.TradingRequirements{
SpotMarketOrderAmountPurchaseQuotationOnly: true,
SpotMarketOrderAmountSellBaseOnly: true,
},
Supports: exchange.FeaturesSupported{
REST: true,
Websocket: true,
@@ -984,7 +988,7 @@ func (g *Gateio) GetHistoricTrades(_ context.Context, _ currency.Pair, _ asset.I
// SubmitOrder submits a new order
// TODO: support multiple order types (IOC)
func (g *Gateio) SubmitOrder(ctx context.Context, s *order.Submit) (*order.SubmitResponse, error) {
err := s.Validate()
err := s.Validate(g.GetTradingRequirements())
if err != nil {
return nil, err
}
@@ -1008,11 +1012,20 @@ func (g *Gateio) SubmitOrder(ctx context.Context, s *order.Submit) (*order.Submi
if err != nil {
return nil, err
}
// When doing spot market orders when purchasing base currency, the
// quote currency amount is used. When selling the base currency the
// base currency amount is used.
tradingAmount := s.Amount
if tradingAmount == 0 && s.Type == order.Market {
tradingAmount = s.QuoteAmount
}
sOrder, err := g.PlaceSpotOrder(ctx, &CreateOrderRequestData{
Side: s.Side.Lower(),
Type: s.Type.Lower(),
Account: g.assetTypeToString(s.AssetType),
Amount: types.Number(s.Amount),
Amount: types.Number(tradingAmount),
Price: types.Number(s.Price),
CurrencyPair: s.Pair,
Text: s.ClientOrderID,