diff --git a/DXFeedFramework.xcodeproj/project.pbxproj b/DXFeedFramework.xcodeproj/project.pbxproj index e9c793abe..6a1d68f85 100644 --- a/DXFeedFramework.xcodeproj/project.pbxproj +++ b/DXFeedFramework.xcodeproj/project.pbxproj @@ -542,6 +542,7 @@ 6401A5142A5820C9009BA686 /* DXFeedAllTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = DXFeedAllTests.xctestplan; sourceTree = ""; }; 6406F2562AD9820700B58C42 /* NativePublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativePublisher.swift; sourceTree = ""; }; 6406F25A2AD987EB00B58C42 /* PublisherTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublisherTest.swift; sourceTree = ""; }; + 6408BB712B1F2D14005D7797 /* WriteTapeFile.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = WriteTapeFile.playground; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 64098F492ACD6AF20020D741 /* SceneDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 64098F4C2ACD73820020D741 /* PerfTestEventListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerfTestEventListener.swift; sourceTree = ""; }; 64098F542ACD7E940020D741 /* PerformanceMetricsPrinter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerformanceMetricsPrinter.swift; sourceTree = ""; }; @@ -1008,6 +1009,7 @@ 644C528D2B1E1CB8002C034C /* ConvertTapeFile.playground */, 644C52902B1E345E002C034C /* DxFeedSample.playground */, 6435EE3C2B1F1E9200E8496C /* PrintQuoteEvents.playground */, + 6408BB712B1F2D14005D7797 /* WriteTapeFile.playground */, ); path = Playgrounds; sourceTree = ""; @@ -1467,6 +1469,8 @@ 64262CCB2A4DA64700BA6BA3 /* Packages */, 803BAC0E29BFA50700FFAB1C /* Products */, 803BAC2529BFA67C00FFAB1C /* Frameworks */, + C825416ED3A0E46B52373A8F /* xcschemes */, + C8254B3C92B620BC72193130 /* 8.4 */, ); sourceTree = ""; }; @@ -1614,6 +1618,62 @@ path = Property; sourceTree = ""; }; + C825416ED3A0E46B52373A8F /* xcschemes */ = { + isa = PBXGroup; + children = ( + ); + name = xcschemes; + path = DXFeedFramework.xcodeproj/project.xcworkspace/xcuserdata/akosylo.xcuserdatad/xcschemes; + sourceTree = ""; + }; + C82542FFD107EFFF8F3ADE0D /* checksums */ = { + isa = PBXGroup; + children = ( + ); + path = checksums; + sourceTree = ""; + }; + C82549AC99CBAC409C9F0CC3 /* vcsMetadata */ = { + isa = PBXGroup; + children = ( + ); + path = vcsMetadata; + sourceTree = ""; + }; + C8254B3C92B620BC72193130 /* 8.4 */ = { + isa = PBXGroup; + children = ( + C8254BF430409866B626ED3C /* fileChanges */, + C82549AC99CBAC409C9F0CC3 /* vcsMetadata */, + C82542FFD107EFFF8F3ADE0D /* checksums */, + C8254EE12256EB1C633A366E /* fileHashes */, + C8254FDB0F46F8BE3FC99B3D /* dependencies-accessors */, + ); + name = 8.4; + path = .gradle/8.4; + sourceTree = ""; + }; + C8254BF430409866B626ED3C /* fileChanges */ = { + isa = PBXGroup; + children = ( + ); + path = fileChanges; + sourceTree = ""; + }; + C8254EE12256EB1C633A366E /* fileHashes */ = { + isa = PBXGroup; + children = ( + ); + path = fileHashes; + sourceTree = ""; + }; + C8254FDB0F46F8BE3FC99B3D /* dependencies-accessors */ = { + isa = PBXGroup; + children = ( + ); + path = "dependencies-accessors"; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ diff --git a/README.md b/README.md index 6cca59e6f..cdc0a03e0 100644 --- a/README.md +++ b/README.md @@ -246,11 +246,11 @@ sudo /usr/bin/xattr -r -d com.apple.quarantine ## Samples -- [x] ConvertTapeFile demonstrates how to convert one tape file to another tape file with optional intermediate processing or filtering -- [x] DxFeedFileParser is a simple demonstration of how events are read form a tape file -- [x] DxFeedSample is a simple demonstration of how to create multiple event listeners and subscribe to `Quote` and `Trade` events -- [x] PrintQuoteEvents is a simple demonstration of how to subscribe to the `Quote` event, using a `DxFeed` instance singleton and `dxfeed.properties` file -- [ ] WriteTapeFile is a simple demonstration of how to write events to a tape file +- [x] [ConvertTapeFile](https://github.com/dxFeed/dxfeed-graal-swift-api/blob/swift/Samples/Playgrounds/ConvertTapeFile.playground/Contents.swift) demonstrates how to convert one tape file to another tape file with optional intermediate processing or filtering +- [x] [DxFeedFileParser](https://github.com/dxFeed/dxfeed-graal-swift-api/blob/swift/Samples/Playgrounds/DxFeedFileParser.playground/Contents.swift) is a simple demonstration of how events are read form a tape file +- [x] [DxFeedSample](https://github.com/dxFeed/dxfeed-graal-swift-api/blob/swift/Samples/Playgrounds/DxFeedSample.playground/Contents.swift) is a simple demonstration of how to create multiple event listeners and subscribe to `Quote` and `Trade` events +- [x] [PrintQuoteEvents](https://github.com/dxFeed/dxfeed-graal-swift-api/blob/swift/Samples/Playgrounds/PrintQuoteEvents.playground/Contents.swift) is a simple demonstration of how to subscribe to the `Quote` event, using a `DxFeed` instance singleton and `dxfeed.properties` file +- [x] [WriteTapeFile](https://github.com/dxFeed/dxfeed-graal-swift-api/blob/swift/Samples/Playgrounds/WriteTapeFile.playground/Contents.swift) is a simple demonstration of how to write events to a tape file - [x] [DxFeedIpfConnect](https://github.com/dxFeed/dxfeed-graal-swift-api/blob/swift/Samples/Tools/IpfConnect.swift) is a simple demonstration of how to get Instrument Profiles - [x] [DXFeedLiveIpfSample](https://github.com/dxFeed/dxfeed-graal-swift-api/blob/swift/Samples/Tools/LiveIpfSample.swift) is a simple demonstration of how to get live updates for Instrument Profiles diff --git a/Samples/Playgrounds/ConvertTapeFile.playground/Contents.swift b/Samples/Playgrounds/ConvertTapeFile.playground/Contents.swift index fbf57dbbf..2a4d08722 100644 --- a/Samples/Playgrounds/ConvertTapeFile.playground/Contents.swift +++ b/Samples/Playgrounds/ConvertTapeFile.playground/Contents.swift @@ -23,13 +23,14 @@ class Listener: DXEventListener, Hashable { } -let inputFilePath = Bundle.main.path(forResource: "ConvertTapeFile.in", ofType: nil) -let tempDirectory = NSTemporaryDirectory() -let outputFilePath = NSURL.fileURL(withPathComponents: [tempDirectory, "ConvertTapeFile.out"])?.path +guard let inputFilePath = Bundle.main.path(forResource: "ConvertTapeFile.in", ofType: nil), + let outputFilePath = NSURL.fileURL(withPathComponents: [NSTemporaryDirectory(), "ConvertTapeFile.out"])?.path else { + fatalError("Wrong path to output file") +} // Determine input and output tapes and specify appropriate configuration parameters. -let inputAddress = "file:\(inputFilePath ?? "")[readAs=stream_data,speed=max]" -let outputAddress = "tape:\(outputFilePath ?? "" )[saveAs=stream_data,format=text]" +let inputAddress = "file:\(inputFilePath)[readAs=stream_data,speed=max]" +let outputAddress = "tape:\(outputFilePath)[saveAs=stream_data,format=text]" // Create input endpoint configured for tape reading. let inputEndpoint = try DXEndpoint.builder() @@ -39,7 +40,7 @@ let inputEndpoint = try DXEndpoint.builder() .build() // Create output endpoint configured for tape writing. -var outputEndpoint = try DXEndpoint.builder() +let outputEndpoint = try DXEndpoint.builder() .withRole(.streamPublisher) // Prevents event conflation and loss due to buffer overflow. .withProperty(DXEndpoint.Property.wildcardEnable.rawValue, "true") // Enables wildcard subscription. .withProperty(DXEndpoint.Property.eventTime.rawValue, "true") // Use provided event times. @@ -99,3 +100,4 @@ ConvertTapeFile: has been successfully tapped to \(outputAddress) """) + diff --git a/Samples/Playgrounds/DxFeedFileParser.playground/Contents.swift b/Samples/Playgrounds/DxFeedFileParser.playground/Contents.swift index c9e8963a0..84618cfb4 100644 --- a/Samples/Playgrounds/DxFeedFileParser.playground/Contents.swift +++ b/Samples/Playgrounds/DxFeedFileParser.playground/Contents.swift @@ -23,14 +23,14 @@ class Listener: DXEventListener, Hashable { } -var file: String = "" -var types: [EventCode] = [.quote] -var symbols = "AAPL" +let file: String = "" +let types: [EventCode] = [.quote] +let symbols = "AAPL" var eventCounter = 0 // Create endpoint specifically for file parsing. -var endpoint = try DXEndpoint.create(.streamFeed) -var feed = endpoint.getFeed() +let endpoint = try DXEndpoint.create(.streamFeed) +let feed = endpoint.getFeed() // Subscribe to a specified event and symbol. var sub = try feed?.createSubscription(types) diff --git a/Samples/Playgrounds/WriteTapeFile.playground/Contents.swift b/Samples/Playgrounds/WriteTapeFile.playground/Contents.swift new file mode 100644 index 000000000..19086a72d --- /dev/null +++ b/Samples/Playgrounds/WriteTapeFile.playground/Contents.swift @@ -0,0 +1,49 @@ +import Cocoa +import DXFeedFramework + +// Write events to a tape file. + +// Create an appropriate endpoint. +let endpoint = try DXEndpoint.builder() +// Is required for tape connector to be able to receive everything. + .withProperty(DXEndpoint.Property.wildcardEnable.rawValue, "true") + .withRole(.publisher) + .build() + +guard let outputFilePath = NSURL.fileURL(withPathComponents: [NSTemporaryDirectory(), "WriteTapeFile.out.txt"])?.path else { + fatalError("Wrong path to output file") +} + +// Connect to the address, remove [format=text] or change on [format=binary] for binary format +try endpoint.connect("tape:\(outputFilePath)[format=text]") +// Get publisher. +let publisher = endpoint.getPublisher() + +// Creates new Quote market events. +let quote1 = Quote("TEST1") +Optional(quote1).map { + $0.bidPrice = 10.1 + $0.askPrice = 10.2 +} +let quote2 = Quote("TEST2") +Optional(quote2).map { + $0.bidPrice = 17.1 + $0.askPrice = 18.1 +} + +// Publish events. +try publisher?.publish(events: [quote1, quote2]) + +// Wait until all data is written, close, and wait until it closes. +try endpoint.awaitProcessed() +try endpoint.closeAndAWaitTermination() + + +// Just print content of result file +let resultTxtFile = try NSString(contentsOf: URL(filePath: outputFilePath), encoding: NSUTF8StringEncoding) +print(""" +Result content of \(outputFilePath): +\(resultTxtFile) +""") + + diff --git a/Samples/Playgrounds/WriteTapeFile.playground/contents.xcplayground b/Samples/Playgrounds/WriteTapeFile.playground/contents.xcplayground new file mode 100644 index 000000000..1c968e7d1 --- /dev/null +++ b/Samples/Playgrounds/WriteTapeFile.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file