This repository contains an event-driven api client for the FactSet Trading API
- Java JDK >= 1.8
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>
Add these dependencies to your project's build file:
repositories {
mavenCentral()
}
dependencies {
implementation "com.factset.sdk.eventdriven:factsettrading:2.0.0-SNAPSHOT"
}
To be able to install snapshot releases of the sdk an additional repository must be added to the maven or gradle config.
<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>
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
- Generate OAuth 2.0 authentication credentials.
- Setup Java environment.
- Install and activate Java 1.8+
- Install gradle
- Install dependencies.
- 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();
}
}
Please refer to the contributing guide.
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.
./gradlew publisToMavenLocal
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.