diff --git a/DXFeedFramework/Events/Market/Candles/CandlePriceLevel.swift b/DXFeedFramework/Events/Market/Candles/CandlePriceLevel.swift index 5d5f86e73..032508f8c 100644 --- a/DXFeedFramework/Events/Market/Candles/CandlePriceLevel.swift +++ b/DXFeedFramework/Events/Market/Candles/CandlePriceLevel.swift @@ -114,7 +114,7 @@ public class CandlePriceLevel { public func toString() -> String { return stringDescription } - + /// Returns full string representation of this candle price level attribute. /// /// It is contains attribute key and its value. diff --git a/DXFeedFramework/Utils/StringUtil.swift b/DXFeedFramework/Utils/StringUtil.swift index 7249b066c..d54e198fa 100644 --- a/DXFeedFramework/Utils/StringUtil.swift +++ b/DXFeedFramework/Utils/StringUtil.swift @@ -27,6 +27,6 @@ class StringUtil { static func random(length: Int) -> String { let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" - return String((0.. 0) + case .failure(let value): + XCTAssert(false, "\(value)") + } + } + + func testIndexedEventTask() async throws { + throw XCTSkip(""" + Skiped +""") + let date = Calendar.current.date(byAdding: .month, value: -1, to: Date())! + guard let task = feed?.getIndexedEvents(type: Series.self, + symbol: "ETH/USD:GDAX", + source: OrderSource.agregateAsk!) else { + XCTAssert(false, "Async task is nil") + return + } + let result = await task.result + switch result { + case .success(let value): + XCTAssert((value?.count ?? 0) > 0) + case .failure(let value): + XCTAssert(false, "\(value)") + } + } +} diff --git a/DXFeedFrameworkTests/DXPromiseTest.swift b/DXFeedFrameworkTests/DXPromiseTest.swift index e08a95ea9..6790c417c 100644 --- a/DXFeedFrameworkTests/DXPromiseTest.swift +++ b/DXFeedFrameworkTests/DXPromiseTest.swift @@ -10,17 +10,21 @@ import XCTest // swiftlint:disable type_body_length final class DXPromiseTest: XCTestCase { + var endpoint: DXEndpoint! + var feed: DXFeed! override func setUpWithError() throws { + endpoint = try DXEndpoint.create().connect("demo.dxfeed.com:7300") + feed = endpoint.getFeed() // Put setup code here. This method is called before the invocation of each test method in the class. } override func tearDownWithError() throws { - // Put teardown code here. This method is called after the invocation of each test method in the class. + try? endpoint.closeAndAwaitTermination() } private func eventPromise(type: IEventType.Type, symbol: String, feed: DXFeed) throws -> Promise { - let promise = try feed.getLastEventPromise(type: type, symbol: symbol) + let promise = try feed.getLastEventPromise(type: type, symbol: symbol) return promise } @@ -38,11 +42,7 @@ final class DXPromiseTest: XCTestCase { func getAsyncResult(timeOut: Int32?, withException: Bool = true) { do { - let endpoint = try DXEndpoint.create().connect("demo.dxfeed.com:7300") - defer { - try? endpoint.closeAndAwaitTermination() - } - let feed = endpoint.getFeed() + let promise = try eventPromise(type: Trade.self, symbol: "ETH/USD:GDAX", feed: feed!) @@ -73,11 +73,7 @@ final class DXPromiseTest: XCTestCase { func testGetAsyncResult() { do { - let endpoint = try DXEndpoint.create().connect("demo.dxfeed.com:7300") - defer { - try? endpoint.closeAndAwaitTermination() - } - let feed = endpoint.getFeed() + let promise = try eventPromise(type: Trade.self, symbol: "ETH/USD:GDAX", feed: feed!) @@ -97,11 +93,7 @@ final class DXPromiseTest: XCTestCase { func testGetResultWithException() { do { - let endpoint = try DXEndpoint.create().connect("demo.dxfeed.com:7300") - defer { - try? endpoint.closeAndAwaitTermination() - } - let feed = endpoint.getFeed() + let promise = try eventPromise(type: Trade.self, symbol: "ETH/USD:GDAX_TEST", feed: feed!) @@ -117,11 +109,7 @@ final class DXPromiseTest: XCTestCase { func testGetIndexedEventResult() { do { - let endpoint = try DXEndpoint.create().connect("demo.dxfeed.com:7300") - defer { - try? endpoint.closeAndAwaitTermination() - } - let feed = endpoint.getFeed() + guard let promise = try feed?.getIndexedEventsPromise(type: Trade.self, symbol: "ETH/USD:GDAX", source: OrderSource.agregateAsk!) else { @@ -137,11 +125,7 @@ final class DXPromiseTest: XCTestCase { func testGetIndexedEventResultWithException() { do { - let endpoint = try DXEndpoint.create().connect("demo.dxfeed.com:7300") - defer { - try? endpoint.closeAndAwaitTermination() - } - let feed = endpoint.getFeed() + guard let promise = try feed?.getIndexedEventsPromise(type: Trade.self, symbol: "ETH/USD:GDAX_TEST", source: OrderSource.agregateAsk!) else { @@ -158,11 +142,7 @@ final class DXPromiseTest: XCTestCase { func testGetMultipleResults() { do { - let endpoint = try DXEndpoint.create().connect("demo.dxfeed.com:7300") - defer { - try? endpoint.closeAndAwaitTermination() - } - let feed = endpoint.getFeed() + let promises = try feed?.getLastEventPromises(type: Quote.self, symbols: ["ETH/USD:GDAX", "AAPL"]) if promises?.isEmpty != false { XCTAssert(false, "Promises is empty") @@ -182,11 +162,7 @@ final class DXPromiseTest: XCTestCase { func testGetAyncMultipleResults() { do { let symbols = ["ETH/USD:GDAX", "AAPL"] - let endpoint = try DXEndpoint.create().connect("demo.dxfeed.com:7300") - defer { - try? endpoint.closeAndAwaitTermination() - } - let feed = endpoint.getFeed() + let promises = try feed?.getLastEventPromises(type: Quote.self, symbols: symbols) if promises?.isEmpty != false { XCTAssert(false, "Promises is empty") @@ -209,11 +185,7 @@ final class DXPromiseTest: XCTestCase { func testGetMultipleResultsWithException() { do { - let endpoint = try DXEndpoint.create().connect("demo.dxfeed.com:7300") - defer { - try? endpoint.closeAndAwaitTermination() - } - let feed = endpoint.getFeed() + let promises = try feed?.getLastEventPromises(type: Quote.self, symbols: ["ETH/USD:GDAX_TEST", "AAPL_TEST"]) if promises?.isEmpty != false { XCTAssert(false, "Promises is empty") @@ -235,11 +207,7 @@ final class DXPromiseTest: XCTestCase { func testGetTimeSeriesResult() { do { let date = Calendar.current.date(byAdding: .month, value: -1, to: Date())! - let endpoint = try DXEndpoint.create().connect("demo.dxfeed.com:7300") - defer { - try? endpoint.closeAndAwaitTermination() - } - let feed = endpoint.getFeed() + guard let promise = try feed?.getTimeSeriesPromise(type: Candle.self, symbol: "AAPL{=1d}", fromTime: Long(date.millisecondsSince1970), @@ -257,11 +225,7 @@ final class DXPromiseTest: XCTestCase { func testAllOffPromises() { do { - let endpoint = try DXEndpoint.create().connect("demo.dxfeed.com:7300") - defer { - try? endpoint.closeAndAwaitTermination() - } - let feed = endpoint.getFeed() + let promise = try eventPromise(type: Profile.self, symbol: "IBM", feed: feed!) guard var promises = try feed?.getLastEventPromises(type: Quote.self, symbols: ["ETH/USD:GDAX", "AAPL"]) else { @@ -384,52 +348,5 @@ final class DXPromiseTest: XCTestCase { } } - func testTimeSeriesTask() async throws { - let endpoint = try DXEndpoint.create().connect("demo.dxfeed.com:7300") - defer { - try? endpoint.closeAndAwaitTermination() - } - let feed = endpoint.getFeed() - let date = Calendar.current.date(byAdding: .month, value: -1, to: Date())! - guard let task = feed?.getTimeSeries(type: Candle.self, - symbol: "AAPL{=1d}", - fromTime: Long(date.millisecondsSince1970), - toTime: Long.max) else { - XCTAssert(false, "Async task is nil") - return - } - let result = await task.result - switch result { - case .success(let value): - XCTAssert((value?.count ?? 0) > 0) - case .failure(let value): - XCTAssert(false, "\(value)") - } - } - - func testIndexedEventTask() async throws { - throw XCTSkip(""" - Skiped -""") - let endpoint = try DXEndpoint.create().connect("demo.dxfeed.com:7300") - defer { - try? endpoint.closeAndAwaitTermination() - } - let feed = endpoint.getFeed() - let date = Calendar.current.date(byAdding: .month, value: -1, to: Date())! - guard let task = feed?.getIndexedEvents(type: Series.self, - symbol: "ETH/USD:GDAX", - source: OrderSource.agregateAsk!) else { - XCTAssert(false, "Async task is nil") - return - } - let result = await task.result - switch result { - case .success(let value): - XCTAssert((value?.count ?? 0) > 0) - case .failure(let value): - XCTAssert(false, "\(value)") - } - } } // swiftlint:enable type_body_length diff --git a/Samples/QuoteTableApp/QuoteTableViewController.swift b/Samples/QuoteTableApp/QuoteTableViewController.swift index 84c809c19..a3825f359 100644 --- a/Samples/QuoteTableApp/QuoteTableViewController.swift +++ b/Samples/QuoteTableApp/QuoteTableViewController.swift @@ -99,7 +99,7 @@ extension QuoteTableViewController: DXEventListener { func receiveEvents(_ events: [MarketEvent]) { events.forEach { event in switch event.type { - case .quote: + case .quote: dataSource[event.eventSymbol]?.update(event.quote) case .profile: dataSource[event.eventSymbol]?.update(event.profile.descriptionStr ?? "")