-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add histogram chart and ETF fetchers for chart.
- Loading branch information
Showing
16 changed files
with
237 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...ableWallet/UnstoppableWallet/Modules/Market/MarketGlobalMetric/Etf/MarketEtfFetcher.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Chart | ||
import Combine | ||
import Foundation | ||
import MarketKit | ||
|
||
class MarketEtfFetcher { | ||
private let marketKit: MarketKit.Kit | ||
private let currencyManager: CurrencyManager | ||
|
||
private let needUpdateSubject = PassthroughSubject<Void, Never>() | ||
|
||
init(marketKit: MarketKit.Kit, currencyManager: CurrencyManager) { | ||
self.marketKit = marketKit | ||
self.currencyManager = currencyManager | ||
} | ||
} | ||
|
||
extension MarketEtfFetcher: IMetricChartFetcher { | ||
var valueType: MetricChartModule.ValueType { | ||
.compactCurrencyValue(currencyManager.baseCurrency) | ||
} | ||
|
||
var needUpdatePublisher: AnyPublisher<Void, Never> { | ||
Empty().eraseToAnyPublisher() | ||
} | ||
|
||
var intervals: [HsPeriodType] { [] } | ||
|
||
func fetch(interval _: HsPeriodType) async throws -> MetricChartModule.ItemData { | ||
let points = try await marketKit.etfPoints(currencyCode: currencyManager.baseCurrency.code) | ||
|
||
var items = [MetricChartModule.Item]() | ||
var totalInflow = [Decimal]() | ||
var totalAssets = [Decimal]() | ||
for point in points.sorted(by: { p1, p2 in p1.date < p2.date }) { | ||
items.append(MetricChartModule.Item(value: point.dailyInflow, timestamp: point.date.timeIntervalSince1970)) | ||
totalInflow.append(point.totalInflow) | ||
totalAssets.append(point.totalAssets) | ||
} | ||
return MetricChartModule.ItemData( | ||
items: items, | ||
indicators: [ | ||
MarketGlobalModule.totalInflow: totalInflow, | ||
MarketGlobalModule.totalAssets: totalAssets, | ||
], | ||
type: .etf | ||
) | ||
} | ||
} |
Oops, something went wrong.