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

chore: docs for calculating market price quantity tick size #245

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions .gitbook/calulations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Calculations

Here are some formula formatting values between the chain and UI human-readable.

### Bridges Supported

| Topic | Description |
| ------------------------------------------------------- | --------------------------------------- |
| [Market min price tick size](minPriceTickSize.md) | Minimum market order price tick size |
| [Market min quantity tick size](minQuantityTickSzie.md) | Minimum market order quantity tick size |
47 changes: 47 additions & 0 deletions .gitbook/calulations/minPriceTickSize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Market min price tick size

The min market price tick size for an order price - if a market has an minPriceTickSick of `0.001` and order submission with the price of `0.0011` will be rejected.

Note that calculating the formula for calculating a spot and quote market price tick size are different.

### Spot market

1. UI human readable to chain format:
Using INJ/USDT market which has 18 base decimals and 6 quote decimals as an example, here's how we convert the value to the chain format:

```js
const chainFormat = new BigNumberInBase(10)
.pow(quoteDecimal - baseDecimal)
.times(value)
.toFixed()
```

1. Chain format to UI human readable format:
Using INJ/USDT market which has 18 base decimals and 6 quote decimals as an example, here's how we convert the value to the UI human readable format:

```js
const humanReadableFormat = new BigNumber(value)
.shiftedBy(baseDecimals - quoteDecimals)
.toFixed()
```

### Derivative market

1. UI human readable to chain format:
Using INJ/USDT perp market which has 6 quote decimals as an example, here's how we convert the value to the chain format:

```js
const chainFormat = new BigNumberInBase(10)
.pow(-quoteDecimal)
.times(value)
.toFixed()
```

1. Chain format to UI human readable format:
Using INJ/USDT perp market which has 6 quote decimals as an example, here's how we convert the value to the UI human readable format:

```js
const humanReadableFormat = new BigNumber(value)
.shiftedBy(-quoteDecimals)
.toFixed()
```
23 changes: 23 additions & 0 deletions .gitbook/calulations/minQuantityTickSize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Market min quantity tick size

The min market quantity tick size for an order price - if a market has an minQuantityTickSize of `0.001` and order submission with the quantity of `0.0011` will be rejected.

Note that derivate markets shares the same format for minQuantityTickSize between UI and the chain, so no formatting is required.

### Spot market

1. UI human readable to chain format:
Using on a INJ/USDT market which has 18 base decimals and 6 quote decimals as an example, here's how we convert the value to the chain format:

```js
const chainFormat = new BigNumberInWei(value).toBase(baseDecimals)
```

1. Chain format to UI human readable format:
Using INJ/USDT market which has 18 base decimals and 6 quote decimals as an example, here's how we convert the value to the UI human readable format:

```js
const humanReadableFormat = new BigNumber(minQuantityTickSize)
.shiftedBy(-baseDecimals)
.toFixed()
```