Initial commit
This commit is contained in:
111
docs/peatio/coin_market_cap.md
Normal file
111
docs/peatio/coin_market_cap.md
Normal file
@@ -0,0 +1,111 @@
|
||||
# CoinMarketCap API integration
|
||||
|
||||
Peatio has a simple way to integrate with CoinMarketCap<br/>
|
||||
This doc includes technical documentation needed to formulate/standardize exchange API endpoints.<br/>
|
||||
Exchanges are expected to minimally support the mandatory endpoints outlined below along with their corresponding mandatory data-points for integration.<br/>
|
||||
|
||||
## List of supported API endpoints described here:
|
||||
1. `api/v2/coinmarketcap/summary` - *Overview of market data for all tickers and all markets*<br/>
|
||||
**Response example:**
|
||||
```json
|
||||
[
|
||||
{
|
||||
"trading_pairs": "Identifier of a ticker with delimiter to separate base/quote",
|
||||
"base_currency": "Symbol/currency code of base currency",
|
||||
"quote_currency": "Symbol/currency code of base currency",
|
||||
"last_price": "Last transacted price of base currency based on given quote currency",
|
||||
"lowest_ask": "Lowest Ask price of base currency based on given quote currency",
|
||||
"highest_bid": "Highest bid price of base currency based on given quote currency",
|
||||
"base_volume": "24-hr volume of market pair denoted in BASE currency",
|
||||
"quote_volume": "24-hr volume of market pair denoted in QUOTE currency",
|
||||
"price_change_percent_24h": "24-hr % price change of market pair",
|
||||
"highest_price_24h": "Highest price of base currency based on given quote currency in the last 24-hrs",
|
||||
"lowest_price_24h": "Lowest price of base currency based on given quote currency in the last 24-hrs"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
2. `api/v2/coinmarketcap/assets` - *The assets endpoint is to provide a detailed summary for each available currency*<br/>
|
||||
**Response example:**
|
||||
```json
|
||||
[
|
||||
{
|
||||
"CURRENCY_CODE": {
|
||||
"name": "Full name of cryptocurrency",
|
||||
"unified_cryptoasset_id": "Unique ID of cryptocurrency assigned by Unified Cryptoasset ID",
|
||||
"can_withdraw": "Identifies whether withdrawals are enabled or disabled",
|
||||
"can_deposit": "Identifies whether deposits are enabled or disabled",
|
||||
"min_withdraw": "Identifies the single minimum withdrawal amount of a cryptocurrency"
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
3. `/api/v2/coinmarketcap/ticker` - *The ticker endpoint is to provide a 24-hour pricing and volume summary for each available market pair available* <br/>
|
||||
**Response example:**
|
||||
```json
|
||||
[
|
||||
{
|
||||
"MARKET_NAME": {
|
||||
"base_id": "The quote pair Unified Cryptoasset ID",
|
||||
"quote_id": "The base pair Unified Cryptoasset ID",
|
||||
"last_price": "Last transacted price of base currency based on given quote currency",
|
||||
"base_volume": "24-hour trading volume denoted in BASE currency",
|
||||
"quote_volume": "24 hour trading volume denoted in QUOTE currency",
|
||||
"isFrozen": "Indicates if the market is currently enabled (0) or disabled (1)"
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
4. `/api/v2/coinmarketcap/orderbook/:market_pair` - *The order book endpoint is to provide a complete level 2 order book (arranged by best asks/bids) with full depth returned for a given market pair* <br/>
|
||||
**Parameters:**<br/>
|
||||
market_pair - A pair such as “LTC_BTC”\
|
||||
depth - Orders depth quantity: [0,5,10,20,50,100,500].Not defined or 0 = full order book. Depth = 100 means 50 for each bid/ask side.<br/>
|
||||
**Response example:**
|
||||
```javascript
|
||||
[
|
||||
{
|
||||
"timestamp": "Unix timestamp in milliseconds for when the last updated time occurred",
|
||||
// An array containing 2 elements. The offer price and quantity for each bid order
|
||||
"bids":[
|
||||
[
|
||||
"12462000",
|
||||
"0.04548320"
|
||||
],
|
||||
[
|
||||
"12457000",
|
||||
"3.00000000"
|
||||
]
|
||||
],
|
||||
// An array containing 2 elements. The ask price and quantity for each ask order
|
||||
"asks":[
|
||||
[
|
||||
"12506000",
|
||||
"2.73042000"
|
||||
],
|
||||
[
|
||||
"12508000",
|
||||
"0.33660000"
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
5. `/api/v2/coinmarketcap/trades/:market_pair` - *The trades endpoint is to return data on all recently completed trades for a given market pair* <br/>
|
||||
**Parameters:**<br/>
|
||||
market_pair - A pair such as “LTC_BTC”<br/>
|
||||
**Response example:**
|
||||
```json
|
||||
[
|
||||
{
|
||||
"trade_id": "A unique ID associated with the trade for the currency pair transaction",
|
||||
"price": "Last transacted price of base currency based on given quote currency",
|
||||
"base_volume": "Transaction amount in BASE currency",
|
||||
"quote_volume": "Transaction amount in QUOTE currency",
|
||||
"timestamp": "Unix timestamp in milliseconds for when the transaction occurred",
|
||||
"type": "Used to determine whether or not the transaction originated as a buy or sell"
|
||||
}
|
||||
]
|
||||
```
|
||||
7
docs/peatio/configuration.md
Normal file
7
docs/peatio/configuration.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Peatio environments configuration
|
||||
This document provides description of available configuration through the environment.
|
||||
|
||||
### General configuration
|
||||
| Environment variable | Default value | Possible values | Description |
|
||||
| ----------------------------- | ------------- | --------------- | ------------------------------------------------------------ |
|
||||
| `PEATIO_DEPOSIT_FUNDS_LOCKED` | false | `true`, `false` | When turned on (`true`) user funds will be locked on deposit, and unlocked once the collection of this deposit succeed |
|
||||
42
docs/peatio/daemons.md
Normal file
42
docs/peatio/daemons.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# Peatio daemons
|
||||
|
||||
Peatio daemons are managed by [God](http://godrb.com/).
|
||||
|
||||
## Starting daemons
|
||||
|
||||
To start God as daemon run:
|
||||
|
||||
`god -c lib/daemons/daemons.god`
|
||||
|
||||
You can also start God in foreground:
|
||||
|
||||
`god -c lib/daemons/daemons.god -D`
|
||||
|
||||
**God starts all daemons when it is being initialized.**
|
||||
|
||||
Use `god stop` to stop all daemons. God will still be up.
|
||||
Use `god start` to start all daemons.
|
||||
|
||||
## Stopping daemons
|
||||
|
||||
To stop God and all daemons run:
|
||||
|
||||
`god terminate`
|
||||
|
||||
To stop only daemons leaving God up run:
|
||||
|
||||
`god stop`
|
||||
|
||||
## Restarting daemons
|
||||
|
||||
`god restart`
|
||||
|
||||
Be patient when starting or stopping daemons: most of daemons support graceful termination so God will first send SIGTERM, wait short period of time, and forcefully kill process by sending SIGKILL if it is still up.
|
||||
|
||||
## Querying status
|
||||
|
||||
`god status`
|
||||
|
||||
## Reading logs
|
||||
|
||||
Each daemon has it's own log file localed at `log/daemons`.
|
||||
30
docs/peatio/deposits_flow.md
Normal file
30
docs/peatio/deposits_flow.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Peatio deposit flow
|
||||
## Previous version
|
||||
In previous version we had deposit collection flow based on amqp daemon (deposit_collection_fees, deposit_collection)
|
||||
|
||||
Legacy deposit process diagram:
|
||||
|
||||

|
||||
|
||||
1. Blockchain daemon process blocks and filter platform deposits.
|
||||
2. We are waiting for the N number of confirmations.
|
||||
3. Blockchain daemon produces AMQP message for deposit_collection_fees daemon.
|
||||
4. deposit_collection_fees daemon trying to collect fees if needed (erc20 case) and after collection immediately produce a message for the next daemon (deposit_collection).
|
||||
|
||||
deposit_collection daemon processing message and trying to collect deposit depending on the deposit spread.
|
||||
|
||||
The main problem for this approach that we don't wait till the transaction that we generated in the deposit_collection_fees daemon successfully executed and we are failing on deposit collection in the last step (it happens mostly for each erc20 deposit). Also, there is some chance that we can miss amqp message due to server instability.
|
||||
|
||||
## New deposit collection flow based on SQL worker
|
||||
|
||||
We decided to remove to AMQP base deposit daemons and create a new deposit daemon that will work on deposit states changes and will prevent immediate proceeding of erc20 deposits.
|
||||
|
||||
New deposit process diagram:
|
||||
|
||||

|
||||
|
||||
1. Blockchain daemon process blocks and filter platform deposits.
|
||||
2. We are waiting for the N number of confirmations.
|
||||
3. In the deposit daemons we select each 60s deposits with state `processing` and `fee_processing`.
|
||||
4. For `processing` deposits we are checking if plugin implement method `prepare_deposit_collection!` if it doesn't we immediately process the deposit and collect deposit to the `hot`, `warm`, `cold` wallets. If plugin implement method `prepare_deposit_collection!` daemon processing of collection fees and change deposit state to `fee_processing`.
|
||||
For deposits with `fee_processing` state, we select each minute deposits that have `updated_at` older than 5 minutes and process them. With time condition we are sure that fee transaction has already been executed.
|
||||
45
docs/peatio/engine.md
Normal file
45
docs/peatio/engine.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# ENGINES
|
||||
|
||||
Engines in Peatio represent market's matching engine settings.
|
||||
|
||||
| column | Desc |
|
||||
| ---------------- | ---------------------------------------------------- |
|
||||
| id | an unique identifier in database |
|
||||
| name | human-readable description |
|
||||
| driver | More about driver in DRIVERS section |
|
||||
| uid | User's UID for upstream markets (more in UPSTREAM) |
|
||||
| url | URL for upstream |
|
||||
| key_encrypted | apikey kid for upstream |
|
||||
| secret_encrypted | apikey secret for upstream |
|
||||
| data_encrypted | can hold any engine-specific key-value configuration |
|
||||
| state | Either online or offline |
|
||||
|
||||
Every market belongs to one of defined engines and every engine should have one of supported drivers.
|
||||
|
||||
## DRIVERS
|
||||
|
||||
Drivers can be divided into two groups - Local or Upstream.
|
||||
|
||||
Supported local drivers are peatio and finex-spot.
|
||||
|
||||
Peatio comes with peatio driver available only.
|
||||
|
||||
Upstream drivers are supported in finex trading engine.
|
||||
|
||||
## UPSTREAM
|
||||
|
||||
Upstream is a remote platform you can connect to to use them as liquidity provider for your platform.
|
||||
|
||||
To setup upstream market, you need to create an upstream engine:
|
||||
|
||||
```ruby
|
||||
engine = Engine.create(name: "BitFinex", driver: "bitfinex", uid: "UID", key: "KID", secret: "SECRET", url: "wss://api.bitfinex.com/ws/2", data: {"rest": "http://api-pub.bitfinex.com/ws/2", "websocket": "wss://api-pub.bitfinex.com/ws/2", "trade_proxy"=>true, "orderbook_proxy"=>true})
|
||||
```
|
||||
|
||||
`UID` is an 'upstream' user UID on **your platform**. When you submit an order to the upstream market and get a trade on remote platform, the trade will be recorded as a trade between you and this user.
|
||||
|
||||
`KID` and `SECRET` are your **remote platform** credentials.
|
||||
|
||||
`data` field should contain a configuration for trade and orderbook proxy. Peatio Upstream daemon will connect to the remote platform via `rest` and `websocket` params in data and will forward latest trades and incremental orderbook updates to your platform.
|
||||
|
||||
And do not forget to deposit some funds to remote platform :)
|
||||
168
docs/peatio/opendax_wallet_plugin.md
Normal file
168
docs/peatio/opendax_wallet_plugin.md
Normal file
@@ -0,0 +1,168 @@
|
||||
## Opendax Wallet plugin
|
||||
|
||||
This service is used in OpenDAX Go HDwallet microservice to generate wallets, sign and broadcast transactions. It is using BIP-32 HD Wallet, which mean all addresses are generated from one master seed
|
||||
|
||||
### Settings configuration examples
|
||||
|
||||
Deposit wallet
|
||||
|
||||
```json
|
||||
blockchain_key: eth blockchain (infura) with right explorer_address, explorer_transaction
|
||||
gateway: field set as `opendax`
|
||||
settings:
|
||||
uri: a link to go-hd microservice (e.g. "https://hdwallet/api/v2/hdwallet")
|
||||
gateway_url: a url of the infura or private node for broadcast transactions
|
||||
```
|
||||
|
||||
Example:
|
||||
```ruby
|
||||
Wallet.create!(
|
||||
blockchain_key: "eth-testnet",
|
||||
name: "ETH/ERC-20 Deposit Wallet",
|
||||
address: "changeme",
|
||||
gateway: "opendax",
|
||||
kind: "deposit",
|
||||
settings: {uri: "https://hdwallet/api/v2/hdwallet", gateway_url: "https://infura.io"},
|
||||
max_balance: 0,
|
||||
status: "active"
|
||||
)
|
||||
```
|
||||
|
||||
Hot wallet
|
||||
|
||||
To save Hot wallet you need to generate it [see](#create-address)
|
||||
|
||||
```json
|
||||
blockchain_key: eth blockchain (infura) with right explorer_address, explorer_transaction
|
||||
gateway: field set as `opendax`
|
||||
address: Hot wallet address
|
||||
settings:
|
||||
uri: a link to go-hd microservice (https://hdwallet/api/v2/hdwallet)
|
||||
gateway_url: a url of the infura or private node for broadcast transactions
|
||||
wallet_index: should be vault encrypted secret from wallet private key
|
||||
secret: index provided in the address generation step
|
||||
```
|
||||
|
||||
Example:
|
||||
```ruby
|
||||
Wallet.create!(
|
||||
blockchain_key: "eth-testnet",
|
||||
name: "ETH/ERC-20 HOT Wallet",
|
||||
address: "hot-wallet-address",
|
||||
gateway: "opendax",
|
||||
kind: "hot",
|
||||
settings: {
|
||||
uri: "https://hdwallet/api/v2/hdwallet",
|
||||
gateway_url: "https://infura.io"},
|
||||
wallet_index: 1,
|
||||
secret: "changeme",
|
||||
max_balance: 1000,
|
||||
status: "active"
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
#### Implemented functions are
|
||||
### Create address
|
||||
To test address creating you need to be sure that:
|
||||
1. You have deposit wallet with right configuration
|
||||
- `blockchain_key` should be some fake blockchain with right explorer_address, explorer_transaction
|
||||
- `gateway` field set as `opendax`
|
||||
- in wallet settings you have:
|
||||
- `uri` should be a link to go-hd microservice, default is `https://hdwallet/api/v2/hdwallet`;
|
||||
- `gateway_url` should be a url of the crypto node, infura;
|
||||
- `passphrase` - should be vault encrypted secret from wallet private key;
|
||||
- `wallet_index` - index provided in the address generation step
|
||||
|
||||
### There are 3 options to test:
|
||||
1. From rails console
|
||||
|
||||
```ruby
|
||||
# Find deposit wallet and save it to variable
|
||||
w = Wallet.find(id)
|
||||
service = WalletService.new(w)
|
||||
service.create_address!(uid, {})
|
||||
# response
|
||||
{
|
||||
"address":"0x6876447bF1ab4efc09740e242eaED2Ab389509a4",
|
||||
"passphrase":"2ee7dc93b6581c3ac31f62d32257477e",
|
||||
"coin-type":"eth",
|
||||
"wallet-index":20004
|
||||
}
|
||||
```
|
||||
|
||||
2. From API call
|
||||
`api/v2/peatio/account/deposit_address/:currency`
|
||||
```json
|
||||
// response
|
||||
{
|
||||
"currencies": ["bigo","cro","eth"],
|
||||
"address":"0xb06dd7f8ee1852cf3f9e43b9a703a06f8e28d31f",
|
||||
"state":"active"
|
||||
}
|
||||
```
|
||||
|
||||
3. From peatio daemon
|
||||
To check if there is some problem, with user address generation you should check `amqp-daemon-deposit-coin-address` daemon logs
|
||||
|
||||
To verify address information has right format
|
||||
```ruby
|
||||
# Find deposit wallet and member configuration
|
||||
wallet = Wallet.find(id)
|
||||
member = Member.find_by(email 'your email')
|
||||
# Find member payment address
|
||||
payment_address = PaymentAddress.find_by(wallet_id: wallet.id, member_id: member.id)
|
||||
# In payment address secret should be information about passphrase (encrypted password from private key)
|
||||
payment_address.secret
|
||||
"a4ee099cc541dd222dc24ea546dd46c6"
|
||||
# In payment address details should be information about wallet index, and coin type
|
||||
payment_address.details
|
||||
{"wallet_index"=>2, "coin_type"=>"eth"}
|
||||
```
|
||||
|
||||
### Create transaction
|
||||
|
||||
To test create transaction you should have all configuration described on `create_address` step for all wallets related to your currency (especially deposit, hot wallet)
|
||||
|
||||
Be sure that you have blockchain configured before doing transaction and this blockchain-key connected both for currency and wallets!
|
||||
Blockchain `server` param should be the same as `url` param in wallet settings (node url, infura url)
|
||||
1. Deposit
|
||||
- Deposit some funds to your created address
|
||||
- Check logs of `daemon-deposit`
|
||||
- You can get information about deposit status from rails console, admin tower or your wallet page
|
||||
2. Withdraw
|
||||
- Transfer funds from your account
|
||||
- Check logs of `amqp-daemon-withdraw-coin` about withdraw status from rails console, admin tower or your wallet page
|
||||
|
||||
### Load balance
|
||||
To test load balance you should have all configuration described on `create_address` step for all wallets related to your currency (deposit, hot, warm, cold)
|
||||
### There are 2 options to test:
|
||||
1. From rails console
|
||||
```ruby
|
||||
1. Find deposit wallet and save it to variable
|
||||
w = Wallet.find(id)
|
||||
w.current_balance
|
||||
# response
|
||||
{
|
||||
"balance":216380800000000000
|
||||
}
|
||||
```
|
||||
2. From Admin API call
|
||||
`api/v2/peatio/admin/wallets/:id`
|
||||
```json
|
||||
//response
|
||||
"id": 1,
|
||||
"name": "Test wallet",
|
||||
"kind": "deposit",
|
||||
"currencies": ["fth","seele"],
|
||||
"address": "changeme",
|
||||
"gateway": "parity",
|
||||
"max_balance": "212.0",
|
||||
"balance": {
|
||||
"fth": "2.3",
|
||||
"seele": "223.3"
|
||||
},
|
||||
"blockchain_key": "eth-testnet",
|
||||
"status": "active",
|
||||
"created_at": "2020-09-10T17:53:03+02:00","updated_at": "2020-10-20T05:00:49+02:00"
|
||||
```
|
||||
84
docs/peatio/pnl_calculation.md
Normal file
84
docs/peatio/pnl_calculation.md
Normal file
@@ -0,0 +1,84 @@
|
||||
## Trader PnL calculation
|
||||
|
||||
This doc describes how you can calculate a trader’s total P&L
|
||||
|
||||
| Term | Definition |
|
||||
| ------------------ | ------------------------------------------------------------ |
|
||||
| PnL currency | The currency into which the entries are converted to. |
|
||||
| Currency | Trader income or outcome currency |
|
||||
| Total Credit | Sum of incomes of the trader in the currency (without fees) |
|
||||
| Total Credit Fees | Sum of fees applied to incomes of the trader in the currency |
|
||||
| Total Credit Value | (Total Credit + Total Credit Fees) estimated in pnl currency using the latest market price |
|
||||
| Total Debit | Sum of outcomes of the trader in the currency (without fees) |
|
||||
| Total Debit Fees | Sum of fees applied to outcomes of the trader in the currency |
|
||||
| Total Debit Value | (Total Debit + Total Debit Fees) estimated in pnl currency |
|
||||
| Average Buy Price | Total Credit Value / (Total Credit + Total Credit Fees) |
|
||||
| Average Sell Price | Total Debit Value / (Total Debit + Total Debit Fees) |
|
||||
|
||||
### Configuration
|
||||
|
||||
To enable the PnL calculation for traders you need to setup at least one destination currency in the PNL_CURRENCIES variable.
|
||||
|
||||
| Environment Variable | Example | Description |
|
||||
| -------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
|
||||
| PNL_CURRENCIES | usd,btc | List of pnl currencies |
|
||||
| CONVERSION_PATHS | usd/krw:_usdt/usd,usdt/krw this will convert usd to krw using the last price of markets usd/usdt (reversed) and usd/krw | By default conversions are made using the direct market (BTC to USD use latest market price of btc/usd). If a direct conversion market is missing you can specify a conversion path setting this variable. Several paths can be defined with semi-colon (;) separation. |
|
||||
| PNL_EXCLUDE_ROLES | maker,broker | Skip PnL calculation for users with the following roles |
|
||||
|
||||
|
||||
### Formulas
|
||||
#### Calculate user Realized PNL
|
||||
##### For one currency
|
||||
-----
|
||||
###### Realized PNL Value = Total Debit Value * (Average Sell Price - Average Buy Price) / Average Sell Price
|
||||
-----
|
||||
#### Calculate user Unrealized PNL
|
||||
##### For one currency
|
||||
-----
|
||||
###### Asset Current Value = Balance * Last Market Price
|
||||
###### Asset Average Buy Value = Balance * Average Buy Price
|
||||
###### Unrealized PNL Value = Asset Current Value - Asset Average Buy Value
|
||||
###### Unrealized PNL Percentage = (100 * Unrealized PNL Value) / Asset Average Buy Value
|
||||
-----
|
||||
#### Calculate user Total PNL
|
||||
##### For one currency
|
||||
-----
|
||||
###### Total PNL = Realized PNL + Unrealized PNL
|
||||
-----
|
||||
#### Total user assets PNL
|
||||
-----
|
||||
###### Total Asset Average Value = SUM(Asset Average Buy Value)
|
||||
###### Total Asset Current Value = SUM(Asset Current Value)
|
||||
###### Total PNL Value = Total Asset Current Value - Total Asset Average Value
|
||||
###### Total PNL Percentage = (100 * Total PNL Value) / Total Asset Average Value
|
||||
-----
|
||||
#### 1) Initial State
|
||||
|
||||
|
||||
|Currency| Balance |Total Credit | Total Credit Fees | Total Credit Value | Total Debit | Total Debit Fees | Total Debit Value | Average Buy Price | Average Sell Price | Realized PNL | Unrealized PNL| Total PNL | Average PNL Price |Total PNL Value|
|
||||
|---|---|---|---|---|---|---| ---|---|---|---|---|---|---|---|
|
||||
| BTC | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0| 0| 0| 0| 0 | 0|
|
||||
|
||||
#### 2) Deposit 3 BTC, Portfolio Currency = ETH, Last Market Price (BTC/ETH) = 10 000
|
||||
|
||||
|Currency| Balance |Total Credit | Total Credit Fees | Total Credit Value | Total Debit | Total Debit Fees | Total Debit Value | Average Buy Price | Average Sell Price | Realized PNL | Unrealized PNL| Total PNL | Average PNL Price |Total PNL Value|
|
||||
|---|---|---|---|---|---|---| ---|---|---|---|---|---|---|---|
|
||||
| BTC | 2.994000 | 2.994000 | 0.006000 | 30 000 | 0 | 0 | 0 | 10 000| 0| 0| 0| 0| 10000 | 29940 |
|
||||
-------
|
||||
###### Average Buy Price = 30000 / (2.994000 + 0.006000) = 10000
|
||||
###### Total PNL Value = Total Credit * Average Buy Price -Total Debit Value = 2.994000 * 10 000 - 0 = 29940
|
||||
###### Average PNL Price = Total PNL Value / Balance = 29940 / 2.994000 = 10000
|
||||
------
|
||||
#### 3) Sell 1 BTC, Portfolio Currency = ETH, Last Market Price (BTC/ETH) = 9000
|
||||
|
||||
|Currency| Balance |Total Credit | Total Credit Fees | Total Credit Value | Total Debit | Total Debit Fees | Total Debit Value | Average Buy Price | Average Sell Price | Realized PNL | Unrealized PNL| Total PNL | Average PNL Price |Total PNL Value|
|
||||
|---|---|---|---|---|---|---| ---|---|---|---|---|---|---|---|
|
||||
| BTC| 1.994000 | 2.994000 | 0.006000| 30 000 | 1 | 0 | 9000 | 10 000 | 9000 | -1000| -1994| -2994 | 10501.5045135 | 20940 |
|
||||
------
|
||||
###### Average Sell Price = 9000 / (1 + 0.006000) = 9000
|
||||
###### Realized PNL = Total Debit Value * (Average Sell Price - Average Buy Price) / Average Sell Price = 9000 * (9000 - 10 000) / 9000 = -1000
|
||||
###### Unrealized PNL = Balance * Last Market Price (BTC/ETH) - Balance * Average Buy Price = 1.994000 * 9000 - 1.994000 * 10 000 = - 1994
|
||||
###### Total PNL = Realized PNL + Unrealized PNL = -1000 + (-1994) = -2994
|
||||
###### Total PNL Value = Total Credit * Average Buy Price - Total Debit Value = 2.994000 * 10 000 - 9000 = 20940
|
||||
###### Average PNL Price = Total PNL Value / Balance = 20940 / 1.994000 = 10501.5045135
|
||||
-----
|
||||
33
docs/peatio/withdraw_limits.md
Normal file
33
docs/peatio/withdraw_limits.md
Normal file
@@ -0,0 +1,33 @@
|
||||
## Global Withdraw Limits
|
||||
|
||||
This document describes how withdraw limits works in opendax peatio.
|
||||
|
||||
Withdraw limits schema:
|
||||
|
||||
| Term | Definition |
|
||||
| -------------- | ------------------------------------------------ |
|
||||
| Group | Member group. Will be used to select limit |
|
||||
| KYC Level | Member KYC level. Will be used to select limit |
|
||||
| 24 hour limit | 24 hour limit in platform currency e.g. USD |
|
||||
| 1 month limit | 1 month limit in platform currency e.g. USD |
|
||||
|
||||
Every user has a KyC level (starts from 0) and a group (default is 'any').
|
||||
The KYC level has a higher priority than group match.
|
||||
|
||||
For example a member with kyc_level 2 and group 'vip-0' will match the following rules in order:
|
||||
The first is the highest priority.
|
||||
|
||||
|KYC level|Group |Priority|
|
||||
|---------|---------|--------|
|
||||
| 2 | vip-0 | 1 |
|
||||
| 2 | any | 2 |
|
||||
| any | vip-0 | 3 |
|
||||
| any | any | 4 |
|
||||
|
||||
Withdraw limits check flow:
|
||||
|
||||
1. If the user hasn't reached any withdrawal limits, the system process the withdrawal request automatically from the currency 'Hot wallet'. If the 'Hot wallet' doesn't have enough funds to process the withdrawal request the system will throw an error. In this situation, the admin needs to replenish the 'Hot wallet'.
|
||||
|
||||
2. If the user reached at least one of withdrawal limits (24 hours or 1 month) the system accepts the request, locks the user funds but doesn't process the withdraw automatically. Admin can manually reject or process this withdrawal request from the 'Hot wallet' or process it manually from the warm wallet.
|
||||
|
||||
More info about [Peatio Financial Flow](https://www.openware.com/sdk/guides/operator/financial-flow.html) and [Peatio Wallet Guidelines](https://www.openware.com/sdk/guides/operator/wallet-guidelines.html).
|
||||
Reference in New Issue
Block a user