Skip to content

dxFeed/dxfeed-jni-native-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

light

This package grants you access to dxFeed market data. The library is designed as a С-library and directly invokes our flagship dxFeed Java API using Java Native Interface, making it easily integrable into your projects.

⚠️ It’s an alpha version and still under active development. Don’t use it in a production environment.

Platform License

Table of Contents

Overview

Reasons

Our Java API serves as the cornerstone of our technology, and with our SDK, you can seamlessly integrate it into any language, leveraging it as a native library for all desktop platforms.

Benefits

  • 🚀 Performance almost is same as for our best Java API
  • 🌌 Wider functionality
  • ♊ Identical programming interfaces to our best API
  • 👍 Higher quality of support and service

Implementation details

We use standalone JDK and specially written code that invokes Java methods from native using Java Native Iterface 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 (DxFeedJniNativeSdk.dylib|.so|.dll) 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).

image
  • Required components:
    • preinstalled Java VM 1.8+
    • JAR dependency with:
    • C ABI implementation as dynamic link library (DxFeedJniNativeSdk.dylib|.so|.dll)

Usage (demo)

Code
#include <iostream>
#include <chrono>
#include <thread>

#include "api/dxfg_api.h"

void c_print(graal_isolatethread_t* thread, dxfg_event_type_list* events, void* user_data) {
  for (int i = 0; i < events->size; ++i) {
    dxfg_event_type_t* pEvent = events->elements[i];
    if (pEvent && pEvent->clazz == DXFG_EVENT_QUOTE) {
      const auto* quote = (const dxfg_quote_t*) pEvent;
      printf(
        "C: QUOTE{event_symbol=%s, bid_price=%f, bid_time=%lld, ask_price=%f, ask_time=%lld}\n",
        quote->market_event.event_symbol,
        quote->bid_price,
        quote->bid_time,
        quote->ask_price,
        quote->ask_time);
    }
  }
}

int main() {
  const auto address = "demo.dxfeed.com:7300";
  const auto symbol = "AAPL";

  auto thread = create_thread();
  if (thread != nullptr) {
    // Create endpoint and connect to specified address.
    dxfg_endpoint_t* endpoint = dxfg_DXEndpoint_create(thread);
    dxfg_DXEndpoint_connect(thread, endpoint, address);

    // Create feed and subscription with specified types attached to feed.
    dxfg_feed_t* feed = dxfg_DXEndpoint_getFeed(thread, endpoint);
    dxfg_subscription_t* subscription = dxfg_DXFeed_createSubscription(thread, feed, DXFG_EVENT_QUOTE);

    // Adds event listener.
    dxfg_feed_event_listener_t* listener = dxfg_DXFeedEventListener_new(thread, &c_print, nullptr);
    dxfg_DXFeedSubscription_addEventListener(thread, subscription, listener);

    // Create STRING symbol.
    dxfg_string_symbol_t stringSymbol;
    stringSymbol.supper.type = STRING;
    stringSymbol.symbol = symbol;

    // Add symbol to subscription.
    dxfg_DXFeedSubscription_setSymbol(thread, subscription, &stringSymbol.supper);

    // Sleep 10 seconds waiting for the response about Quotes.
    std::chrono::seconds seconds(10);
    std::this_thread::sleep_for(seconds);

    // Close subscription and clear resources.
    dxfg_DXFeedSubscription_close(thread, subscription);
    dxfg_DXEndpoint_close(thread, endpoint);
    dxfg_JavaObjectHandler_release(thread, &listener->handler);
    dxfg_JavaObjectHandler_release(thread, &subscription->handler);
    dxfg_JavaObjectHandler_release(thread, &endpoint->handler);
}

Installation

Build JAR dependency

  • artifact src/c/main/demo/build/dxfeed-jni-native-sdk-0.1.0.jar
$ git clone https://github.com/dxFeed/dxfeed-jni-native-sdk.git
$ cd dxfeed-jni-native-sdk
$ mvn clean package

Build Native dependency

Unix systems

  • artifact src/c/main/jni-lib/build/DxFeedJniNativeSdk.dylib|.so
$ cd src/main/c/jni-lib
$ sh build_release.sh

Windows x64

  • artifact src/c/main/jni-lib/build/DxFeedJniNativeSdk.dll
$ cd src\main\c\jni-lib
$ build_release.cmd

Build Demo with Native dependency

Unix systems

  • artifact src/c/main/demo/build/dxfeed-jni-native-sdk-0.1.0.jar
  • artifact src/c/main/demo/build/DxFeedJniNativeSdk.dylib|.so
  • artifact src/c/main/demo/build/DxFeedDemo
$ cd src/main/c
$ sh build_demo_release.sh
$ cd demo/build
$ ./DxFeedDemo demo.dxfeed.com:7300 AAPL

Windows x64

  • artifact src\c\main\demo\build\dxfeed-jni-native-sdk-0.1.0.jar
  • artifact src\c\main\demo\build\DxFeedJniNativeSdk.dll
  • artifact src\c\main\demo\build\DxFeedDemo.exe
$ cd src\main\c
$ build_demo_release.cmd
$ cd demo\build
$ DxFeedDemo.exe demo.dxfeed.com:7300 AAPL

Documentation

Find useful information in our self-service dxFeed Knowledge Base:

Samples

  • Demo is a sample demontration (linked with DxFeedJniNativeSdk) how to connect to address, add event listener and subscribe to Quote event
  • DxFeedConnect is a sample demontration how to connect to use console args to connect address and subscribe to Quote event
  • 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, using a DxFeed instance singleton and dxfeed.properties file
  • 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
  • DxFeedPublishProfiles is a simple demonstration of how to publish market events
  • ScheduleSample is a simple demonstration of how to get various scheduling information for instruments

How to build a sample

  • build JAR dependency -> src/c/main/demo/build/dxfeed-jni-native-sdk-0.1.0.jar
  • build native dependency -> src/c/main/demo/build/DxFeedJniNativeSdk.dylib|.so|.dll
  • copy to ${SAMPLE_DIR}/build files
    • dxfeed-jni-native-sdk-0.1.0.jar
    • DxFeedJniNativeSdk.dylib|.so|.dll
  • cd ${SAMPLE_DIR}
  • run script sh build_release.sh or build_release.cmd
    • or open CMakeLists.txt as project and build from IDE

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 (.NET API sample)

  • STREAM_FEED is similar to Feed and also connects to the remote data feed provider but is designed for bulk data parsing from files (.NET API sample)

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

  • STREAM_PUBLISHER is similar to Publisher and also connects to the remote publisher hub, but is designed for bulk data publishing (.NET API sample)

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

  • ON_DEMAND_FEED is similar to Feed, but it is designed to be used with OnDemandService for historical data replay 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

  • Configuration is an event with an application-specific attachment

  • Message is an event with an application-specific attachment

Subscription Symbols

Subscriptions & Models

IPF & Schedule

Services