Trade data & service

Classes to manage trade information and creates order.

Data.

Trade package class diagram

OrderCreationResultDTO.

OrderCreationResultDTO is returned after an order is created. It contains either the order id or the error message.

Field

Description

orderId

Order ID (filled if order creation is successful).

errorMessage

Error message (filled if order creation failed).

exception

Exception (filled if order creation failed).

successful

Indicates if the position creation was successful or not.

OrderDTO.

OrderDTO represents order information from the exchange. A market order is a request by an investor to buy or sell in the current market.

Field

Description

type

Order type i.e. bid or ask.

originalAmount

Amount to be ordered / amount that was ordered.

currencyPair

The currency pair.

id

An identifier set by the exchange that uniquely identifies the order.

userReference

An identifier provided by the user on placement that uniquely identifies the order.

timestamp

The timestamp on the order according to the exchange’s server, null if not provided.

status

Status of order during it lifecycle.

cumulativeAmount

Amount to be ordered / amount that has been matched against order on the order book/filled.

averagePrice

Weighted Average price of the fills in the order.

fee

The total of the fees incurred for all transactions related to this order.

leverage

The leverage to use for margin related to this order.

limitPrice

The limit price.

OrderTypeDTO.

OrderTypeDTO describes the different types of orders.

Field

Description

BID

Buying order.

ASK

Selling order.

OrderStatusDTO.

OrderStatusDTO describes the different status of an order.

Field

Description

PENDING_NEW

Initial order when instantiated.

NEW

Initial order when placed on the order book at exchange.

PARTIALLY_FILLED

Partially match against opposite order on order book at exchange.

FILLED

Fully match against opposite order on order book at exchange.

PENDING_CANCEL

Waiting to be removed from order book at exchange.

PARTIALLY_CANCELED

Order was partially canceled at exchange.

CANCELED

Removed from order book at exchange.

PENDING_REPLACE

Waiting to be replaced by another order on order book at exchange.

REPLACED

Order has been replace by another order on order book at exchange.

STOPPED

Order has been triggered at stop price.

REJECTED

Order has been rejected by exchange and not place on order book.

EXPIRED

Order has expired it’s time to live or trading session and been removed from order book.

UNKNOWN

The exchange returned a state which is not in the exchange’s API documentation. The state of the order cannot be confirmed.

TradeDTO.

TradeDTO is the action of buying and selling goods and services

Field

Description

id

An identifier set by the exchange that uniquely identifies the trade.

orderId

The id of the order responsible for execution of this trade.

type

A bid or a ask.

originalAmount

Amount to be ordered / amount that was ordered.

currencyPair

The currency-pair.

price

The price.

timestamp

The timestamp on the order according to the exchange's server, null if not provided.

fee

The fee that was charged by the exchange for this trade.

Service.

Trade service.

Trade service and its XChange implementation :

Method

Description

createBuyMarketOrder()

Creates a buy market order.

createSellMarketOrder()

Creates a sell market order.

createBuyLimitOrder()

Creates a buy limit order.

createSellLimitOrder()

Creates a sell limit order.

getOpenOrderByOrderId()

Get an open order by its id.

getOpenOrders()

Get open orders.

cancelOrder()

Cancel order.

getTrades()

Get last week trades.

restoreTrade()

Used by Cassandre to restore trades after restart

backupTrade()

Used by Cassandre to backup trades to database

There is also a dry mode implementation.