Skip to content

Commit

Permalink
Merge pull request #110 from CoreumFoundation/update_dex_api_docs
Browse files Browse the repository at this point in the history
Update CoreDEX API docs
  • Loading branch information
alinetskyi authored Mar 3, 2025
2 parents 3bed68c + cd8040c commit 7185a48
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 51 deletions.
54 changes: 32 additions & 22 deletions app/docs/core_dex/api-server/overview/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Params:
- `from` _required_ - unix timestamp of trades start
- `to` _required_ - unix timestamp of trades end
- `account` _optional_ - account address for which trades should be returned
- `side` _optional_ - side of the trade (1 - buy, 2 - sell (see enum domain/order-properties))

Returns:

Expand Down Expand Up @@ -156,6 +157,8 @@ Returns:
}
```

For retrieving the exchange history, the dev should only retrieve one `side`: If both sides are retrieved the list contains duplicates (party and counter party) of the trades, which would be confusing the end users.

#### tickers

The tickers endpoint returns the latest price for all trading pairs.
Expand Down Expand Up @@ -298,7 +301,7 @@ Below is a matrix of possible values for the order object before it can be succe
| **timeInForce** | TIME_IN_FORCE_GTC (1) | |
| | TIME_IN_FORCE_IOC (2) | TIME_IN_FORCE_IOC (2) |
| | TIME_IN_FORCE_FOK (3) | |
| **goodTil** | `{goodTilBlockTime: Date Object, goodTilBlockHeight: 0}` or undefined | undefined |
| **goodTil** | \{goodTilBlockTime: Date Object, goodTilBlockHeight: 0\} or undefined | undefined |
| **baseDenom** | string (denomName-issuer eg. udevcore) | string (denomName-issuer eg. udevcore) |
| **quoteDenom** | string (denomName-issuer eg. udevcore) | string (denomName-issuer eg. udevcore) |
| **quantity** | string (eg. 10000) | string (eg. 10000) |
Expand Down Expand Up @@ -351,6 +354,7 @@ Example response:
"good_til": {
"good_til_block_time": "2025-12-30T12:00:00Z"
}
}
```

