ismailfer / dukascopy-api-websocket

Spring Boot Dukascopy API (Rest API and Websockets) for Market Data feed, Historical Data, Account Data feed and Instruments, and can place orders
16 stars 8 forks source link
algo-trading-strategies algorithms docker dukascopy forex kubernetes market-data-feeds order-book rest-api spring-boot strategy top-of-book websockets

dukascopy-api-websocket

plot

dukas-api is a standalone server application for providing REST/WebSocket access to [Dukascopy][dukascopy-home]'s JForex trading platform.

The official [JForex SDK][dukascopy-wiki] allows the user to use JForex API by programming custom Java applications.

dukas-api server leverages this official SDK and provides REST/WebSocket access for the SDK.

dukas-api-websocket project was inspired by dukas-proxy project that uses Websocket Stomp.

Potential uses of Dukascopy-api

Technology Stack

Getting Started

Account

You can use either a demo account or a real account to connect.

You will need the username and password in order to connect to Dukascopy servers.

Installation

Download the ZIP archive from [releases][github-releases] page, and unarchive into an arbitrary directory on the server.

Configuration

Standard Spring Boot application.properties file

You can configure various properties:

Due to a limitation in spring boot framework with running native websockets (instead of websocket stomp/sockjs); the application will be running on two ports:

RestAPI

Get Historical Data

To get historical bar data:

Params:

timeFrame: 1SEC | 10SEC | 1MIN | 5MIN | 10MIN | 15MIN | 1HOUR | DAILY to (optional) : unix timestamp

[
    {
        "symbol": "EURUSD",
        "open": 1.05137,
        "high": 1.05137,
        "low": 1.05137,
        "close": 1.05137,
        "volume": 0.0,
        "ticks": 0,
        "time": 1655003040000,
        "period": 60
    },
    {
        "symbol": "EURUSD",
        "open": 1.05137,
        "high": 1.05137,
        "low": 1.05137,
        "close": 1.05137,
        "volume": 0.0,
        "ticks": 0,
        "time": 1655003100000,
        "period": 60
    },
    ...
]

Get Position

Params: clientOrderId or dukasOrderID

Open Position

To place a market order; issue a POST request; with the following parameters:

Market Position Example

Order Response for successful placement:

{
    "symbol": "EURUSD",
    "clientOrderID": "ORD_1003",
    "dukasOrderID": "218270954",
    "fillQty": 100000.0,
    "fillPrice": 1.04278,
    "orderSuccess": true
}

Order response for a rejected order:

{
    "symbol": "EURUSD",
    "clientOrderID": "ORD_1003",
    "fillQty": 0.0,
    "fillPrice": 0.0,
    "orderSuccess": false,
    "rejectReason": "Duplicate ClientOrderID: ORD_1003"
}
Limit Order Example

Order Response for successful placement:

{
    "symbol": "EURUSD",
    "clientOrderID": "ORD_1005",
    "dukasOrderID": "218271095",
    "fillQty": 100000.0,
    "fillPrice": 1.03,
    "orderSuccess": true
}

Order response for a rejected order:

{
    "symbol": "EURUSD",
    "clientOrderID": "ORD_1003",
    "fillQty": 0.0,
    "fillPrice": 0.0,
    "orderSuccess": false,
    "rejectReason": "Duplicate ClientOrderID: ORD_1003"
}
Edit Position

Params: clientOrderId or dukasOrderID

Close Position

Params: clientOrderId or dukasOrderID

WebSocket

WebSocket streaming interface can be accessed via standard websocket client

You can either subscribe to topOfBook; or to the full order book:

To subscribe to Top of Book with the configured list of instruments:

To subscribe to Top of Book; with custom list of instruments

To subscribe to Order Book (10 levels) with the configured list of instruments:

To subscribe to Order Book; with custom list of instruments

Top Of Book Payload is a JSON object (application/json)

{
    "symbol": "USD/JPY",
    "bidQty": 1.32,
    "bid": 133.176,
    "ask": 133.185,
    "askQty": 1.2,
    "last": 133.1805,
    "spread": 0.009000000000014552,
    "spreadBps": 0.6757517738494989,
    "updateTime": 1655429612056,
    "updateNumber": 0,
    "depthLevels": 10,
    "live": true
}

Order Book Payload is a JSON object (application/json)

{
    "symbol": "USD/JPY",
    "bidQty": 1.44,
    "bid": 133.307,
    "ask": 133.318,
    "askQty": 1.12,
    "last": 133.3125,
    "spread": 0.011000000000024102,
    "spreadBps": 0.8250948859136876,
    "updateTime": 1655430074627,
    "updateNumber": 0,
    "depthLevels": 10,
    "live": true,
    "bids": [
        {
            "quantity": 1.44,
            "price": 133.307
        },
        {
            "quantity": 3.75,
            "price": 133.304
        },
        {
            "quantity": 4.12,
            "price": 133.301
        },
        {
            "quantity": 1.8,
            "price": 133.299
        },
        {
            "quantity": 1.35,
            "price": 133.298
        },
        {
            "quantity": 1.8,
            "price": 133.296
        },
        {
            "quantity": 1.35,
            "price": 133.291
        },
        {
            "quantity": 3.6,
            "price": 133.29
        },
        {
            "quantity": 0.45,
            "price": 133.285
        },
        {
            "quantity": 8.95,
            "price": 133.262
        }
    ],
    "asks": [
        {
            "quantity": 1.12,
            "price": 133.318
        },
        {
            "quantity": 1.12,
            "price": 133.319
        },
        {
            "quantity": 4.57,
            "price": 133.32
        },
        {
            "quantity": 3.6,
            "price": 133.321
        },
        {
            "quantity": 4.05,
            "price": 133.322
        },
        {
            "quantity": 1.35,
            "price": 133.324
        },
        {
            "quantity": 4.05,
            "price": 133.331
        },
        {
            "quantity": 0.45,
            "price": 133.335
        },
        {
            "quantity": 1.8,
            "price": 133.358
        },
        {
            "quantity": 9.77,
            "price": 133.366
        }
    ]
}

To unsubscribe; just close the connection.

Building from Source

JDK 11 or later is required. Make sure the JAVA_HOME environment variable is configured.

Then Clone the repository, and use maven build to build the archives.

$JAVA_HOME/bin/java -version

git clone git@github.com:ismailfer/dukas-api-websocket.git

cd dukas-api-websocket

mvn clean package

Deployment to Docker / Kubenetes

This application have been dockerized (see Dockerfile).

Docker image:

https://hub.docker.com/r/ismailfer/dukascopy-api

To download docker image:


docker pull ismailfer/dukascopy-api:latest

To run docker image:


docker run --name dukascopy-api -d -p 7080:7080 -p 7081:7081 ismailfer/dukascopy-api:latest

If you want to build a docker image; make sure to update the correct Dukascopy server URL, username and password.

Alternatively you can edit Dockerfile and update the application parameters.

To build a docker image:


docker build --tag dukascopy-api:1.0 .