Developer Guides

Draft 0.5

Services

Back-End consists of a collection of small, autonomous microservices. Each service is self-contained and implements a single business capability within a bounded context. A bounded context is a natural division within a business and provides an explicit boundary within which a domain model exists:

Service "balances"

This service, upon startup or reboot, reads the contents of ledger records and for all users registered in the system will build a structure of balances in memory. This is done by balances.loadBalances. The process of building the structure of balances in memory can take a significant amount of time (up to an hour and a half for 54,000 users). This does not affect system performance in any way, as there is "out of order lazy loading" of the balance for a given user using balances.loadUserBalances.
See also Developer Guides | Subscription userBalanceUpdated

Service "operations"

Subscription userBalanceUpdated

This subscription allows user to receive information about the current state of the following accounts in subscription mode:

balance: [account #201], field name in Admin panel: Balance
advancedTradingBalance: [account #202], field name in Admin panel: Trading Balance
advancedTradingLockedBalance: [account #203], field name in Admin panel: Trading Locked Balance
lockedBalance: [account #204], field name in Admin panel: Locked Balance

Admin panel:

Command:

subscription { userBalanceUpdated( token: "eyJhbG...lxA" ) { currencyId balance advancedTradingBalance advancedTradingLockedBalance lockedBalance ts } }

Response example:

{
"data": {
"userBalanceUpdated": {
"currencyId": "DEV2",
"balance": 0,
"advancedTradingBalance": 92.0168,
"advancedTradingLockedBalance": 7.9832,
"lockedBalance": 0,
"ts": "1681292864617"
}
}
}

Checking command execution results in Docker logs:

docker-compose logs -f --tail 100 operations

View command execution in graphql playground:

Note for developers. This subscription returns account status data from the following services
(tag: "USER_BALANCE_UPDATED"):

balances.service: debit
balances.service: credit
balances.service: debitCredit
custodianOperations.service: sendUserBalanceUpdated
The list of actions, their parameters and used types of data structures can be found in the graphql playground “DOCS” tab.

See also Developer Guides | Service "balances"

Service "trading"

Trading service is an online trading platform - selling one currency to buy another. It implements the process of changing one cryptocurrency into another and allows customers/investors to manage their own orders online: open (openOrder), cancel(cancelOrder) etc . An order is the fundamental trading unit of a market. When a customer has decided to buy or sell an asset, an order is initiated. Orders broadly fall into two different categories, which allow customers to place restrictions on their orders affecting the price and time at which the order can be executed. The two major types of orders that every customer should know are the market order and the limit order. So here are some basic order types: limit (conditional) order and market order. The limit order dictates a particular price level (limit) at which the order must be executed. A limit order specifies a certain price at which the order must be filled, although there is no guarantee that some or all of the order will trade if the limit is set too high or low. A limit order (pending order) allows customers to buy and sell cryptocurrencies at a certain price in the future. In effect, a limit order sets the amount and the minimum price at which customer is willing to buy or sell. A market order instructs the service to complete the order at the best available price. A market order simply buys (or sells) cryptocurrencies at the prevailing market prices until the order is filled. A market order is an order to buy or sell immediately at the current price. Market order is always opened & executed unless there is no trading liquidity. The trading service allows customer to trade on various markets created in the system. A market is cryptocurrency pair e.g. BTC-USDT. The first listed cryptocurrency of a currency pair is called the base currency, and the second currency is called the quote currency. When an order is placed, the first listed currency or base currency is bought while the second listed currency in a currency pair or quote currency is sold.
There are two types of limit orders. Buy Limit Order is an order to purchase a currency at or below a specified price. Sell Limit Order is an order to sell a currency at or above a specified price. Also there are two types of market orders. Buy Market Order is an order to purchase a currency immediately at the current price. Sell Market Order is an order to sell a currency immediately at the current price.

Mutation openOrder

mutation { mut1: openOrder( market: "C1-C2" type: "limit" side: "sell" amount: 0.2 price: 2 ) { id status } mut2: openOrder( market: "C1-C2" type: "market" side: "buy" amount: 0.1 ) { id status } }

Subscription marketDynamics

Command:

subscription { marketDynamics(market: "C1-C2") { startPrice amount24h lastPrice } }

Response example:

{
"data": {
"marketDynamics": {
"startPrice": 2.9863,
"amount24h": 176.301,
"lastPrice": 2.9842
}
}
}

Subscription marketRate

Command:

Response example:

{
"data": {
"marketRate": {
"market": "C1-C2",
"spread": null,
"rate": 3,
"ts": "1682074648297"
}
}
}

Query publicOrderBook

The Order book refers to an electronic list of buy and sell orders for a specific cryptocurrency organised by price level. It helps traders make more informed trading decisions. An order book lists the number of shares being bid on or offered at each price point, or market depth. It does not identifies the market participants behind the buy and sell orders to give a possibility for traders to remain anonymous. These lists help traders and also improve market transparency because they provide valuable trading information. There are two parts to an order book: buy orders, sell orders. An order book is dynamic, meaning it's constantly updated in real-time throughout the day (permanently). The order book is accompanied by a candlestick chart, which provides useful information about the current and past state of the market.

Command:

Response example:

{
"data": {
"publicOrderBook": {
"buy": [
{
"price": 2.989,
"amount": 0.136,
"cumulativeAmount": 0.136
},
{
"price": 2.9878,
"amount": 0.158,
"cumulativeAmount": 0.294
},
{
"price": 2.9819,
"amount": 0.065,
"cumulativeAmount": 0.359
},
{
"price": 2.9684,
"amount": 0.191,
"cumulativeAmount": 0.55
},
{
"price": 2.9562,
"amount": 0.187,
"cumulativeAmount": 0.737
}
],
"sell": [
{
"price": 2.9902,
"amount": 0.15,
"cumulativeAmount": 0.15
},
{
"price": 2.9954,
"amount": 0.186,
"cumulativeAmount": 0.336
},
{
"price": 2.9979,
"amount": 0.152,
"cumulativeAmount": 0.488
},
{
"price": 2.9997,
"amount": 0.137,
"cumulativeAmount": 0.625
}
]
}
}
}

Subscription publicTrades

Command:

Response example:

{
"data": {
"publicTrades": {
"id": "5f41ea08-24da-4c28-8cc8-00092ef0cba1",
"price": 2.981,
"amount": 0.085
}
}
}

Service "tradingView"

This service generates data for Candlestick charts. Candlestick charts display the high, low, open, and closing prices of a cryptocurrency for a specific period. A candlestick is a type of price chart used in technical analysis that displays the high, low, open, and closing prices of a cryptocurrency for a specific period. The wide part of the candlestick is called the "real body" and tells customers whether the closing price was higher or lower than the opening price (black/red if the cryptocurrency closed lower, white/green if the cryptocurrency closed higher). Candlesticks can be used by traders looking for chart patterns.

To be continued…