Order Operations
TrexWallet includes a built-in P2P exchange with order book, private exchange rooms and an instant swap. Users can trade currencies directly with each other without external exchanges.
Order Types
Selection is driven by the isLimit and postOnly flags on the order request:
isLimit | postOnly | Resulting type | Behavior |
|---|---|---|---|
true | false | Limit | Execute at limit price or better; rest goes to the book |
true | true | LimitOnly | Post-only — rejected if it would immediately match |
false | — | Market | Execute immediately at best available price |
Internal/system order types (FastLimit, LockLimit, ExternalMarket, ExternalLimit, MarketLong) are not exposed via the public order creation API; they are produced by the market engine and external execution layer.
Order States (OrderEnumState)
| State | Value | Description |
|---|---|---|
Active | 1 | Order is in the book / waiting for execution |
Completed | 198 | Fully matched (logical completion) |
Canceled | 199 | Cancelled by user or system |
Finished | 200 | Settled (external orders posted to balance) |
Failed | 255 | Processing error |
ChangePriceTo (20), ExternalExecute (127), RequestInfo (210), PartialUnlock (211) are engine action codes, not terminal user states.
API Endpoints
Create Order
POST /trex/v1/market/create_order
{
"fromCurrency": "BTC",
"toCurrency": "USDT",
"fromAmount": "0.46346",
"toAmount": "23646.475",
"clientNonce": "24529041564",
"isLimit": true,
"postOnly": false,
"roomKey": "0",
"tag": null
}
fromAmount/toAmountare decimal strings (preserve precision). For market orderstoAmountmay be omitted.clientNoncemust be a fresh int64 (e.g. milliseconds) per request — used for idempotency.roomKey = "0"targets the public room.- A wallet may hold at most
MaxActiveOrdersPerWalletopen orders (default 50); exceeding it returnsMaxActiveOrdersExceeded(10094).
Cancel Order
POST /trex/v1/market/cancel_order?id=<orderTimetick>
id is the order's timetick. Cancellation returns the locked source amount to free_balance.
Get Orders
GET /trex/v1/market/get_orders
?currency_from=BTC
¤cy_to=USDT
&room_key=0
&start=2026-01-01
&end=2026-05-01
&from_order_id=<timetick>
&limit=10
&ord_states=Active&ord_states=Completed
All filters are optional. Default window is the last 90 days; limit is capped at 100.
Get Trade Info
GET /trex/v1/market/get_trade_info?currency_from=BTC¤cy_to=USDT&room_key=0&results_limit=20
Returns the aggregated order book (asks/bids grouped by price level), current rates, and fee information.
Order Matching
Orders are matched by price level:
- New order arrives via
create_order. - The engine finds matching orders at the target price or better.
- Matches are settled atomically.
- Partial fills leave the remainder as an open order at the same price level.
- Fees are applied per the tariff matched to each side.
A match produces one transaction for each participant using the ExchangeToBroker and
ExchangeFromBroker transaction types. See
Transaction States.
Exchange Rooms
Rooms provide isolated trading environments with custom rules.
Public Room (roomKey = "0")
The default exchange room. Open to all users. All standard orders go here unless an explicit roomKey is supplied.
Private Rooms
Users can create private exchange rooms. A creator may have up to 5 rooms.
POST /trex/v1/market/create_room
{
"currency1": "BTC",
"currency2": "USDT",
"flags": 0,
"toBalanceLimit": "100000000000"
}
| Field | Notes |
|---|---|
currency1 / currency2 | Currency codes the room trades |
flags | RoomFlags bitfield: None = 0, IcoMode = 1 |
toBalanceLimit | Destination-balance cap (currently persisted only; not enforced at order matching yet) |
Joining a room is done through /trex/v1/apply_code using the share code returned in list_rooms to the room's creator.
Room Management
# List rooms the wallet participates in
GET /trex/v1/market/list_rooms
# Close (delete) a private room — owner only
POST /trex/v1/market/close_room?roomId=<roomKey>
Instant Swap
Swap is an atomic exchange at the current market rate, without participating in the order book. It is a separate two-step endpoint (preview + confirm) and uses the same NewOrderInfo payload as orders.
POST /trex/v1/market/create_swap?confirmationTimetick=<txId>&confirmationCode=<code>
{
"fromCurrency": "BTC",
"toCurrency": "USDT",
"fromAmount": "0.01",
"toAmount": "650.0",
"clientNonce": "...",
"isLimit": false,
"postOnly": false,
"roomKey": "0"
}
- First call (no query params) returns a confirmation payload (
txId,fee,confirmationStatusCode) and may also return the OTP code in the response when no second channel is configured. - Second call with both
confirmationTimetick(thetxIdfrom step one) andconfirmationCodeexecutes the atomic swap. toAmountis required for a swap (unlikecreate_order, where it is optional); omitting it returnsInvalidAmount(10014). It is the net receive amount after fee as confirmed by the user; the server recalculates settlement amount and fee from the tariff and rejects if drift is too large.
Swap Info
GET /trex/v1/market/swap_info?currency_from=BTC¤cy_to=USDT
Returns the current rate, min/max amounts, fees, and limits.
Rates
Sources
Rate aggregation is provided through GET /markets/v1/get_rates; TrexWallet exposes the public
get_rates endpoint below for wallet clients. The rate provider and source configuration are
deployment concerns.
The list of polled exchanges is documented once in Market Making.
Rate Calculation
1. Direct rate (if available): BTC/USDT
2. Cross-rate via USDT: BTC/USDT × USDT/EUR
3. Cross-rate via BTC: token/BTC × BTC/USDT
Get Rates
GET /trex/v1/market/get_rates?to=USDT
# optionally restrict the source list:
GET /trex/v1/market/get_rates?to=USDT&from=BTC&from=ETH
to is the target currency (default EUR). from is an optional list of source
currencies; if omitted, rates for all available currencies are returned.
ChargeBack Protection
When enabled, swaps check the age of incoming funds:
- Funds received less than N days ago are restricted from outbound swap usage.
- Prevents users from swapping freshly deposited funds that might be reversed.
- Configurable through the
ChargeBackDaysoperator setting.