Bitshares-Core  2.0.181105
BitShares blockchain implementation and command-line interface software
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
graphene::chain::price Struct Reference

The price struct stores asset prices in the Graphene system. More...

#include <asset.hpp>

Public Member Functions

 price (const asset &_base=asset(), const asset &_quote=asset())
 
price max () const
 
price min () const
 
double to_real () const
 
bool is_null () const
 
void validate () const
 

Static Public Member Functions

static price max (asset_id_type base, asset_id_type quote)
 
static price min (asset_id_type base, asset_id_type quote)
 
static price call_price (const asset &debt, const asset &collateral, uint16_t collateral_ratio)
 
static price unit_price (asset_id_type a=asset_id_type())
 The unit price for an asset type A is defined to be a price such that for any asset m, m*A=m. More...
 

Public Attributes

asset base
 
asset quote
 

Detailed Description

The price struct stores asset prices in the Graphene system.

A price is defined as a ratio between two assets, and represents a possible exchange rate between those two assets. prices are generally not stored in any simplified form, i.e. a price of (1000 CORE)/(20 USD) is perfectly normal.

The assets within a price are labeled base and quote. Throughout the Graphene code base, the convention used is that the base asset is the asset being sold, and the quote asset is the asset being purchased, where the price is represented as base/quote, so in the example price above the seller is looking to sell CORE asset and get USD in return.

Definition at line 115 of file asset.hpp.

Constructor & Destructor Documentation

◆ price()

graphene::chain::price::price ( const asset _base = asset(),
const asset _quote = asset() 
)
inlineexplicit

Definition at line 117 of file asset.hpp.

Member Function Documentation

◆ call_price()

price graphene::chain::price::call_price ( const asset debt,
const asset collateral,
uint16_t  collateral_ratio 
)
static

The black swan price is defined as debt/collateral, we want to perform a margin call before debt == collateral. Given a debt/collateral ratio of 1 USD / CORE and a maintenance collateral requirement of 2x we can define the call price to be 2 USD / CORE.

This method divides the collateral by the maintenance collateral ratio to derive a call price for the given black swan ratio.

There exists some cases where the debt and collateral values are so small that dividing by the collateral ratio will result in a 0 price or really poor rounding errors. No matter what the collateral part of the price ratio can never go to 0 and the debt can never go more than GRAPHENE_MAX_SHARE_SUPPLY

CR * DEBT/COLLAT or DEBT/(COLLAT/CR)

Definition at line 207 of file asset.cpp.

◆ is_null()

bool graphene::chain::price::is_null ( ) const

Definition at line 221 of file asset.cpp.

◆ max() [1/2]

price graphene::chain::price::max ( asset_id_type  base,
asset_id_type  quote 
)
static

Definition at line 101 of file asset.cpp.

◆ max() [2/2]

price graphene::chain::price::max ( ) const
inline

Definition at line 131 of file asset.hpp.

◆ min() [1/2]

price graphene::chain::price::min ( asset_id_type  base,
asset_id_type  quote 
)
static

Definition at line 102 of file asset.cpp.

◆ min() [2/2]

price graphene::chain::price::min ( ) const
inline

Definition at line 132 of file asset.hpp.

◆ to_real()

double graphene::chain::price::to_real ( ) const
inline

Definition at line 134 of file asset.hpp.

◆ unit_price()

static price graphene::chain::price::unit_price ( asset_id_type  a = asset_id_type())
inlinestatic

The unit price for an asset type A is defined to be a price such that for any asset m, m*A=m.

Definition at line 129 of file asset.hpp.

◆ validate()

void graphene::chain::price::validate ( ) const

Definition at line 227 of file asset.cpp.

Member Data Documentation

◆ base

asset graphene::chain::price::base

Definition at line 120 of file asset.hpp.

◆ quote

asset graphene::chain::price::quote

Definition at line 121 of file asset.hpp.


The documentation for this struct was generated from the following files: