Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add order book documentation #85

Merged
merged 9 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions docs/learn/order-book.md
maltekliemann marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
id: order-book
title: Order Book
---

An order book is a digital ledger used in asset trading that records open
orders, a buy or sell instruction from a trader for a specific asset or
security. It functions as the backbone of most modern trading platforms and
exchanges, enabling users to execute trades based on current market conditions.

## How the Order Book works in Zeitgeist

In Zeitgeist, the order book contains trading pairs of outcome assets and the
market's base asset (collateral). The order book can be set as the market's
scoring rule. The operations within the order book are primarily managed through
three fundamental functions: `place_order`, `remove_order`, and `fill_order`.
It's important to mention that market creator fees are charged for each taken
order.

### Place Order

This function is used to introduce a new order into the market. When traders
decide to buy or sell an asset, they use `place_order` to specify the details of
their order, the quantity they wish to buy the `taker_asset` for `taker_amount`
and sell the `maker_asset` for `maker_amount`. This order is then added to the
order book, where it waits to be matched by taker(s).

It is important to mention that the users of the Zeitgeist order book do specify
the price of the assets implicitly. This means that the `place_order` does not
take a price as an argument, but rather the `taker_amount` and `maker_amount`.
This means the caller of the `place_order` function does willingly sell the
`maker_amount` of the `maker_asset` to buy the given `taker_amount` of the
`taker_asset`. After the execution of `place_order` the `maker_amount` of the
`maker_asset` is reserved for the order. This means it is not available for the
user to use in other transactions.

##### Price Example

Let's assume you wish to purchase `42` outcome tokens, referred to as
`taker_asset`. You decide to offer `7` ZTG, your `maker_asset`, for this
transaction. Essentially, this means you're ready to exchange `7` ZTG for `42`
outcome tokens. By doing so, you've implicitly set a rate of `6` outcome tokens
per `1` ZTG (since `42` divided by `7` equals `6`). Therefore, if a taker agrees
to your proposed rate, they need to supply `42` outcome tokens (or fewer, in the
case of partial order fulfillment) and, in return, will get `7` ZTG from you (or
less, depending on the partial fulfillment scenario).

It's important to note that the market creator's fee is always deducted in the
market's base currency, which in our example is ZTG. So, if the market creator
charges a `1%` fee, the taker ends up receiving `6.3` ZTG, while the market
creator gets `0.7` ZTG. However, the `taker_amount` you receive as the maker
Chralt98 marked this conversation as resolved.
Show resolved Hide resolved
remains unchanged, as no fees are deducted from the outcome token. It might seem
like the recipient of the base asset (in this case, ZTG) is always the one who
pays the fee. But this perspective can vary because each order is unique and may
already factor in the associated fees at the time of its creation, adjusting the
price accordingly.

### Fill Order

The crux of any trading activity is the completion of trades, which is
facilitated by the `fill_order` function. This function is triggered when a
taker matches a given maker order. The `fill_order` function will execute the
trade, transferring the specified asset between parties at the agreed price, and
update the order book to reflect the completion of the trade.

The taker has the ability to partially fill the order for a given
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by this description. I think you're confusing maker and taker here. The taker is the one who fills the order, so I'm not quite sure what "This amount specifies the partial amount of what the maker wants to fill." is referring to.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree it's confusing. Your sentence "The taker is the one who fills the order" and my sentence is just the perspective of the maker "This amount specifies the partial amount of what the maker wants to fill". But shall we leave this sentence rather out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I'm saying is that the sentence "... the maker wants to fill" doesn't really work because the maker doesn't fill orders.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it's the maker wants to get filled

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But anyways, I deleted it. Can you approve?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next sentence also mentions the maker filling an order. ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`maker_partial_fill` amount. The maker always wants to fill the `taker_amount`
of the specified taker asset (in `place_order`). Thus, the `maker_partial_fill`
(if a partial fill is wanted) should be smaller than the `taker_amount` of the
maker order.

### Remove Order

Orders may need to be withdrawn from the order book for various reasons, such as
a change in market strategy or a mistake in the order's details. The
`remove_order` function allows traders or the system to cancel an existing
order. This function ensures that the order book remains up-to-date with only
active intents to trade, thereby preserving market liquidity and participant
interest.

### Market Creator Fees

As other trading mechanisms on Zeitgeist, the order book does also charge fees
for the market creator. The fees are charged for each taken order in the
market's base asset (collateral). As usual, the fee is specified by the market
creator.
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const sidebars = {
"learn/using-zeitgeist-markets",
"learn/governance",
"learn/court",
"learn/order-book",
"learn/futarchy",
"learn/comparisons",
{
Expand Down
Loading