From e0e51a0e91dc1633181971e24776539bc7b8a537 Mon Sep 17 00:00:00 2001 From: AKosylo Date: Thu, 30 Nov 2023 12:51:03 +0100 Subject: [PATCH] add dxlink sampe in readme.md --- DXFeedFramework.xcodeproj/project.pbxproj | 4 ++ DXFeedFrameworkTests/DXConnectionTest.swift | 68 +++++++++++++++++++++ README.md | 58 +++++++++++++----- 3 files changed, 114 insertions(+), 16 deletions(-) create mode 100644 DXFeedFrameworkTests/DXConnectionTest.swift diff --git a/DXFeedFramework.xcodeproj/project.pbxproj b/DXFeedFramework.xcodeproj/project.pbxproj index ce3131376..84e8c67d0 100644 --- a/DXFeedFramework.xcodeproj/project.pbxproj +++ b/DXFeedFramework.xcodeproj/project.pbxproj @@ -214,6 +214,7 @@ 648BD56B2AC4576F004A3A95 /* HelpTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 648BD56A2AC4576F004A3A95 /* HelpTool.swift */; }; 648BD56D2AC56A04004A3A95 /* SubscriptionUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 648BD56C2AC56A04004A3A95 /* SubscriptionUtils.swift */; }; 648BD56F2AC582AB004A3A95 /* DateTimeParserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 648BD56E2AC582AB004A3A95 /* DateTimeParserTest.swift */; }; + 648C72472B18ABFC00E2FEF3 /* DXConnectionTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 648C72462B18ABFC00E2FEF3 /* DXConnectionTest.swift */; }; 648E98AA2AAF625800BFD219 /* IIndexedEvent+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 648E98A92AAF625800BFD219 /* IIndexedEvent+Ext.swift */; }; 649282E72AD54919008F0F04 /* ScheduleUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649282E62AD54919008F0F04 /* ScheduleUtils.swift */; }; 649282E82AD54919008F0F04 /* ScheduleUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649282E62AD54919008F0F04 /* ScheduleUtils.swift */; }; @@ -686,6 +687,7 @@ 648BD56A2AC4576F004A3A95 /* HelpTool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelpTool.swift; sourceTree = ""; }; 648BD56C2AC56A04004A3A95 /* SubscriptionUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionUtils.swift; sourceTree = ""; }; 648BD56E2AC582AB004A3A95 /* DateTimeParserTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateTimeParserTest.swift; sourceTree = ""; }; + 648C72462B18ABFC00E2FEF3 /* DXConnectionTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXConnectionTest.swift; sourceTree = ""; }; 648E98A92AAF625800BFD219 /* IIndexedEvent+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "IIndexedEvent+Ext.swift"; sourceTree = ""; }; 649282E62AD54919008F0F04 /* ScheduleUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScheduleUtils.swift; sourceTree = ""; }; 649282E92AD55323008F0F04 /* IpfConnect.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IpfConnect.swift; sourceTree = ""; }; @@ -1502,6 +1504,7 @@ 6486B95C2AD0287E00D8D5FA /* DateTests.swift */, 649282EC2AD593F3008F0F04 /* OrderSourceTest.swift */, 6406F25A2AD987EB00B58C42 /* PublisherTest.swift */, + 648C72462B18ABFC00E2FEF3 /* DXConnectionTest.swift */, ); path = DXFeedFrameworkTests; sourceTree = ""; @@ -2372,6 +2375,7 @@ 6401A5152A582134009BA686 /* IsolateTest.swift in Sources */, 6406F25B2AD987EB00B58C42 /* PublisherTest.swift in Sources */, 64ACBCCF2A27851C00032C53 /* FeedTest.swift in Sources */, + 648C72472B18ABFC00E2FEF3 /* DXConnectionTest.swift in Sources */, 6486B95D2AD0287E00D8D5FA /* DateTests.swift in Sources */, 6447A5ED2A8FCC2200739CCF /* UtilsTest.swift in Sources */, 64278C6C2A602CA20074B5AA /* CandleTests.swift in Sources */, diff --git a/DXFeedFrameworkTests/DXConnectionTest.swift b/DXFeedFrameworkTests/DXConnectionTest.swift new file mode 100644 index 000000000..a55e22590 --- /dev/null +++ b/DXFeedFrameworkTests/DXConnectionTest.swift @@ -0,0 +1,68 @@ +// +// DXConnectionTest.swift +// DXFeedFrameworkTests +// +// Created by Aleksey Kosylo on 30.11.23. +// + +import XCTest +@testable import DXFeedFramework + +private class Listener: DXEventListener { + func receiveEvents(_ events: [MarketEvent]) { + events.forEach { + print($0.toString()) + } + } +} + +extension Listener: Hashable { + static func == (lhs: Listener, rhs: Listener) -> Bool { + return lhs === rhs + } + + func hash(into hasher: inout Hasher) { + hasher.combine("\(self):\(stringReference(self))") + } + +} + +final class DXConnectionTest: XCTestCase { + + +// connect "dxlink:wss://demo.dxfeed.com/dxlink-ws" Quote AAPL -p dxfeed.experimental.dxlink.enable=true + func testDXLinkConnection() throws { + try SystemProperty.setProperty("dxfeed.experimental.dxlink.enable", "true") + let endpoint = try DXEndpoint.builder() + .withProperty("dxfeed.address", "dxlink:wss://demo.dxfeed.com/dxlink-ws") + .build() + let subscription = try endpoint.getFeed()?.createSubscription(EventCode.quote) + let eventListener = Listener() + try subscription?.add(listener: eventListener) + try subscription?.addSymbols("AAPL") + wait(seconds: 2) + } + + func testConnection() throws { + let endpoint = try DXEndpoint.builder() + .withProperty("dxfeed.address", "demo.dxfeed.com:7300") + .build() + let subscription = try endpoint.getFeed()?.createSubscription(EventCode.quote) + let eventListener = Listener() + try subscription?.add(listener: eventListener) + try subscription?.addSymbols("AAPL") + wait(seconds: 2) + } + + + + + + func testPerformanceExample() throws { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/README.md b/README.md index 91d5c0abb..815f5b127 100644 --- a/README.md +++ b/README.md @@ -137,13 +137,13 @@ class Listener: DXEventListener { } } -let endpoint = DXEndpoint.builder() - .withPropery("dxfeed.address", "demo.dxfeed.com:7300") +let endpoint = try DXEndpoint.builder() + .withProperty("dxfeed.address", "demo.dxfeed.com:7300") .build() -let subscription = endpoint.getFeed().createSubscription(EventCode.quote) +let subscription = try endpoint.getFeed()?.createSubscription(EventCode.quote) let eventListener = Listener() -subscription.add(observer: eventListener} -subscription.addSymbols("AAPL") +try subscription?.add(listener: eventListener) +try subscription?.addSymbols("AAPL") ```
@@ -151,17 +151,18 @@ subscription.addSymbols("AAPL")
``` -I 221219 224811.681 [main] QD - Using QDS-3.313+file-UNKNOWN+mars-UNKNOWN+monitoring-UNKNOWN+tools-UNKNOWN, (C) Devexperts -I 221219 224811.695 [main] QD - Using scheme com.dxfeed.api.impl.DXFeedScheme DH2FdjP0DtOEIOAbE4pRVpmJsPnaZzAo1mICPJ6b06w -I 221219 224812.010 [main] QD - qd with collectors [Ticker, Stream, History] -I 221219 224812.017 [main] ClientSocket-Distributor - Starting ClientSocketConnector to demo.dxfeed.com:7300 -I 221219 224812.017 [demo.dxfeed.com:7300-Reader] ClientSocketConnector - Resolving IPs for demo.dxfeed.com -I 221219 224812.021 [demo.dxfeed.com:7300-Reader] ClientSocketConnector - Connecting to 208.93.103.170:7300 -I 221219 224812.170 [demo.dxfeed.com:7300-Reader] ClientSocketConnector - Connected to 208.93.103.170:7300 -D 221219 224812.319 [demo.dxfeed.com:7300-Reader] QD - Distributor received protocol descriptor multiplexor@WQMPz [type=qtp, version=QDS-3.306, opt=hs, mars.root=mdd.demo-amazon.multiplexor-demo1] sending [TICKER, STREAM, HISTORY, DATA] from 208.93.103.170 -Quote{AAPL, eventTime=0, time=20221219-223311.000, timeNanoPart=0, sequence=0, bidTime=20221219-223311, bidExchange=Q, bidPrice=132.16, bidSize=2, askTime=20221219-223311, askExchange=K, askPrice=132.17, askSize=10} -Quote{AAPL, eventTime=0, time=20221219-223312.000, timeNanoPart=0, sequence=0, bidTime=20221219-223312, bidExchange=Q, bidPrice=132.16, bidSize=6, askTime=20221219-223312, askExchange=K, askPrice=132.17, askSize=10} -Quote{AAPL, eventTime=0, time=20221219-223312.000, timeNanoPart=0, sequence=0, bidTime=20221219-223312, bidExchange=K, bidPrice=132.16, bidSize=10, askTime=20221219-223312, askExchange=V, askPrice=132.17, askSize=4} +I 231130 124734.411 [main] QD - Using QDS-3.325+file-UNKNOWN, (C) Devexperts +I 231130 124734.415 [main] QD - Using scheme com.dxfeed.api.impl.DXFeedScheme slfwemJduh1J7ibvy9oo8DABTNhNALFQfw0KmE40CMI +I 231130 124734.418 [main] MARS - Started time synchronization tracker using multicast 239.192.51.45:5145 with dPyAu +I 231130 124734.422 [main] MARS - Started JVM self-monitoring +I 231130 124734.423 [main] QD - monitoring with collectors [Ticker, Stream, History] +I 231130 124734.424 [main] QD - monitoring DXEndpoint with dxfeed.address=demo.dxfeed.com:7300 +I 231130 124734.425 [main] ClientSocket-Distributor - Starting ClientSocketConnector to demo.dxfeed.com:7300 +I 231130 124734.425 [demo.dxfeed.com:7300-Reader] ClientSocketConnector - Resolving IPs for demo.dxfeed.com +I 231130 124734.427 [demo.dxfeed.com:7300-Reader] ClientSocketConnector - Connecting to 208.93.103.170:7300 +I 231130 124734.530 [demo.dxfeed.com:7300-Reader] ClientSocketConnector - Connected to 208.93.103.170:7300 +D 231130 124734.634 [demo.dxfeed.com:7300-Reader] QD - Distributor received protocol descriptor multiplexor@fFLro [type=qtp, version=QDS-3.319, opt=hs, mars.root=mdd.demo-amazon.multiplexor-demo1] sending [TICKER, STREAM, HISTORY, DATA] from 208.93.103.170 +Quote{AAPL, eventTime=0, time=20231130-123206.000, timeNanoPart=0, sequence=0, bidTime=20231130-123206.000, bidExchange=P, bidPrice=189.36, bidSize=3.0, askTime=20231130-123129.000, askExchange=P, askPrice=189.53, askSize=10.0} ```
@@ -178,11 +179,36 @@ Quote{AAPL, eventTime=0, time=20221219-223312.000, timeNanoPart=0, sequence=0, b ### How to connect to dxLink +```swift +try SystemProperty.setProperty("dxfeed.experimental.dxlink.enable", "true") +let endpoint = try DXEndpoint.builder() + .withProperty("dxfeed.address", "dxlink:wss://demo.dxfeed.com/dxlink-ws") + .build() +let subscription = try endpoint.getFeed()?.createSubscription(EventCode.quote) +let eventListener = Listener() +try subscription?.add(listener: eventListener) +try subscription?.addSymbols("AAPL") +```
Output
``` +I 231130 124929.817 [main] QD - Using QDS-3.325+file-UNKNOWN, (C) Devexperts +I 231130 124929.821 [main] QD - Using scheme com.dxfeed.api.impl.DXFeedScheme slfwemJduh1J7ibvy9oo8DABTNhNALFQfw0KmE40CMI +I 231130 124929.824 [main] MARS - Started time synchronization tracker using multicast 239.192.51.45:5145 with sWipb +I 231130 124929.828 [main] MARS - Started JVM self-monitoring +I 231130 124929.828 [main] QD - monitoring with collectors [Ticker, Stream, History] +I 231130 124929.829 [main] QD - monitoring DXEndpoint with dxfeed.address=dxlink:wss://demo.dxfeed.com/dxlink-ws +I 231130 124929.831 [main] DxLinkClientWebSocket-Distributor - Starting DxLinkClientWebSocketConnector to wss://demo.dxfeed.com/dxlink-ws +SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". +SLF4J: Defaulting to no-operation (NOP) logger implementation +SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. +I 231130 124929.831 [wss://demo.dxfeed.com/dxlink-ws-Writer] DxLinkClientWebSocket-Distributor - Connecting to wss://demo.dxfeed.com/dxlink-ws +I 231130 124930.153 [wss://demo.dxfeed.com/dxlink-ws-Writer] DxLinkClientWebSocket-Distributor - Connected to wss://demo.dxfeed.com/dxlink-ws +D 231130 124931.269 [oioEventLoopGroup-2-1] QD - Distributor received protocol descriptor [type=dxlink, version=0.1-0.18-20231017-133150, keepaliveTimeout=120, acceptKeepaliveTimeout=5] sending [] from wss://demo.dxfeed.com/dxlink-ws +D 231130 124931.271 [oioEventLoopGroup-2-1] QD - Distributor received protocol descriptor [type=dxlink, version=0.1-0.18-20231017-133150, keepaliveTimeout=120, acceptKeepaliveTimeout=5, authentication=] sending [] from wss://demo.dxfeed.com/dxlink-ws +Quote{AAPL, eventTime=0, time=20231130-123421.000, timeNanoPart=0, sequence=0, bidTime=20231130-123421.000, bidExchange=Q, bidPrice=189.47, bidSize=4.0, askTime=20231130-123421.000, askExchange=P, askPrice=189.53, askSize=10.0} ```