class PriceMonitor(private val tapSequenceManager: TapSequenceManager) { private var…
- User
class PriceMonitor(private val tapSequenceManager: TapSequenceManager) { private var currentPrice: Double? = null private var isInBuyTrade = false
fun updatePrice(newPrice: Double) { Log.d("PriceMonitor", "New Price: $newPrice, Current Price: $currentPrice, In Buy Trade: $isInBuyTrade") if (currentPrice != null) { val priceDifference = newPrice - currentPrice!! if (priceDifference >= 1 && !isInBuyTrade) { // Enter buy trade ONLY if not already in one Log.d("PriceMonitor", "Entering Buy Trade") tapSequenceManager.performSequenceAction1() isInBuyTrade = true } else if (priceDifference <= -1 && isInBuyTrade) { // Exit buy trade (sell) ONLY if in a buy trade Log.d("PriceMonitor", "Exiting Buy Trade (Selling)") tapSequenceManager.performSequenceAction2() isInBuyTrade = false } // No else block here - we don't do anything if the price fluctuates within the buy trade currentPrice = newPrice // Update current price regardless of trade actions } else { currentPrice = newPrice } }} Want to make it more versatile , no codes only suggestion and ideas give ( what else architecture approach can i use eg event based, what else can be more , no codes
- Assistant