-
Notifications
You must be signed in to change notification settings - Fork 1
/
Contents.swift
47 lines (39 loc) · 1.37 KB
/
Contents.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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()
let pathComponents = [NSTemporaryDirectory(), "WriteTapeFile.out.txt"]
guard let outputFilePath = NSURL.fileURL(withPathComponents: pathComponents)?.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)
""")