2
0
Просмотр исходного кода

RiskManager

- GetOrderSize: remove returning candle's open price
Alexey Kim 1 месяц назад
Родитель
Сommit
5fd3e0cf67
1 измененных файлов с 8 добавлено и 3 удалено
  1. 8 3
      util/order.go

+ 8 - 3
util/order.go

@@ -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
 	}