diff --git a/DXFeedFramework.xcodeproj/project.pbxproj b/DXFeedFramework.xcodeproj/project.pbxproj index f0565aa9f..8a8a2b243 100644 --- a/DXFeedFramework.xcodeproj/project.pbxproj +++ b/DXFeedFramework.xcodeproj/project.pbxproj @@ -109,6 +109,7 @@ 642DC9432AAA299800974F5C /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 646979712A3B5AF60003A9BA /* Colors.xcassets */; }; 642DC9442AAA29EA00974F5C /* IpfCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 642DC9402AAA290300974F5C /* IpfCell.swift */; }; 6433B12D2BCE7ADD004EFED7 /* DXFeed+LastEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6433B12C2BCE7ADD004EFED7 /* DXFeed+LastEvents.swift */; }; + 6433B1322BCFC01F004EFED7 /* DXLastEventsSubscribedTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6433B1312BCFC01F004EFED7 /* DXLastEventsSubscribedTest.swift */; }; 64437A8F2A9DEE6F005929B2 /* InstrumentProfile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64437A8E2A9DEE6F005929B2 /* InstrumentProfile.swift */; }; 64437A922A9DF1DE005929B2 /* NativeInstrumentProfileReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64437A912A9DF1DE005929B2 /* NativeInstrumentProfileReader.swift */; }; 6447A5DB2A8E559000739CCF /* ILastingEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6447A5DA2A8E559000739CCF /* ILastingEvent.swift */; }; @@ -665,6 +666,7 @@ 642DC9402AAA290300974F5C /* IpfCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IpfCell.swift; sourceTree = ""; }; 6433B12C2BCE7ADD004EFED7 /* DXFeed+LastEvents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DXFeed+LastEvents.swift"; sourceTree = ""; }; 6433B1302BCE87D4004EFED7 /* RequestProfile.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = RequestProfile.playground; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + 6433B1312BCFC01F004EFED7 /* DXLastEventsSubscribedTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXLastEventsSubscribedTest.swift; sourceTree = ""; }; 6435EE3C2B1F1E9200E8496C /* PrintQuoteEvents.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = PrintQuoteEvents.playground; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 64437A8E2A9DEE6F005929B2 /* InstrumentProfile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstrumentProfile.swift; sourceTree = ""; }; 64437A912A9DF1DE005929B2 /* NativeInstrumentProfileReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeInstrumentProfileReader.swift; sourceTree = ""; }; @@ -1641,6 +1643,7 @@ 641C64B32B347C430023CFAD /* DXObservableSubscriptionTest.swift */, 6423E4682B457000006B208D /* DXTimeSeriesSubscriptionTest.swift */, 646064E92B4D8973009201E2 /* DXLastEventTest.swift */, + 6433B1312BCFC01F004EFED7 /* DXLastEventsSubscribedTest.swift */, 64EAA1A12B7A38F8005087BC /* DXPromiseTest.swift */, 64DF09342BC924AB009F1486 /* DXAsyncLastTest.swift */, 64EAA1A52B838ED3005087BC /* DXSnapshotProcessorTest.swift */, @@ -2176,6 +2179,7 @@ /* Begin PBXShellScriptBuildPhase section */ 64656F632A1BB22E006A0B19 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -2591,6 +2595,7 @@ 649813C42ADD5CB2003CE3B3 /* TestEndpoointStateListener.swift in Sources */, 641C64B42B347C430023CFAD /* DXObservableSubscriptionTest.swift in Sources */, 64ACBCEC2A29FE2300032C53 /* XCTestCase+Utils.swift in Sources */, + 6433B1322BCFC01F004EFED7 /* DXLastEventsSubscribedTest.swift in Sources */, 6423E4692B457000006B208D /* DXTimeSeriesSubscriptionTest.swift in Sources */, 64ECD67F2A9CF4CB00B36935 /* IPFTests.swift in Sources */, 64ACBCD52A2789EF00032C53 /* TestListener.swift in Sources */, diff --git a/DXFeedFramework/Api/Osub/TimeSeriesSubscriptionSymbol.swift b/DXFeedFramework/Api/Osub/TimeSeriesSubscriptionSymbol.swift index fb66c667e..904df0b0d 100644 --- a/DXFeedFramework/Api/Osub/TimeSeriesSubscriptionSymbol.swift +++ b/DXFeedFramework/Api/Osub/TimeSeriesSubscriptionSymbol.swift @@ -52,7 +52,9 @@ public class TimeSeriesSubscriptionSymbol: GenericIndexedEventSubscriptionSymbol /// Custom symbol has to return string representation. public override var stringValue: String { - return "\(symbol.description){fromTime=\((try? DXTimeFormat.defaultTimeFormat?.withMillis?.format(value: fromTime)) ?? "")}" + return """ +\(symbol.description){fromTime=\((try? DXTimeFormat.defaultTimeFormat?.withMillis?.format(value: fromTime)) ?? "")} +""" } } diff --git a/DXFeedFramework/Native/Feed/NativeFeed.swift b/DXFeedFramework/Native/Feed/NativeFeed.swift index 82dac324b..3e177c326 100644 --- a/DXFeedFramework/Native/Feed/NativeFeed.swift +++ b/DXFeedFramework/Native/Feed/NativeFeed.swift @@ -101,96 +101,6 @@ class NativeFeed { return event?.lastingEvent } - func getLastEventIfSubscribed(type: IEventType.Type, symbol: Symbol) throws -> ILastingEvent? { - let thread = currentThread() - let converted = SymbolMapper.newNative(symbol) - defer { - if let converted = converted { - SymbolMapper.clearNative(symbol: converted) - } - } - do { - let result = try ErrorCheck.nativeCall(thread, - dxfg_DXFeed_getLastEventIfSubscribed(thread, - feed, - type.type.nativeCode(), - converted)) - return try mapper.fromNative(native: result)?.lastingEvent - } catch GraalException.nullException { - return nil - } - } - - func getIndexedEventsIfSubscribed(type: IEventType.Type, - symbol: Symbol, - source: IndexedEventSource) throws -> [IIndexedEvent]? { - let thread = currentThread() - let converted = SymbolMapper.newNative(symbol) - defer { - if let converted = converted { - SymbolMapper.clearNative(symbol: converted) - } - } - do { - let result = try ErrorCheck.nativeCall(thread, - dxfg_DXFeed_getIndexedEventsIfSubscribed(thread, - feed, - type.type.nativeCode(), - converted, - source.name.toCStringRef())) - if result.pointee.size == 0 { - return nil - } else { - let events: [IIndexedEvent] = - (0.. [ITimeSeriesEvent]? { - let thread = currentThread() - let converted = SymbolMapper.newNative(symbol) - defer { - if let converted = converted { - SymbolMapper.clearNative(symbol: converted) - } - } - do { - let result = try ErrorCheck.nativeCall(thread, - dxfg_DXFeed_getTimeSeriesIfSubscribed(thread, - feed, - type.type.nativeCode(), - converted, - fromTime, - toTime)) - if result.pointee.size == 0 { - return nil - } else { - let events: [ITimeSeriesEvent] = - (0.. [ILastingEvent] { let listPointer = UnsafeMutablePointer.allocate(capacity: 1) listPointer.pointee.size = Int32(types.count) @@ -316,7 +226,9 @@ class NativeFeed { toTime)) return NativePromise(promise: &native.pointee.base) } +} +extension NativeFeed { func attach(subscription: NativeSubscription) throws { let thread = currentThread() try ErrorCheck.nativeCall(thread, @@ -333,3 +245,96 @@ class NativeFeed { subscription.subscription)) } } + +extension NativeFeed { + func getLastEventIfSubscribed(type: IEventType.Type, symbol: Symbol) throws -> ILastingEvent? { + let thread = currentThread() + let converted = SymbolMapper.newNative(symbol) + defer { + if let converted = converted { + SymbolMapper.clearNative(symbol: converted) + } + } + do { + let result = try ErrorCheck.nativeCall(thread, + dxfg_DXFeed_getLastEventIfSubscribed(thread, + feed, + type.type.nativeCode(), + converted)) + return try mapper.fromNative(native: result)?.lastingEvent + } catch GraalException.nullException { + return nil + } + } + + func getIndexedEventsIfSubscribed(type: IEventType.Type, + symbol: Symbol, + source: IndexedEventSource) throws -> [IIndexedEvent]? { + let thread = currentThread() + let converted = SymbolMapper.newNative(symbol) + defer { + if let converted = converted { + SymbolMapper.clearNative(symbol: converted) + } + } + do { + let result = try ErrorCheck.nativeCall(thread, + dxfg_DXFeed_getIndexedEventsIfSubscribed(thread, + feed, + type.type.nativeCode(), + converted, + source.name.toCStringRef())) + if result.pointee.size == 0 { + return nil + } else { + let events: [IIndexedEvent] = + (0.. [ITimeSeriesEvent]? { + let thread = currentThread() + let converted = SymbolMapper.newNative(symbol) + defer { + if let converted = converted { + SymbolMapper.clearNative(symbol: converted) + } + } + do { + let result = try ErrorCheck.nativeCall(thread, + dxfg_DXFeed_getTimeSeriesIfSubscribed(thread, + feed, + type.type.nativeCode(), + converted, + fromTime, + toTime)) + if result.pointee.size == 0 { + return nil + } else { + let events: [ITimeSeriesEvent] = + (0.. 0 { events.forEach { event in XCTAssertEqual(event.type, .otcMarketsOrder) - var event = event.otcMarketsOrder + let event = event.otcMarketsOrder if event.eventSymbol == SYMBOL1 { XCTAssertEqual(event.marketMaker, "MM1") XCTAssertEqual(event.price, 10) diff --git a/DXFeedFrameworkTests/DXPromiseTest.swift b/DXFeedFrameworkTests/DXPromiseTest.swift index 5b0703848..1801c0db9 100644 --- a/DXFeedFrameworkTests/DXPromiseTest.swift +++ b/DXFeedFrameworkTests/DXPromiseTest.swift @@ -186,7 +186,8 @@ final class DXPromiseTest: XCTestCase { func testGetMultipleResultsWithException() { do { - let promises = try feed?.getLastEventsPromises(type: Quote.self, symbols: ["ETH/USD:GDAX_TEST", "AAPL_TEST"]) + let promises = try feed?.getLastEventsPromises(type: Quote.self, + symbols: ["ETH/USD:GDAX_TEST", "AAPL_TEST"]) if promises?.isEmpty != false { XCTAssert(false, "Promises is empty") } diff --git a/Samples/QuoteTableApp/QuoteTableViewController.swift b/Samples/QuoteTableApp/QuoteTableViewController.swift index a3825f359..3881b4fd3 100644 --- a/Samples/QuoteTableApp/QuoteTableViewController.swift +++ b/Samples/QuoteTableApp/QuoteTableViewController.swift @@ -29,7 +29,9 @@ class QuoteTableViewController: UIViewController { quoteTableView.separatorStyle = .none - NotificationCenter.default.addObserver(forName: .selectedSymbolsChanged, object: nil, queue: nil) { [weak self] (_) in + NotificationCenter.default.addObserver(forName: .selectedSymbolsChanged, + object: nil, + queue: nil) { [weak self] (_) in guard let strongSelf = self else { return }