Răsfoiți Sursa

RiskManament

- add Renovacion
Alexey Kim 6 luni în urmă
părinte
comite
8d9f92be84
3 a modificat fișierele cu 15 adăugiri și 8 ștergeri
  1. 6 5
      errors.go
  2. 2 0
      risk_manager.go
  3. 7 3
      util/order.go

+ 6 - 5
errors.go

@@ -3,9 +3,10 @@ package sentio
 import "errors"
 import "errors"
 
 
 var (
 var (
-	ErrMarketClosed  = errors.New("market is closed")
-	ErrTooSmallOrder = errors.New("too small order size")
-	ErrHighStoploss  = errors.New("base price is lower than stoploss")
-	ErrLowTakeProfit = errors.New("base price is too close to take profit")
-	ErrLowVolatility = errors.New("too low volatility")
+	ErrMarketClosed          = errors.New("market is closed")
+	ErrTooSmallOrder         = errors.New("too small order size")
+	ErrHighStoploss          = errors.New("base price is lower than stoploss")
+	ErrLowTakeProfit         = errors.New("base price is too close to take profit")
+	ErrLowVolatility         = errors.New("too low volatility")
+	ErrRiskManagementPrevent = errors.New("RiskManagement: prevent trading")
 )
 )

+ 2 - 0
risk_manager.go

@@ -4,4 +4,6 @@ type RiskManager interface {
 	EnsureVolatility(symbol string) bool
 	EnsureVolatility(symbol string) bool
 	StopLoss(symbol string, current float64, safe bool) float64
 	StopLoss(symbol string, current float64, safe bool) float64
 	TakeProfit(symbol string, current float64, safe bool) float64
 	TakeProfit(symbol string, current float64, safe bool) float64
+
+	Renovacion(market Market) (float64, error)
 }
 }

+ 7 - 3
util/order.go

@@ -60,9 +60,13 @@ func CreateOrder(
 		return sentio.ErrTooSmallOrder
 		return sentio.ErrTooSmallOrder
 	}
 	}
 
 
-	ratio := .9
-	if action == sentio.Action_BUY || action == sentio.Action_SELL {
-		ratio = .4
+	var ratio float64
+	if ratio, err = rm.Renovacion(m); err != nil {
+		return err
+	}
+
+	if ratio <= 0 {
+		return sentio.ErrRiskManagementPrevent
 	}
 	}
 
 
 	// create a new order
 	// create a new order