In which the TXBytes is the base64 encoded transaction that needs to be signed and submitted to the blockchain.
Expand Down Expand Up @@ -421,29 +425,35 @@ Sample return:
```json5
{
Buy: [
"Buy": [
{
Price: "3140",
HumanReadablePrice: "3140",
Amount: "2272",
SymbolAmount: "0.002272",
Sequence: 41567,
OrderID: "8b341e25-482e-487f-b9e2-9467d98c16ac",
"Price": "3140",
"HumanReadablePrice": "3140",
"Amount": "2272",
"SymbolAmount": "0.002272",
"Sequence": 41567,
"OrderID": "8b341e25-482e-487f-b9e2-9467d98c16ac",
"RemainingAmount": "2272",
"RemainingSymbolAmount": "0.002272",
},
],
Sell: [
"Sell": [
{
Price: "3360",
HumanReadablePrice: "3360",
Amount: "2071",
SymbolAmount: "0.002071",
Sequence: 41760,
OrderID: "8b341e25-482e-487f-b9e2-9467d98c16ac",
"Price": "3360",
"HumanReadablePrice": "3360",
"Amount": "2071",
"SymbolAmount": "0.002071",
"Sequence": 41760,
"OrderID": "8b341e25-482e-487f-b9e2-9467d98c16ac",
"RemainingAmount": "2071",
"RemainingSymbolAmount": "0.002071",
},
],
}
```
where a frontend could display `(SymbolAmount-RemainingSymbolAmount)/SymbolAmount` as an indicator of progress of the order.
#### /wallet/assets
Returns the assets for a certain account.
Expand All @@ -457,14 +467,14 @@ Sample return:
```json5
[
{
Denom: "dextestdenom0-devcore1p0edzyzpazpt68vdrjy20c42lvwsjpvfzahygs",
Amount: "1000000000000",
SymbolAmount: "1000.0000",
"Denom": "dextestdenom0-devcore1p0edzyzpazpt68vdrjy20c42lvwsjpvfzahygs",
"Amount": "1000000000000",
"SymbolAmount": "1000.0000",
},
{
Denom: "dextestdenom1-devcore1p0edzyzpazpt68vdrjy20c42lvwsjpvfzahygs",
Amount: "1000000000000",
SymbolAmount: "1000.0000",
"Denom": "dextestdenom1-devcore1p0edzyzpazpt68vdrjy20c42lvwsjpvfzahygs",
"Amount": "1000000000000",
"SymbolAmount": "1000.0000",
},
//...
]
Expand All @@ -481,7 +491,7 @@ curl -H "Network: devnet" \
The update service uses a websocket for a subscription system in which the user subscribes to certain information.
See the <a href="/docs/core_dex/api-server/update-service" target="_blank" className="text-[#25D695] hover:opacity-80 text-base font-bold">Update service</a> for extensive information.
See the [README-update-service.md](README-update-service.md) for extensive information.
## Application start parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Update service
# update service

The update service provides a websocket which refreshes the data based on actual changes. The use of the websocket reduces the numbers of reads required to produce the same data to the connected clients, thus lowering database load and related costs.

Expand Down
60 changes: 37 additions & 23 deletions app/docs/core_dex/frontend/frontend.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,44 +41,58 @@ The websocket manager takes care of data handling and manages its own state.

You may choose to create a wrapper like a React hook for the websocket manager in your project. But below is an example of how you would connect and subscribe using only the websocket manager:

// TODO update examples after refactoring websocket

```
import { useEffect } from 'react';
import useWebSocketStore from './websocketStore';
const TestOrderBook: React.FC = () => {
const { isConnected, messages, connect, subscribe } = useWebSocketStore();
// memoize callback and subscription to prevent unnecessary subscriptions/unsubscriptions
const handleOrderbookUpdate = useCallback(
(message: WebSocketMessage) => {
setOrderbook(message.Subscription?.Content);
},
[setOrderbook]
);

const subscription = useMemo(
```
import { useEffect, useMemo } from 'react';
import {
Method,
NetworkToEnum,
UpdateStrategy,
wsManager,
} from "@/services/websocket";
const Test: React.FC = () => {
const walletSubscription = useMemo(
() => ({
Network: Network.DEVNET,
Method: Method.ORDERBOOK,
ID: market.pair_symbol,
Network: NetworkToEnum(network),
Method: Method.WALLET,
ID: `${wallet ? wallet.address : ""}`,
}),
[market.pair_symbol]
[market.pair_symbol, wallet]
);
useWebSocket(subscription, handleOrderbookUpdate);
const handleWalletUpdate = (message: WalletBalances) => {
if (message.length > 0) {
setWalletBalances(message);
}
};
useEffect(() => {
wsManager.connected().then(() => {
wsManager.subscribe(
walletSubscription,
handleWalletUpdate,
UpdateStrategy.REPLACE
);
});
return () => {
wsManager.unsubscribe(walletSubscription, setWalletBalances);
};
}, [walletSubscription]);
return (
<div>
...
</div>
);
};
export default TestOrderBook;
export default Test;
```

- you can pass a custom handler function or just a setter. The above example uses `handleWalletUpdate`
- there are a few basic update strategies like replace, merge, etc that describe how data should be added to the ws state (append, replace, etc)

## API

This project also handles all backend API calls in `services/api.ts` and can be ported to your project as well.
Expand Down
8 changes: 4 additions & 4 deletions app/docs/core_dex/overview/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ A set of single instances is expected to be able to handle 1000s of parallel req
To support deployment on cloud services, there are 4 docker files in the root of the project. These can be used to build the docker images for the components.

```bash
docker build -t api-server -f Dockerfile.api-server .
docker build -t data-aggregator -f Dockerfile.data-aggregator .
docker build -t store -f Dockerfile.store .
docker build -t frontend -f Dockerfile.frontend .
docker build -t coreumfoundation/api-server:latest -f Dockerfile.api-server .
docker build -t coreumfoundation/data-aggregator:latest -f Dockerfile.data-aggregator .
docker build -t coreumfoundation/store:latest -f Dockerfile.store .
docker build -t coreumfoundation/frontend:latest -f Dockerfile.frontend .
```

There are also sample deployment files for Kubernetes in the `apps/kubernetes` directory.
Expand Down
2 changes: 1 addition & 1 deletion app/docs/core_dex/store/store.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ All tables, indexes, and foreign keys will be created by the store itself on fir

- `MYSQL_CONFIG` - See utils/mysqlstore for connection description
- `LOG_LEVEL` (optional) - Set the log level to one of the following values: `debug`, `info`, `warn`, `error`
- `GRPC_PORT` - Format `:{port number}`. Port the grpc server will listen on
- `GRPC_PORT` - Format `:{port number}`. Port the grpc server will listen on

0 comments on commit 7185a48

Please sign in to comment.