This repo provides samples of using dxFeed Java API.
Find useful information in our self-service dxFeed Knowledge Base:
Adding Gradle Dependency
- add information about the new repository in settings.gradle in the dependencyResolutionManagement section
maven {
url 'https://dxfeed.jfrog.io/artifactory/maven-open'
}
- add information about the required dependencies to the dependencies section of build.gradle
implementation ('com.devexperts.qd:dxlink-websocket:3.328') {}
implementation ('com.devexperts.mdd:auther-api:476') {
exclude module:"qds-monitoring"
}
import com.dxfeed.api.DXEndpoint
import com.dxfeed.event.market.Quote
// For token-based authorization, use the following address format:
// "demo.dxfeed.com:7300[login=entitle:token]"
val endpoint = DXEndpoint.newBuilder().build()
val subscription = endpoint.feed.createSubscription(Quote::class.java)
subscription?.addEventListener {
it.forEach { event -> println(event) }
}
subscription?.addSymbols("AAPL")
endpoint.connect("demo.dxfeed.com:7300")
Output
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}
import com.dxfeed.api.DXEndpoint
import com.dxfeed.event.market.Quote
// The experimental property must be enabled.
System.setProperty("dxfeed.experimental.dxlink.enable", "true")
val endpoint = DXEndpoint.newBuilder().build()
val subscription = endpoint.feed.createSubscription(Quote::class.java)
subscription?.addEventListener {
it.forEach { event -> println(event) }
}
subscription?.addSymbols("AAPL")
endpoint.connect("dxlink:wss://demo.dxfeed.com/dxlink-ws")
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}
To familiarize with the dxLink protocol, please click here.
- Quote Table - simple application that can get current quotes
- Latency Test App - application that displays the latency in receiving data. Based on the difference between system time and event time
- Perf Test App - application for evaluating device performance. Metric: number of events per second that pass through the QD. It is important that the metric also depends on the bandwidth between device and multiplexor