Skip to content

Commit

Permalink
update dep
Browse files Browse the repository at this point in the history
add index to candlemodel
add insert/remove for nonsnapshot update
  • Loading branch information
kosyloa committed May 30, 2024
1 parent ae69423 commit 55c88ac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
7 changes: 5 additions & 2 deletions Samples/DXFeedCandleChartMac/CandleChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down
26 changes: 18 additions & 8 deletions Samples/DXFeedCandleChartMac/CandleChartModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 55c88ac

Please sign in to comment.