|
@@ -12,6 +12,7 @@ func CreateOrder(
|
|
|
action sentio.Action,
|
|
|
quotes map[string]sentio.Quote,
|
|
|
rm sentio.RiskManager,
|
|
|
+ budget float64,
|
|
|
) error {
|
|
|
var (
|
|
|
symbol string
|
|
@@ -57,16 +58,20 @@ func CreateOrder(
|
|
|
}
|
|
|
|
|
|
var (
|
|
|
- limit float64
|
|
|
ratio float64
|
|
|
)
|
|
|
|
|
|
- if limit, ratio = rm.GetOrderSize(symbol, bid); ratio <= 0 {
|
|
|
+ if ratio = rm.GetOrderSize(symbol, bid); ratio <= 0 {
|
|
|
return sentio.ErrRiskManagementPrevent
|
|
|
}
|
|
|
|
|
|
+ cash := account.GetCash()
|
|
|
+ if budget > 0 && cash > budget {
|
|
|
+ cash = budget
|
|
|
+ }
|
|
|
+
|
|
|
// create a new order
|
|
|
- if size = uint(math.Floor(account.GetCash() * ratio / limit)); size < 1 {
|
|
|
+ if size = uint(math.Floor(cash * ratio / bid)); size < 1 {
|
|
|
return sentio.ErrTooSmallOrder
|
|
|
}
|
|
|
|