Skip to content

For Swift developers, this library offers easy access to dxFeed market data. Built upon the GraalVM Native Image and our flagship dxFeed Java API, it provides a seamless experience for Swift-based applications

License

Notifications You must be signed in to change notification settings

dxFeed/dxfeed-graal-swift-api

Repository files navigation

light

This package provides access to dxFeed market data. The library is built as a language-specific wrapper over the dxFeed Graal Native library, which was compiled with GraalVM Native Image and dxFeed Java API (our flagman API).

Build Platform Language Release SPM License

Table of Contents

Overview

dxFeed Graal Swift API allows developers to create efficient applications in Swift language. This enables developers to leverage all the benefits of native app development, resulting in maximum performance and usability for end users.

Implementation Details

We use GraalVM Native Image technology and specially written code that wraps Java methods into native ones to get dynamically linked libraries for different platforms (Linux, macOS, and Windows) based on the latest Java API package.

Then, the resulting dynamic link library (dxFeed Graal-native) is used through C ABI (application binary interface), and we write programming interfaces that describe our business model (similar to Java API).

As a result, we get a full-featured, similar performance as with Java API. Regardless of the language, writing the final application logic using API calls will be very similar (only the syntax will be amended, "best practices", specific language restrictions)

Below is a scheme of this process:

light

Documentation

Find useful information in our self-service dxFeed Knowledge Base or Swift API documentation:

Requirements

macOS

OS Version Architectures
macOS 10.13+ x64
macOS 11+ Arm64

Is supported in the Rosetta 2 x64 emulator.

iOS

OS Version Architectures
iOS 12+ Arm64
iOS Simulator 12+ x64, Arm64

Installation

Adding a Dependency

  1. Open your project in Xcode.
  2. Select File > Swift Packages > Add Package Dependency…
  3. Enter the URL https://github.com/dxFeed/dxfeed-graal-swift-api of the package repository and click Next.
  4. Choose the version or branch you want and click Next.
  5. Select the target to which you want to add the package and click Finish.

Usage

How to connect to QD endpoint

class Listener: DXEventListener {
    func receiveEvents(_ events: [MarketEvent]) {
        events.forEach {
            print($0.toString())
        }
    }
}

// For token-based authorization, use the following address format:
// "demo.dxfeed.com:7300[login=entitle:token]"
let endpoint = try DXEndpoint.builder().build()
let subscription = try endpoint.getFeed()?.createSubscription(EventCode.quote)
let eventListener = Listener()
try subscription?.add(listener: eventListener)
try subscription?.addSymbols("AAPL")
try 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}

How to connect to dxLink

class Listener: DXEventListener {
    func receiveEvents(_ events: [MarketEvent]) {
        events.forEach {
            print($0.toString())
        }
    }
}

// The experimental property must be enabled.
try SystemProperty.setProperty("dxfeed.experimental.dxlink.enable", "true")
// Set scheme for dxLink.
try SystemProperty.setProperty("scheme", "ext:opt:sysprops,resource:dxlink.xml")

// For token-based authorization, use the following address format:
// "dxlink:wss://demo.dxfeed.com/dxlink-ws[login=dxlink:token]"
let endpoint = try DXEndpoint.builder().build()
let subscription = try endpoint.getFeed()?.createSubscription(EventCode.quote)
let eventListener = Listener()
try subscription?.add(listener: eventListener)
try subscription?.addSymbols("AAPL")
try 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.

Tools

Tools is a collection of utilities that allow you to subscribe to various market events for the specified symbols. The tools can be downloaded from Release (tools.zip includes self-contained versions)

  • Connect connects to the specified address(es) and subscribes to the specified events with the specified symbol
  • Dump dumps all events received from address. This was designed to retrieve data from a file
  • PerfTest connects to the specified address(es) and calculates performance counters (events per second, memory usage, CPU usage, etc.)
  • LatencyTest connects to the specified address(es) and calculates latency
  • Qds collection of tools ported from the Java qds-tools

To run tools on macOS, it may be necessary to unquarantine them:

sudo /usr/bin/xattr -r -d com.apple.quarantine <directory_with_tools>

Samples

  • ConvertTapeFile demonstrates how to convert one tape file to another tape file with optional intermediate processing or filtering
  • DxFeedFileParser is a simple demonstration of how events are read form a tape file
  • DxFeedSample is a simple demonstration of how to create multiple event listeners and subscribe to Quote and Trade events
  • PrintQuoteEvents is a simple demonstration of how to subscribe to the Quote event, using a DxFeed instance singleton and dxfeed.properties file
  • WriteTapeFile is a simple demonstration of how to write events to a tape file
  • DxFeedIpfConnect is a simple demonstration of how to get Instrument Profiles
  • DXFeedLiveIpfSample is a simple demonstration of how to get live updates for Instrument Profiles
  • PublishProfiles is a simple demonstration of how to publish market events
  • ScheduleSample is a simple demonstration of how to get various scheduling information for instruments
  • FetchDailyCandles is a simple demonstration of how to fetch last N-days of candles for a specified symbol

Current State

Endpoint Roles

  • FEED connects to the remote data feed provider and is optimized for real-time or delayed data processing, this is a default role

  • STREAM_FEED is similar to Feed and also connects to the remote data feed provider but is designed for bulk data parsing from files

  • PUBLISHER connects to the remote publisher hub (also known as multiplexor) or creates a publisher on the local host (WriteTapeFile)

  • STREAM_PUBLISHER is similar to Publisher and also connects to the remote publisher hub, but is designed for bulk data publishing

  • LOCAL_HUB is a local hub without the ability to establish network connections. Events published via Publisher are delivered to local Feed only

Event Types

  • Order is a snapshot of the full available market depth for a symbol

  • SpreadOrder is a snapshot of the full available market depth for all spreads

  • AnalyticOrder is an Order extension that introduces analytic information, such as adding iceberg-related information to a given order

  • Trade is a snapshot of the price and size of the last trade during regular trading hours and an overall day volume and day turnover

  • TradeETH is a snapshot of the price and size of the last trade during extended trading hours and the extended trading hours day volume and day turnover

  • Candle event with open, high, low, and close prices and other information for a specific period

  • Quote is a snapshot of the best bid and ask prices and other fields that change with each quote

  • Profile is a snapshot that contains the security instrument description

  • Summary is a snapshot of the trading session, including session highs, lows, etc.

  • TimeAndSale represents a trade or other market event with price, such as the open/close price of a market, etc.

  • Greeks is a snapshot of the option price, Black-Scholes volatility, and greeks

  • Series is a snapshot of computed values available for all options series for a given underlying symbol based on options market prices

  • TheoPrice is a snapshot of the theoretical option price computation that is periodically performed by dxPrice model-free computation

  • Underlying is a snapshot of computed values available for an option underlying symbol based on the market’s option prices

  • OptionSale represents a trade or another market event with the price (for example, market open/close price, etc.) for each option symbol listed under the specified Underlying

  • OtcMarketsOrder represents an extension of Order for the symbols traded on the OTC Markets

Subscription Symbols

Subscriptions & Models

IPF & Schedule

About

For Swift developers, this library offers easy access to dxFeed market data. Built upon the GraalVM Native Image and our flagship dxFeed Java API, it provides a seamless experience for Swift-based applications

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages