-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WriteTapeFile
- Loading branch information
Showing
6 changed files
with
131 additions
and
16 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
49 changes: 49 additions & 0 deletions
49
Samples/Playgrounds/WriteTapeFile.playground/Contents.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 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) | ||
""") | ||
|
||
|
4 changes: 4 additions & 0 deletions
4
Samples/Playgrounds/WriteTapeFile.playground/contents.xcplayground
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,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> |