-
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.
PrintQuoteEvents fix test error(reproduced only on github builder)
- Loading branch information
Showing
8 changed files
with
86 additions
and
18 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
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
60 changes: 60 additions & 0 deletions
60
Samples/Playgrounds/PrintQuoteEvents.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,60 @@ | ||
import Foundation | ||
import PlaygroundSupport | ||
import DXFeedFramework | ||
|
||
//Empty Listener with handler | ||
class Listener: DXEventListener, Hashable { | ||
|
||
static func == (lhs: Listener, rhs: Listener) -> Bool { | ||
lhs === rhs | ||
} | ||
|
||
func hash(into hasher: inout Hasher) { | ||
hasher.combine("\(self):\(stringReference(self))") | ||
} | ||
var callback: ([MarketEvent]) -> Void = { _ in } | ||
|
||
func receiveEvents(_ events: [MarketEvent]) { | ||
self.callback(events) | ||
} | ||
|
||
init(overrides: (Listener) -> Listener) { | ||
_ = overrides(self) | ||
} | ||
} | ||
|
||
// A simple sample that shows how to subscribe to quotes for one instruments, | ||
// and print all received quotes to the console. | ||
// Use default DXFeed instance for that data feed address is defined by "dxfeed.properties" file. | ||
// The properties file is copied to the build output directory from the project directory. | ||
|
||
// Specified instrument name, for example AAPL, IBM, MSFT, etc. | ||
let symbol = "AAPL" | ||
|
||
// Use path to dxfeed.properties with feed address | ||
let propertiesFilePath = Bundle.main.path(forResource: "dxfeed.properties", ofType: nil) | ||
try SystemProperty.setProperty(DXEndpoint.Property.properties.rawValue, propertiesFilePath ?? "") | ||
|
||
// Creates a subscription attached to a default DXFeed with a Quote event type. | ||
// The endpoint address to use is stored in the "dxfeed.properties" file. | ||
let subscription = try DXEndpoint.getInstance() | ||
.getFeed()? | ||
.createSubscription(EventCode.quote) | ||
let listenerTrade = Listener { listener in | ||
listener.callback = { events in | ||
events.forEach { event in | ||
print(event.toString()) | ||
} | ||
} | ||
return listener | ||
} | ||
// Listener must be attached before symbols are added. | ||
try subscription?.add(listener: listenerTrade) | ||
try subscription?.addSymbols(symbol) | ||
|
||
|
||
// infinity execution | ||
PlaygroundPage.current.needsIndefiniteExecution = true | ||
|
||
// to finish execution run this line | ||
PlaygroundPage.current.finishExecution() |
2 changes: 2 additions & 0 deletions
2
Samples/Playgrounds/PrintQuoteEvents.playground/Resources/dxfeed.properties
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,2 @@ | ||
# Connection address for an endpoint with role Feed and OnDemandFeed. | ||
dxfeed.address=demo.dxfeed.com:7300 |
4 changes: 4 additions & 0 deletions
4
Samples/Playgrounds/PrintQuoteEvents.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> |