BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface 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 
31  const fc::time_point_sec& now,
32  const asset_object& asset_base,
33  const asset_object& asset_quote,
34  const order_book& orders)
35 {
36  time = now;
37  base = asset_base.symbol;
38  quote = asset_quote.symbol;
39  percent_change = "0";
40  lowest_ask = "0";
43  highest_bid = "0";
46  fc::uint128_t bv;
47  fc::uint128_t qv;
48  price latest_price = asset( mto.latest_base, mto.base ) / asset( mto.latest_quote, mto.quote );
49  if( mto.base != asset_base.id )
50  latest_price = ~latest_price;
51  latest = price_to_string( latest_price, asset_base, asset_quote );
52  if( mto.last_day_base != 0 && mto.last_day_quote != 0 // has trade data before 24 hours
53  && ( mto.last_day_base != mto.latest_base || mto.last_day_quote != mto.latest_quote ) ) // price changed
54  {
55  price last_day_price = asset( mto.last_day_base, mto.base ) / asset( mto.last_day_quote, mto.quote );
56  if( mto.base != asset_base.id )
57  last_day_price = ~last_day_price;
58  percent_change = price_diff_percent_string( last_day_price, latest_price );
59  }
60  if( asset_base.id == mto.base )
61  {
62  bv = mto.base_volume;
63  qv = mto.quote_volume;
64  }
65  else
66  {
67  bv = mto.quote_volume;
68  qv = mto.base_volume;
69  }
71  quote_volume = uint128_amount_to_string( qv, asset_quote.precision );
72 
73  if(!orders.asks.empty())
74  {
75  lowest_ask = orders.asks[0].price;
76  lowest_ask_base_size = orders.asks[0].base;
77  lowest_ask_quote_size = orders.asks[0].quote;
78  }
79 
80  if(!orders.bids.empty())
81  {
82  highest_bid = orders.bids[0].price;
83  highest_bid_base_size = orders.bids[0].base;
84  highest_bid_quote_size = orders.bids[0].quote;
85  }
86 
87 }
88 
90  const asset_object& asset_base,
91  const asset_object& asset_quote)
92 {
93  time = now;
94  base = asset_base.symbol;
95  quote = asset_quote.symbol;
96  latest = "0";
97  lowest_ask = "0";
100  highest_bid = "0";
101  highest_bid_base_size = "0";
103  percent_change = "0";
104  base_volume = "0";
105  quote_volume = "0";
106 }
107 
108 } } // graphene::app
std::string price_to_string(const graphene::protocol::price &_price, const uint8_t base_precision, const uint8_t quote_precision)
Definition: util.cpp:68
std::string uint128_amount_to_string(const fc::uint128_t &amount, const uint8_t precision)
Definition: util.cpp:42
Definition: api.cpp:56
object_id_type id
Definition: object.hpp:73
The price struct stores asset prices in the BitShares system.
Definition: asset.hpp:114
string symbol
Ticker symbol for this asset, i.e. "USD".
tracks the parameters of an assetAll assets have a globally unique symbol name that controls how they...
uint8_t precision
Maximum number of digits after the decimal point (must be <= 12)
std::string price_diff_percent_string(const graphene::protocol::price &old_price, const graphene::protocol::price &new_price)
Definition: util.cpp:104