mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 17:13:51 +00:00
25 lines
797 B
Go
25 lines
797 B
Go
|
package bollmaker
|
||
|
|
||
|
import "github.com/c9s/bbgo/pkg/fixedpoint"
|
||
|
|
||
|
// QuantityOrAmount is a setting structure used for quantity/amount settings
|
||
|
type QuantityOrAmount struct {
|
||
|
// Quantity is the base order quantity for your buy/sell order.
|
||
|
// when quantity is set, the amount option will be not used.
|
||
|
Quantity fixedpoint.Value `json:"quantity"`
|
||
|
|
||
|
// Amount is the order quote amount for your buy/sell order.
|
||
|
Amount fixedpoint.Value `json:"amount"`
|
||
|
}
|
||
|
|
||
|
// CalculateQuantity calculates the equivalent quantity of the given price when amount is set
|
||
|
// it returns the quantity if the quantity is set
|
||
|
func (qa *QuantityOrAmount) CalculateQuantity(currentPrice fixedpoint.Value) fixedpoint.Value {
|
||
|
if qa.Amount > 0 {
|
||
|
quantity := qa.Amount.Div(currentPrice)
|
||
|
return quantity
|
||
|
}
|
||
|
|
||
|
return qa.Quantity
|
||
|
}
|