command module
Version: v0.0.0-...-5ae7496 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2020 License: MIT Imports: 1 Imported by: 0


ODEX Backend

Chat on discord License Contributions welcome

The ODEX Decentralized Exchange

The ODEX decentralized exchange is a hybrid decentralized exchange that aims at bringing together the ease of use of centralized exchanges along with the security and privacy features of decentralized exchanges. Orders are matched through an off-chain orderbook. After orders are matched and signed, the decentralized exchange operator has the sole ability to perform a transaction to the AA. This provides for the best UX as the exchange operator is the only party having to interact directly with the blockchain. Exchange users simply sign orders which are broadcasted then to the orderbook. This design enables users to queue and cancel their orders seamlessly.

Several matchers can operate exchanges based on ODEX technology at the same time. They share their orderbooks and exchange all new orders among themselves, thus improving liquidity for all ODEX exchanges. An order can be submitted through any ODEX exchange, however to be matched, both maker and taker orders have to indicate the same matcher. The exchange that was used to submit the order serves as an affliate and can charge a fee from its users. Anyone can become a matcher or affiliate, or just watch the orders that are being exchanged among the matchers and detect any possible misbehavior by matchers.

Getting Started



go get github.com/byteball/odex-backend


You don't run the backend directly. Run ODEX wallet and it will launch the backend automatically.

API Endpoints


  • GET /tokens : returns list of all the tokens from the database
  • GET /tokens/<asset>: returns details of a token from db using token's asset ID
  • POST /tokens: Create/Insert token in DB. Sample input:


  • GET /pairs : returns list of all the pairs from the database
  • GET /pairs/<baseToken>/<quoteToken>: returns details of a pair from db using using asset IDs of its constituting tokens
  • GET /pairs/book/<pairName>: Returns orderbook for the pair using pair name
  • POST /pairs/create: Create/Insert pair in DB. Sample input:


  • POST /account/create?address=<addr>: Create/Insert address and corresponding balance entry in DB.


  • GET /account/balances/<addr>: Fetch the balance details from db of the given address.


  • GET /orders?address=<addr>: Fetch all the orders placed by the given address


  • GET /trades/history/<pair>: Fetch complete trade history of given pair using pair name
  • GET /trades?address=<addr>: Fetch all the trades in which the given address is either maker or taker
  • GET /trades/ticks: Fetch ohlcv data. Query Params:
// Query Params for /trades/ticks
pairName: names of pair separated by comma(,) ex: "hpc/aut,abc/xyz". (At least 1 Required)
unit: sec,min,hour,day,week,month,yr. (default:hour)
duration: in int. (default: 24)
from: unix timestamp of from time.(default: start of timestamp)
to: unix timestamp of to time. (default: current timestamp)



Orders contain the information that is required to register an order in the orderbook as a "Maker".

  • id is the primary ID of the order (possibly deprecated)
  • orderType is either BUY or SELL. It is currently not parsed by the server and compute directly from tokenBuy, tokenSell, amountBuy, amountSell
  • exchangeAddress is the exchange AA address
  • maker is the maker (usually sender) Obyte address
  • tokenBuy is the BUY token asset ID
  • tokenSell is the SELL token asset ID
  • amountBuy is the BUY amount (in BUY_TOKEN units)
  • amountSell is the SELL amount (in SELL_TOKEN units)
  • expires is the order expiration timestamp
  • nonce is a random string or number to make sure order hashes are unique even if all other parameters are identical
  • pairID is a hash of the corresponding
  • hash is a hash of the order details (see details below)
  • signature is a signature of the order hash. The signer must equal to the maker address for the order to be valid.
  • price corresponds to the pricepoint computed by the matching engine (not parsed)
  • amount corresponds to the amount computed by the matching engine (not parsed)

Order Price and Amount

There are two ways to describe the amount of tokens being bought/sold. The AA requires (sell_asset, buy_asset, sell_amount, price) while the orderbook requires (pairID, amount, price).

The conversion between both systems can be found in the engine.ComputeOrderPrice function

Order Hash

The order hash is a sha-256 hash of the following elements:

  • Exchange address
  • Token Buy asset ID
  • Amount Buy
  • Token Sell asset ID
  • Amount Sell
  • Nonce
  • User Address


  • orderHash is the hash of the matching order
  • amount is the amount of tokens that will be traded
  • taker is the taker Obyte address
  • pairID is a hash identifying the token pair that will be traded
  • hash is a unique identifier hash of the trade details (see details below)

Trade Hash:

The trade hash is a sha-256 hash of the following elements:

  • Order Hash
  • Amount
  • Taker Address

The (Order, Trade) tuple can then be used to perform an on-chain transaction for this trade.

Quote Tokens and Token Pairs

In the same way as traditional exchanges function with the idea of base currencies and quote currencies, the ODEX decentralized exchange works with base tokens and quote tokens under the following principles:

  • Only the exchange operator can register a quote token
  • Anybody can register a token pair (but the quote token needs to be registered)

Token pairs are identified by an ID (a hash of both token asset IDs)

Websocket API



Thank you for considering helping the ODEX project !

To make the ODEX project truely revolutionary, we need and accept contributions from anyone and are grateful even for the smallest fixes.

If you want to help ODEX, please fork and setup the development environment of the appropriate repository. In the case you want to submit substantial changes, please get in touch with our development team on #odex channel on Obyte Discord to verify those modifications are in line with the general goal of the project and receive early feedback. Otherwise you are welcome to fix, commit and send a pull request for the maintainers to review and merge into the main code base.

Please make sure your contributions adhere to our coding guidelines:

Code must adhere as much as possible to standard conventions (DRY - Separation of concerns - Modular) Pull requests need to be based and opened against the master branch Commit messages should properly describe the code modified Ensure all tests are passing before submitting a pull request


If you have questions, ideas or suggestions, you can reach the development team on Discord in the #odex channel. Discord Link


ODEX backend is based on AMP Exchange, the most beautiful and easy to use decentralized exchange.


All the code in this repository is licensed under the MIT License, also included in our repository in the LICENSE file.


The Go Gopher

There is no documentation for this package.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL