BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
api_objects.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
26 #include <graphene/app/util.hpp>
27 
28 namespace graphene { namespace app {
29 
30 order::order( const string& _price,
31  const string& _quote,
32  const string& _base,
33  const limit_order_id_type& _id,
34  const account_id_type& _oid,
35  const string& _oname,
36  const time_point_sec& _exp )
37 : price( _price ),
38  quote( _quote ),
39  base( _base ),
40  id( _id ),
41  owner_id( _oid ),
42  owner_name( _oname ),
43  expiration( _exp )
44 {
45  // Nothing to do
46 }
47 
48 order_book::order_book( const string& _base, const string& _quote )
49 : base( _base ), quote( _quote )
50 {
51  // Do nothing else
52 }
53 
55  const fc::time_point_sec& now,
56  const asset_object& asset_base,
57  const asset_object& asset_quote,
58  const order_book& orders)
59 {
60  time = now;
61  mto_id = mto.id;
62  base = asset_base.symbol;
63  quote = asset_quote.symbol;
64  percent_change = "0";
65  lowest_ask = "0";
68  highest_bid = "0";
71  fc::uint128_t bv;
72  fc::uint128_t qv;
73  price latest_price = asset( mto.latest_base, mto.base ) / asset( mto.latest_quote, mto.quote );
74  if( mto.base != asset_base.id )
75  latest_price = ~latest_price;
76  latest = price_to_string( latest_price, asset_base, asset_quote );
77  if( mto.last_day_base != 0 && mto.last_day_quote != 0 // has trade data before 24 hours
78  && ( mto.last_day_base != mto.latest_base || mto.last_day_quote != mto.latest_quote ) ) // price changed
79  {
80  price last_day_price = asset( mto.last_day_base, mto.base ) / asset( mto.last_day_quote, mto.quote );
81  if( mto.base != asset_base.id )
82  last_day_price = ~last_day_price;
83  percent_change = price_diff_percent_string( last_day_price, latest_price );
84  }
85  if( asset_base.id == mto.base )
86  {
87  bv = mto.base_volume;
88  qv = mto.quote_volume;
89  }
90  else
91  {
92  bv = mto.quote_volume;
93  qv = mto.base_volume;
94  }
96  quote_volume = uint128_amount_to_string( qv, asset_quote.precision );
97 
98  if(!orders.asks.empty())
99  {
100  lowest_ask = orders.asks[0].price;
101  lowest_ask_base_size = orders.asks[0].base;
102  lowest_ask_quote_size = orders.asks[0].quote;
103  }
104 
105  if(!orders.bids.empty())
106  {
107  highest_bid = orders.bids[0].price;
108  highest_bid_base_size = orders.bids[0].base;
109  highest_bid_quote_size = orders.bids[0].quote;
110  }
111 
112 }
113 
115  const asset_object& asset_base,
116  const asset_object& asset_quote)
117 {
118  time = now;
119  base = asset_base.symbol;
120  quote = asset_quote.symbol;
121  latest = "0";
122  lowest_ask = "0";
123  lowest_ask_base_size = "0";
124  lowest_ask_quote_size = "0";
125  highest_bid = "0";
126  highest_bid_base_size = "0";
128  percent_change = "0";
129  base_volume = "0";
130  quote_volume = "0";
131 }
132 
134 : block_header( bh ), // Slice intentionally
135  witness_signature( with_witness_signature ? bh.witness_signature : optional<signature_type>() )
136 { // Nothing else to do
137 }
138 
139 } } // graphene::app
graphene::app::market_ticker::base_volume
string base_volume
Definition: api_objects.hpp:125
graphene::app::market_ticker::highest_bid
string highest_bid
Definition: api_objects.hpp:121
graphene::market_history::market_ticker_object::last_day_quote
share_type last_day_quote
Definition: market_history_plugin.hpp:144
graphene::db::object::id
object_id_type id
Definition: object.hpp:69
graphene::app::market_ticker::lowest_ask_quote_size
string lowest_ask_quote_size
Definition: api_objects.hpp:120
graphene::market_history::market_ticker_object::latest_quote
share_type latest_quote
Definition: market_history_plugin.hpp:146
graphene::app::maybe_signed_block_header::maybe_signed_block_header
maybe_signed_block_header()=default
graphene::protocol::price
The price struct stores asset prices in the BitShares system.
Definition: asset.hpp:108
graphene::market_history::market_ticker_object::quote
asset_id_type quote
Definition: market_history_plugin.hpp:142
graphene::app::order_book::asks
vector< order > asks
Definition: api_objects.hpp:107
graphene::app::market_ticker::base
string base
Definition: api_objects.hpp:115
graphene::chain::asset_object
tracks the parameters of an asset
Definition: asset_object.hpp:75
fc::zero_initialized_array
Definition: zeroed_array.hpp:30
graphene::app::market_ticker::highest_bid_base_size
string highest_bid_base_size
Definition: api_objects.hpp:122
graphene::chain::asset_object::symbol
string symbol
Ticker symbol for this asset, i.e. "USD".
Definition: asset_object.hpp:131
graphene::app::market_ticker::latest
string latest
Definition: api_objects.hpp:117
graphene::app::market_ticker::lowest_ask
string lowest_ask
Definition: api_objects.hpp:118
graphene::market_history::market_ticker_object::base_volume
fc::uint128_t base_volume
Definition: market_history_plugin.hpp:147
graphene::app::market_ticker::mto_id
optional< object_id_type > mto_id
Definition: api_objects.hpp:127
graphene::chain::asset_object::precision
uint8_t precision
Maximum number of digits after the decimal point (must be <= 12)
Definition: asset_object.hpp:133
graphene::app::market_ticker::lowest_ask_base_size
string lowest_ask_base_size
Definition: api_objects.hpp:119
graphene::app::market_ticker::quote_volume
string quote_volume
Definition: api_objects.hpp:126
graphene::market_history::market_ticker_object::latest_base
share_type latest_base
Definition: market_history_plugin.hpp:145
fc::time_point_sec
Definition: time.hpp:74
graphene::app::market_ticker::quote
string quote
Definition: api_objects.hpp:116
graphene::app::order::order
order()=default
graphene::app::order_book
Definition: api_objects.hpp:102
graphene::market_history::market_ticker_object::last_day_base
share_type last_day_base
Definition: market_history_plugin.hpp:143
graphene::app::market_ticker::time
time_point_sec time
Definition: api_objects.hpp:114
graphene::app::price_diff_percent_string
std::string price_diff_percent_string(const graphene::protocol::price &old_price, const graphene::protocol::price &new_price)
Definition: util.cpp:104
api_objects.hpp
graphene::protocol::signed_block_header
Definition: block.hpp:47
graphene::app::order_book::order_book
order_book()=default
graphene::app::price_to_string
std::string price_to_string(const graphene::protocol::price &_price, const uint8_t base_precision, const uint8_t quote_precision)
Definition: util.cpp:68
graphene::market_history::market_ticker_object::base
asset_id_type base
Definition: market_history_plugin.hpp:141
fc::optional
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
graphene::app::market_ticker::market_ticker
market_ticker()
Definition: api_objects.hpp:129
graphene::app::order_book::bids
vector< order > bids
Definition: api_objects.hpp:106
graphene::protocol::asset
Definition: asset.hpp:31
graphene::app::uint128_amount_to_string
std::string uint128_amount_to_string(const fc::uint128_t &amount, const uint8_t precision)
Definition: util.cpp:42
graphene::market_history::market_ticker_object::quote_volume
fc::uint128_t quote_volume
Definition: market_history_plugin.hpp:148
graphene::app::market_ticker::highest_bid_quote_size
string highest_bid_quote_size
Definition: api_objects.hpp:123
graphene
Definition: api.cpp:48
util.hpp
graphene::market_history::market_ticker_object
Definition: market_history_plugin.hpp:138
graphene::app::market_ticker::percent_change
string percent_change
Definition: api_objects.hpp:124
graphene::protocol::block_header
Definition: block.hpp:29