From 55c88ac44d26c969fa558c5877f1a365190b6d4c Mon Sep 17 00:00:00 2001 From: kosyloa Date: Thu, 30 May 2024 12:39:43 +0200 Subject: [PATCH] update dep add index to candlemodel add insert/remove for nonsnapshot update --- .../DXFeedCandleChartMac/CandleChart.swift | 7 +++-- .../CandleChartModel.swift | 26 +++++++++++++------ build.gradle | 2 +- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Samples/DXFeedCandleChartMac/CandleChart.swift b/Samples/DXFeedCandleChartMac/CandleChart.swift index bcd57ecca..8239b66f2 100644 --- a/Samples/DXFeedCandleChartMac/CandleChart.swift +++ b/Samples/DXFeedCandleChartMac/CandleChart.swift @@ -32,8 +32,9 @@ struct CandleModel: Identifiable { let isPoint: Bool let stringtimeStamp: String + let index: Long - init(currency: String, timestamp: Date, open: Decimal, close: Decimal, high: Decimal, low: Decimal) { + init(currency: String, timestamp: Date, open: Decimal, close: Decimal, high: Decimal, low: Decimal, index: Long) { self.currency = currency self.timestamp = timestamp self.open = open @@ -42,6 +43,7 @@ struct CandleModel: Identifiable { self.high = high self.low = low self.stringtimeStamp = "\(timestamp.timeIntervalSince1970)" + self.index = index } init(candle: Candle, currency: String) { @@ -50,7 +52,8 @@ struct CandleModel: Identifiable { open: Decimal(candle.open), close: Decimal(candle.close), high: Decimal(candle.high), - low: Decimal(candle.low)) + low: Decimal(candle.low), + index: candle.index) } var isClosingHigher: Bool { diff --git a/Samples/DXFeedCandleChartMac/CandleChartModel.swift b/Samples/DXFeedCandleChartMac/CandleChartModel.swift index ac610234a..b5de9d804 100644 --- a/Samples/DXFeedCandleChartMac/CandleChartModel.swift +++ b/Samples/DXFeedCandleChartMac/CandleChartModel.swift @@ -183,16 +183,26 @@ extension CandleChartModel: SnapshotDelegate { self.xScrollPosition = temp[pointsOnScreen - 1].stringtimeStamp } else { result.forEach { candle in - self.maxValue = max(self.maxValue, candle.max()) - self.minValue = min(self.minValue, candle.min()) let newPrice = CandleModel(candle: candle, currency: self.currency) - if let index = self.candles.firstIndex(where: { price in - price.timestamp == newPrice.timestamp - }) { - self.candles.safeReplace(newPrice, at: index) + if candle.isRemove() { + // remove + self.candles.removeAll { price in + price.index == newPrice.index + } + } else { + self.maxValue = max(self.maxValue, candle.max()) + self.minValue = min(self.minValue, candle.min()) + + if let index = self.candles.firstIndex(where: { price in + price.timestamp == newPrice.timestamp + }) { + // update + self.candles.safeReplace(newPrice, at: index) + } else { + // insert + self.candles.insert(newPrice, at: 0) + } } - //add remove - //add insert } } } diff --git a/build.gradle b/build.gradle index d200c5941..a4931e02c 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ repositories { } } -def native_version = '1.1.12' +def native_version = '1.1.16' def name = 'graal-native-sdk' dependencies { implementation(group: 'com.dxfeed', name: "${name}", version: "${native_version}", classifier: 'aarch64-osx', ext: 'zip')