types: add Out() and Int() methods on SubmitOrder type

This commit is contained in:
c9s 2022-08-05 09:44:42 +08:00
parent 938e612c42
commit babb0abc95
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -116,13 +116,13 @@ type SubmitOrder struct {
Side SideType `json:"side" db:"side"`
Type OrderType `json:"orderType" db:"order_type"`
Quantity fixedpoint.Value `json:"quantity" db:"quantity"`
Price fixedpoint.Value `json:"price" db:"price"`
Quantity fixedpoint.Value `json:"quantity" db:"quantity"`
Price fixedpoint.Value `json:"price" db:"price"`
// AveragePrice is only used in back-test currently
AveragePrice fixedpoint.Value `json:"averagePrice"`
StopPrice fixedpoint.Value `json:"stopPrice,omitempty" db:"stop_price"`
StopPrice fixedpoint.Value `json:"stopPrice,omitempty" db:"stop_price"`
Market Market `json:"-" db:"-"`
@ -140,6 +140,32 @@ type SubmitOrder struct {
Tag string `json:"tag" db:"-"`
}
func (o *SubmitOrder) In() (fixedpoint.Value, string) {
switch o.Side {
case SideTypeBuy:
return o.Quantity.Mul(o.Price), o.Market.QuoteCurrency
case SideTypeSell:
return o.Quantity, o.Market.BaseCurrency
}
return fixedpoint.Zero, ""
}
func (o *SubmitOrder) Out() (fixedpoint.Value, string) {
switch o.Side {
case SideTypeBuy:
return o.Quantity, o.Market.BaseCurrency
case SideTypeSell:
return o.Quantity.Mul(o.Price), o.Market.QuoteCurrency
}
return fixedpoint.Zero, ""
}
func (o *SubmitOrder) String() string {
switch o.Type {
case OrderTypeMarket: