فهرست منبع

RiskManament

- add Renovacion
Alexey Kim 2 ماه پیش
والد
کامیت
8d9f92be84
3فایلهای تغییر یافته به همراه15 افزوده شده و 8 حذف شده
  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"
 
 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
 	StopLoss(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
 	}
 
-	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