BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
graphene::protocol::price Struct Reference

The price struct stores asset prices in the BitShares 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 (bool check_upper_bound=false) const
 Check if the object is valid. More...
 

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 BitShares 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 BitShares 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 108 of file asset.hpp.

Constructor & Destructor Documentation

◆ price()

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

Definition at line 110 of file asset.hpp.

Member Function Documentation

◆ call_price()

price graphene::protocol::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)

Note: this function is only used before core-1270 hard fork.

Definition at line 216 of file asset.cpp.

◆ is_null()

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

Definition at line 229 of file asset.cpp.

◆ max() [1/2]

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

Definition at line 124 of file asset.hpp.

◆ max() [2/2]

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

Definition at line 106 of file asset.cpp.

◆ min() [1/2]

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

Definition at line 125 of file asset.hpp.

◆ min() [2/2]

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

Definition at line 109 of file asset.cpp.

◆ to_real()

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

Definition at line 127 of file asset.hpp.

◆ unit_price()

static price graphene::protocol::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 122 of file asset.hpp.

◆ validate()

void graphene::protocol::price::validate ( bool  check_upper_bound = false) const

Check if the object is valid.

Parameters
check_upper_boundWhether to check if the amounts in the price are too large

Definition at line 235 of file asset.cpp.

Member Data Documentation

◆ base

asset graphene::protocol::price::base

Definition at line 113 of file asset.hpp.

◆ quote

asset graphene::protocol::price::quote

Definition at line 114 of file asset.hpp.


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