-
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.
- Loading branch information
Showing
10 changed files
with
142 additions
and
6 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
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
78 changes: 78 additions & 0 deletions
78
Samples/Playgrounds/DXFeedconnect.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,78 @@ | ||
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) | ||
} | ||
} | ||
|
||
let allTypes = [Candle.self, | ||
Trade.self, | ||
TradeETH.self, | ||
Quote.self, | ||
TimeAndSale.self, | ||
Profile.self, | ||
Summary.self, | ||
Greeks.self, | ||
Underlying.self, | ||
TheoPrice.self, | ||
Order.self, | ||
AnalyticOrder.self, | ||
SpreadOrder.self, | ||
Series.self, | ||
OptionSale.self] | ||
|
||
let argSymbols = ["ETH/USD:GDAX"] | ||
let argTime: String? = nil | ||
|
||
// To avoid release inside internal {} scope | ||
//let endpoint = try DXEndpoint.create().connect("demo.dxfeed.com:7300") | ||
let feed = try DXEndpoint.getInstance().connect("demo.dxfeed.com:7300").getFeed() | ||
var feedSubscription: DXFeedSubscription? = nil | ||
let listener = Listener { listener in | ||
listener.callback = { events in | ||
events.forEach { event in | ||
print(event.toString()) | ||
} | ||
} | ||
return listener | ||
} | ||
|
||
if let argTime = argTime, let time: Long = try DXTimeFormat.defaultTimeFormat?.parse(argTime) { | ||
let types: [ITimeSeriesEvent.Type] = allTypes.compactMap({ event in | ||
event as? ITimeSeriesEvent.Type | ||
}) | ||
let subscription = try feed?.createTimeSeriesSubscription(types) | ||
try subscription?.add(listener: listener) | ||
try subscription?.set(fromTime: time) | ||
try subscription?.addSymbols(argSymbols) | ||
feedSubscription = subscription | ||
} else { | ||
let subscription = try feed?.createSubscription(allTypes) | ||
try subscription?.add(listener: listener) | ||
try subscription?.addSymbols(argSymbols) | ||
feedSubscription = subscription | ||
} | ||
|
||
// infinity execution | ||
PlaygroundPage.current.needsIndefiniteExecution = true | ||
|
||
// to finish execution run this line | ||
PlaygroundPage.current.finishExecution() |
4 changes: 4 additions & 0 deletions
4
Samples/Playgrounds/DXFeedconnect.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 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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import UIKit | ||
import PlaygroundSupport | ||
import DXFeedFramework | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
Samples/Playgrounds/PublishProfiles.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'> | ||
<playground version='5.0' target-platform='macos' buildActiveScheme='true' importAppTypes='true'> | ||
<timeline fileName='timeline.xctimeline'/> | ||
</playground> |