-
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.
DxFeedIpfConnect to playground sample
- Loading branch information
Showing
7 changed files
with
79 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,10 +59,6 @@ | |
argument = "Dump" | ||
isEnabled = "NO"> | ||
</CommandLineArgument> | ||
<CommandLineArgument | ||
argument = "DXFeedIpfConnect Quote https://demo:[email protected]/ipf" | ||
isEnabled = "NO"> | ||
</CommandLineArgument> | ||
<CommandLineArgument | ||
argument = "ScheduleSample schedule.zip sample.ipf.zip -f AAPL 2012-05-26-14:15:00" | ||
isEnabled = "NO"> | ||
|
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
70 changes: 70 additions & 0 deletions
70
Samples/Playgrounds/DxFeedIpfConnect.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,70 @@ | ||
import Cocoa | ||
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) | ||
} | ||
} | ||
|
||
// An sample that demonstrates a subscription using InstrumentProfile. | ||
// 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. | ||
|
||
var type = EventCode.timeAndSale | ||
// You can use local ipf file | ||
var ipfFile = "https://demo:[email protected]/ipf" | ||
|
||
// 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 ?? "") | ||
|
||
print("Reading instruments from \(ipfFile)") | ||
guard let profiles = try DXInstrumentProfileReader().readFromFile(address: ipfFile) else { | ||
fatalError("No profiles in \(ipfFile)") | ||
} | ||
// This is just a sample, any arbitrary filtering may go here. | ||
let symbols = profiles.filter({ ipf in | ||
ipf.getIpfType() == .stock | ||
}).map({ profile in | ||
profile.symbol | ||
}) | ||
|
||
print("Selected symbols are: \(symbols)") | ||
let subscription = try DXEndpoint.getInstance().getFeed()?.createSubscription(type) | ||
let listener = Listener { listener in | ||
listener.callback = { events in | ||
// Prints all received events. | ||
events.forEach { event in | ||
print(event.toString()) | ||
} | ||
} | ||
return listener | ||
} | ||
// Listener must be attached before symbols are added. | ||
try subscription?.add(listener: listener) | ||
// Adds specified symbol. | ||
try subscription?.addSymbols(symbols) | ||
|
||
|
||
// infinity execution | ||
PlaygroundPage.current.needsIndefiniteExecution = true | ||
|
||
// to finish execution run this line | ||
PlaygroundPage.current.finishExecution() |
2 changes: 2 additions & 0 deletions
2
Samples/Playgrounds/DxFeedIpfConnect.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/DxFeedIpfConnect.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> |
This file was deleted.
Oops, something went wrong.