Skip to content

Commit

Permalink
DXFeedLiveIpfSample to playground sample
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Dec 5, 2023
1 parent 33d01d5 commit b0f2f6a
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 126 deletions.
6 changes: 2 additions & 4 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@
6486B9792AD04F4000D8D5FA /* OrderBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6486B9782AD04F4000D8D5FA /* OrderBase.swift */; };
6486B97B2AD0517A00D8D5FA /* OrderAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6486B97A2AD0517A00D8D5FA /* OrderAction.swift */; };
6486B97D2AD057F200D8D5FA /* OrderSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6486B97C2AD057F200D8D5FA /* OrderSource.swift */; };
6486B97F2AD4167800D8D5FA /* LiveIpfSample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6486B97E2AD4167800D8D5FA /* LiveIpfSample.swift */; };
648BD5692AC450D6004A3A95 /* ConnectTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 648BD5682AC450D6004A3A95 /* ConnectTool.swift */; };
648BD56B2AC4576F004A3A95 /* HelpTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 648BD56A2AC4576F004A3A95 /* HelpTool.swift */; };
648BD56D2AC56A04004A3A95 /* SubscriptionUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 648BD56C2AC56A04004A3A95 /* SubscriptionUtils.swift */; };
Expand Down Expand Up @@ -542,6 +541,7 @@
6406F2562AD9820700B58C42 /* NativePublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativePublisher.swift; sourceTree = "<group>"; };
6406F25A2AD987EB00B58C42 /* PublisherTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublisherTest.swift; sourceTree = "<group>"; };
640885C42B1F477A00E6CF88 /* DxFeedIpfConnect.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = DxFeedIpfConnect.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
640885C52B1F553C00E6CF88 /* DXFeedLiveIpfSample.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = DXFeedLiveIpfSample.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
6408BB712B1F2D14005D7797 /* WriteTapeFile.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = WriteTapeFile.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
64098F492ACD6AF20020D741 /* SceneDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
64098F4C2ACD73820020D741 /* PerfTestEventListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerfTestEventListener.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -690,7 +690,6 @@
6486B9782AD04F4000D8D5FA /* OrderBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderBase.swift; sourceTree = "<group>"; };
6486B97A2AD0517A00D8D5FA /* OrderAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderAction.swift; sourceTree = "<group>"; };
6486B97C2AD057F200D8D5FA /* OrderSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderSource.swift; sourceTree = "<group>"; };
6486B97E2AD4167800D8D5FA /* LiveIpfSample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveIpfSample.swift; sourceTree = "<group>"; };
648BD5682AC450D6004A3A95 /* ConnectTool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectTool.swift; sourceTree = "<group>"; };
648BD56A2AC4576F004A3A95 /* HelpTool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelpTool.swift; sourceTree = "<group>"; };
648BD56C2AC56A04004A3A95 /* SubscriptionUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionUtils.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -966,7 +965,6 @@
641BDD572AC71CCE00236B78 /* LatencyTestTool.swift */,
645BE8512AC31E7C0028243D /* PerfTestTool.swift */,
648BD5682AC450D6004A3A95 /* ConnectTool.swift */,
6486B97E2AD4167800D8D5FA /* LiveIpfSample.swift */,
64FFE59E2AD430E4003D3353 /* ScheduleSample.swift */,
645CD0032AE145E600F99FCF /* DumpTool.swift */,
648BD56A2AC4576F004A3A95 /* HelpTool.swift */,
Expand Down Expand Up @@ -1009,6 +1007,7 @@
6435EE3C2B1F1E9200E8496C /* PrintQuoteEvents.playground */,
6408BB712B1F2D14005D7797 /* WriteTapeFile.playground */,
640885C42B1F477A00E6CF88 /* DxFeedIpfConnect.playground */,
640885C52B1F553C00E6CF88 /* DXFeedLiveIpfSample.playground */,
);
path = Playgrounds;
sourceTree = "<group>";
Expand Down Expand Up @@ -2121,7 +2120,6 @@
647426AF2ABC93900012F793 /* EventCode+String.swift in Sources */,
645BE8542AC3229D0028243D /* ToolsCommand.swift in Sources */,
644FE5D12AC1F34000580E3A /* LatencyMetricsPrinter.swift in Sources */,
6486B97F2AD4167800D8D5FA /* LiveIpfSample.swift in Sources */,
645BE8522AC31E7C0028243D /* PerfTestTool.swift in Sources */,
645CD0042AE145E600F99FCF /* DumpTool.swift in Sources */,
641E45F92B1DE51700649363 /* EventsListener.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ sudo /usr/bin/xattr -r -d com.apple.quarantine <directory_with_tools>
- [x] [PrintQuoteEvents](https://github.com/dxFeed/dxfeed-graal-swift-api/blob/swift/Samples/Playgrounds/PrintQuoteEvents.playground/Contents.swift) is a simple demonstration of how to subscribe to the `Quote` event, using a `DxFeed` instance singleton and `dxfeed.properties` file
- [x] [WriteTapeFile](https://github.com/dxFeed/dxfeed-graal-swift-api/blob/swift/Samples/Playgrounds/WriteTapeFile.playground/Contents.swift) is a simple demonstration of how to write events to a tape file
- [x] [DxFeedIpfConnect](https://github.com/dxFeed/dxfeed-graal-swift-api/blob/swift/Samples/Playgrounds/DxFeedIpfConnect.playground/Contents.swift) is a simple demonstration of how to get Instrument Profiles
- [x] [DXFeedLiveIpfSample](https://github.com/dxFeed/dxfeed-graal-swift-api/blob/swift/Samples/Tools/LiveIpfSample.swift)
- [x] [DXFeedLiveIpfSample](https://github.com/dxFeed/dxfeed-graal-swift-api/blob/swift/Samples/Playgrounds/DXFeedLiveIpfSample.playground/Contents.swift)
is a simple demonstration of how to get live updates for Instrument Profiles
- [ ] DxFeedPublishProfiles is a simple demonstration of how to publish market events
- [x] [ScheduleSample](https://github.com/dxFeed/dxfeed-graal-swift-api/blob/swift/Samples/Tools/ScheduleSample.swift)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import DXFeedFramework

//Empty Listener with handler
// Empty Listener with handler
class Listener: DXEventListener, Hashable {

static func == (lhs: Listener, rhs: Listener) -> Bool {
Expand Down
69 changes: 69 additions & 0 deletions Samples/Playgrounds/DXFeedLiveIpfSample.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import Cocoa
import PlaygroundSupport
import DXFeedFramework

class Listener: DXInstrumentProfileUpdateListener, Hashable {
// Data model to keep all instrument profiles mapped by their ticker symbol
private var profiles = [String: InstrumentProfile]()
let collector: DXInstrumentProfileCollector

init(_ collector: DXInstrumentProfileCollector) {
self.collector = collector
}


func instrumentProfilesUpdated(_ instruments: [DXFeedFramework.InstrumentProfile]) {
// We can observe REMOVED elements - need to add necessary filtering
// See javadoc for InstrumentProfileCollector for more details

// (1) We can either process instrument profile updates manually
instruments.forEach { ipf in
if ipf.getIpfType() == .removed {
// Profile was removed - remove it from our data model
self.profiles.removeValue(forKey: ipf.symbol)
} else {
// Profile was updated - collector only notifies us if profile was changed
self.profiles[ipf.symbol] = ipf
}
}
print(
"""
Instrument Profiles:
Total number of profiles (1): \(self.profiles.count)
Last modified: \(
(try? DXTimeFormat.defaultTimeFormat?.withMillis?.format(value: collector.getLastUpdateTime())) ?? ""
)
"""
)
}

static func == (lhs: Listener, rhs: Listener) -> Bool {
return lhs === rhs
}

func hash(into hasher: inout Hasher) {
hasher.combine("\(self):\(stringReference(self))")
}

}


// An sample that demonstrates a subscription using InstrumentProfile.
let defaultIpfUrl = "https://demo:[email protected]/ipf"

let collector = try DXInstrumentProfileCollector()
let connection = try DXInstrumentProfileConnection(defaultIpfUrl, collector)
// Update period can be used to re-read IPF files, not needed for services supporting IPF "live-update"
try connection.setUpdatePeriod(60000)
try connection.start()
// It is possible to add listener after connection is started - updates will not be missed in this case
let listener = Listener(collector)
try collector.add(listener: listener)


// infinity execution
PlaygroundPage.current.needsIndefiniteExecution = true

// to finish execution run this line
PlaygroundPage.current.finishExecution()
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>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Cocoa
import PlaygroundSupport
import DXFeedFramework

//Empty Listener with handler
// Empty Listener with handler
class Listener: DXEventListener, Hashable {

static func == (lhs: Listener, rhs: Listener) -> Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import PlaygroundSupport
import DXFeedFramework

//Empty Listener with handler
// Empty Listener with handler
class Listener: DXEventListener, Hashable {

static func == (lhs: Listener, rhs: Listener) -> Bool {
Expand Down
116 changes: 0 additions & 116 deletions Samples/Tools/LiveIpfSample.swift

This file was deleted.

2 changes: 0 additions & 2 deletions Samples/Tools/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import Foundation
let commands: [ToolsCommand] = [PerfTestTool(),
ConnectTool(),
LatencyTestTool(),
LiveIpfSample(),
ScheduleSample(),
IpfConnect(),
DumpTool(),
HelpTool()]

Expand Down

0 comments on commit b0f2f6a

Please sign in to comment.