| 
					
				 | 
			
			
				@@ -9,24 +9,27 @@ import ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 func CreateOrder( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	m sentio.Market, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	s sentio.Strategy, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	t sentio.Side, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	stamp *sentio.Probability_Stamp, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	action sentio.Action, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	quotes map[string]sentio.Quote, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	rm sentio.RiskManager, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 ) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	var ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		symbol    string 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		account   sentio.MarketAccount 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		threshold float32 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		size      uint 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		bid       float64 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		tp        float64 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		sl        float64 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		ok        bool 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		err       error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		symbol  string 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		account sentio.MarketAccount 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		size    uint 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		side    sentio.Side 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		bid     float64 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		tp      float64 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		sl      float64 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		ok      bool 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		err     error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	if symbol, ok = s.PositionSymbols()[t]; !ok { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if side = sentio.ActionToSide(action); sentio.BASE == side { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return errors.New("`CreateOrder`: do nothing while `sentio.BASE`") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if symbol, ok = s.PositionSymbols()[side]; !ok { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return errors.New("`CreateOrder`: unknown Side for the current strategy") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -38,11 +41,6 @@ func CreateOrder( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	tp = sentio.ToFixed(rm.TakeProfit(symbol, bid), 2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	sl = sentio.ToFixed(rm.StopLoss(symbol, bid), 2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// define threshold 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	if threshold, ok = s.PositionProbabilities()[t]; !ok { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		return nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// Prevent orders those have too small expected profit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if tp < bid+0.02 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return sentio.ErrLowTakeProfit 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -62,19 +60,13 @@ func CreateOrder( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return sentio.ErrTooSmallOrder 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	if sentio.LONG == t && stamp.Value > threshold || 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		sentio.SHORT == t && stamp.Value < threshold { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		// create a new order 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		if size = uint(math.Floor(account.GetCash() * .9 / bid)); size < 1 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			return sentio.ErrTooSmallOrder 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		_, err = m.CreateOrder(symbol, size, rm) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		return err 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// create a new order 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if size = uint(math.Floor(account.GetCash() * .9 / bid)); size < 1 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return sentio.ErrTooSmallOrder 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	return nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	_, err = m.CreateOrder(symbol, size, rm) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	return err 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 func CloseAllOrders(m sentio.Market, s sentio.Strategy) error { 
			 |