| 
					
				 | 
			
			
				@@ -8,6 +8,10 @@ import ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const TradingRange = .02 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+func ToPtr[T any](x T) *T { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	return &x 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 func NewOrder( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	m sentio.Market, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	s sentio.Strategy, 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -32,18 +36,18 @@ func NewOrder( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	bid = sentio.ToFixed(quotes[opts.Symbol].BidPrice, 2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	opts.Action = sentio.Action_BUY 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	opts.TakeProfit = sentio.ToFixed(rm.TakeProfit(opts.Symbol, bid), 2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	opts.StopLoss = sentio.ToFixed(rm.StopLoss(opts.Symbol, bid), 2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	opts.TakeProfit = ToPtr(sentio.ToFixed(rm.TakeProfit(opts.Symbol, bid), 2)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	opts.StopLoss = ToPtr(sentio.ToFixed(rm.StopLoss(opts.Symbol, bid), 2)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// Prevent orders those have too small expected profit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	if opts.TakeProfit < bid+TradingRange { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if *opts.TakeProfit < bid+TradingRange { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		err = sentio.ErrLowTakeProfit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// Prevent cases when order will be closed ASAP they were opened. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// Also, Alpaca requires at least 0.01 gap against base_price 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	if opts.StopLoss > bid-TradingRange { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if *opts.StopLoss > bid-TradingRange { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		err = sentio.ErrHighStoploss 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 |