Skip to content

Commit

Permalink
add sample:
Browse files Browse the repository at this point in the history
WriteTapeFile
  • Loading branch information
kosyloa committed Dec 5, 2023
1 parent 3f35401 commit 9e3edcd
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 16 deletions.
60 changes: 60 additions & 0 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@
6401A5142A5820C9009BA686 /* DXFeedAllTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = DXFeedAllTests.xctestplan; sourceTree = "<group>"; };
6406F2562AD9820700B58C42 /* NativePublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativePublisher.swift; sourceTree = "<group>"; };
6406F25A2AD987EB00B58C42 /* PublisherTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublisherTest.swift; sourceTree = "<group>"; };
6408BB712B1F2D14005D7797 /* WriteTapeFile.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = WriteTapeFile.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
64098F492ACD6AF20020D741 /* SceneDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
64098F4C2ACD73820020D741 /* PerfTestEventListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerfTestEventListener.swift; sourceTree = "<group>"; };
64098F542ACD7E940020D741 /* PerformanceMetricsPrinter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerformanceMetricsPrinter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1008,6 +1009,7 @@
644C528D2B1E1CB8002C034C /* ConvertTapeFile.playground */,
644C52902B1E345E002C034C /* DxFeedSample.playground */,
6435EE3C2B1F1E9200E8496C /* PrintQuoteEvents.playground */,
6408BB712B1F2D14005D7797 /* WriteTapeFile.playground */,
);
path = Playgrounds;
sourceTree = "<group>";
Expand Down Expand Up @@ -1467,6 +1469,8 @@
64262CCB2A4DA64700BA6BA3 /* Packages */,
803BAC0E29BFA50700FFAB1C /* Products */,
803BAC2529BFA67C00FFAB1C /* Frameworks */,
C825416ED3A0E46B52373A8F /* xcschemes */,
C8254B3C92B620BC72193130 /* 8.4 */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -1614,6 +1618,62 @@
path = Property;
sourceTree = "<group>";
};
C825416ED3A0E46B52373A8F /* xcschemes */ = {
isa = PBXGroup;
children = (
);
name = xcschemes;
path = DXFeedFramework.xcodeproj/project.xcworkspace/xcuserdata/akosylo.xcuserdatad/xcschemes;
sourceTree = "<group>";
};
C82542FFD107EFFF8F3ADE0D /* checksums */ = {
isa = PBXGroup;
children = (
);
path = checksums;
sourceTree = "<group>";
};
C82549AC99CBAC409C9F0CC3 /* vcsMetadata */ = {
isa = PBXGroup;
children = (
);
path = vcsMetadata;
sourceTree = "<group>";
};
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 = "<group>";
};
C8254BF430409866B626ED3C /* fileChanges */ = {
isa = PBXGroup;
children = (
);
path = fileChanges;
sourceTree = "<group>";
};
C8254EE12256EB1C633A366E /* fileHashes */ = {
isa = PBXGroup;
children = (
);
path = fileHashes;
sourceTree = "<group>";
};
C8254FDB0F46F8BE3FC99B3D /* dependencies-accessors */ = {
isa = PBXGroup;
children = (
);
path = "dependencies-accessors";
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@ sudo /usr/bin/xattr -r -d com.apple.quarantine <directory_with_tools>

## 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
Expand Down
14 changes: 8 additions & 6 deletions Samples/Playgrounds/ConvertTapeFile.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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.
Expand Down Expand Up @@ -99,3 +100,4 @@ ConvertTapeFile:
has been successfully tapped to
\(outputAddress)
""")

10 changes: 5 additions & 5 deletions Samples/Playgrounds/DxFeedFileParser.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
49 changes: 49 additions & 0 deletions Samples/Playgrounds/WriteTapeFile.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -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)
""")


Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

0 comments on commit 9e3edcd

Please sign in to comment.