Skip to content

Latest commit

 

History

History
200 lines (149 loc) · 6.06 KB

File metadata and controls

200 lines (149 loc) · 6.06 KB

FactSet

FactSet Trading event-driven client library for Java

Maven Central

Apache-2 license

This repository contains an event-driven api client for the FactSet Trading API

Requirements

  • Java JDK >= 1.8

Installation

Maven

Add the below dependency to the project's POM:

<dependency>
    <groupId>com.factset.sdk.eventdriven</groupId>
    <artifactId>factsettrading</artifactId>
    <version>2.0.0-SNAPSHOT</version>
</dependency>

Gradle

Add these dependencies to your project's build file:

repositories {
    mavenCentral()
}

dependencies {
    implementation "com.factset.sdk.eventdriven:factsettrading:2.0.0-SNAPSHOT"
}

Snapshot Releases

To be able to install snapshot releases of the sdk an additional repository must be added to the maven or gradle config.

Maven Snapshot Repository

<repositories>
    <repository>
        <id>sonatype</id>
        <name>sonatype-snapshot</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>false</enabled>
        </releases>
    </repository>
</repositories>

Gradle Snapshot Repository

repositories {
    mavenCentral()
    maven {
        url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
        mavenContent {
            snapshotsOnly()
        }
    }
}

Snapshot releases are cached by gradle for some time, for details see: Gradle Dynamic Versions

Usage

  1. Generate OAuth 2.0 authentication credentials.
  2. Setup Java environment.
    1. Install and activate Java 1.8+
    2. Install gradle
  3. Install dependencies.
  4. Run the following code:
package com.factset.sdk.console;

import com.factset.sdk.eventdriven.factsettrading.OrderUpdateApi;
import com.factset.sdk.eventdriven.factsettrading.model.OrderSubscriptionRequest;
import com.factset.sdk.utils.authentication.ConfidentialClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.util.Collections;
import java.util.List;

public class Console {

    private static final Logger logger = LoggerFactory.getLogger("main");

    public static void main(String[] args) throws Exception {
        ConfidentialClient confidentialClient = new ConfidentialClient("/path/to/config/file");

        // initialize the websocket client
        WebsocketApiClient client = new WebsocketApiClient(
                WebsocketApiClient.Options.builder()
                        .url("https://api.factset.com/streaming/trading/ems/v0")
                        .authorizer(confidentialClient)
                        .maximumIdleInterval(Duration.ofSeconds(30))
                        .build()
        ).connectAsync().join();

        // initialize the order update api
        OrderUpdateApi api = new OrderUpdateApi(client);

        // subscribe to order updates
        OrderSubscriptionRequest.Subscribe subscribe = OrderSubscriptionRequest.Subscribe.builder()
                .inboundOrders(true)
                .parentOrders(true)
                .childOrders(true)
                .inboundMessages(true)
                .childMessages(true)
                .build();
        OrderSubscriptionRequest request = new OrderSubscriptionRequest(subscribe);

        Subscription subscription = api.subscribeOrderUpdates(request)
                .onSnapshotEvent((snapshotEvent) -> {
                    // clients logic of handling the snapshotEvent message goes here
                    logger.info(snapshotEvent.toString());
                })
                .onTradeEvent((tradeEvent) -> {
                    // clients logic of handling the tradeEvent message goes here
                    logger.info(tradeEvent.toString());
                })
                .onError((exception) -> {
                    logger.error(exception.toString());
                })
                .subscribe()
                .join();

        // wait
        Thread.sleep(10000);

        // cancel the subscription
        subscription.cancel();

        // close the websocket connection
        client.disconnectAsync().join();
    }
}

Contributing

Please refer to the contributing guide.

Logging

All logger names start with "com.factset".

This library uses SLF4J as logging interface, which requires a binding to your logging framework on the classpath.

If no binding is found, SLF4J prints out the following warning and then defaults to a no-operation implementation, which discard all logs:

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.

Installation into local maven repo

./gradlew publisToMavenLocal

Copyright

Copyright 2023 FactSet Research Systems Inc

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.