BitShares-Core  5.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  mto_id = mto.id;
38  base = asset_base.symbol;
39  quote = asset_quote.symbol;
40  percent_change = "0";
41  lowest_ask = "0";
44  highest_bid = "0";
47  fc::uint128_t bv;
48  fc::uint128_t qv;
49  price latest_price = asset( mto.latest_base, mto.base ) / asset( mto.latest_quote, mto.quote );
50  if( mto.base != asset_base.id )
51  latest_price = ~latest_price;
52  latest = price_to_string( latest_price, asset_base, asset_quote );
53  if( mto.last_day_base != 0 && mto.last_day_quote != 0 // has trade data before 24 hours
54  && ( mto.last_day_base != mto.latest_base || mto.last_day_quote != mto.latest_quote ) ) // price changed
55  {
56  price last_day_price = asset( mto.last_day_base, mto.base ) / asset( mto.last_day_quote, mto.quote );
57  if( mto.base != asset_base.id )
58  last_day_price = ~last_day_price;
59  percent_change = price_diff_percent_string( last_day_price, latest_price );
60  }
61  if( asset_base.id == mto.base )
62  {
63  bv = mto.base_volume;
64  qv = mto.quote_volume;
65  }
66  else
67  {
68  bv = mto.quote_volume;
69  qv = mto.base_volume;
70  }
72  quote_volume = uint128_amount_to_string( qv, asset_quote.precision );
73 
74  if(!orders.asks.empty())
75  {
76  lowest_ask = orders.asks[0].price;
77  lowest_ask_base_size = orders.asks[0].base;
78  lowest_ask_quote_size = orders.asks[0].quote;
79  }
80 
81  if(!orders.bids.empty())
82  {
83  highest_bid = orders.bids[0].price;
84  highest_bid_base_size = orders.bids[0].base;
85  highest_bid_quote_size = orders.bids[0].quote;
86  }
87 
88 }
89 
91  const asset_object& asset_base,
92  const asset_object& asset_quote)
93 {
94  time = now;
95  base = asset_base.symbol;
96  quote = asset_quote.symbol;
97  latest = "0";
98  lowest_ask = "0";
100  lowest_ask_quote_size = "0";
101  highest_bid = "0";
102  highest_bid_base_size = "0";
104  percent_change = "0";
105  base_volume = "0";
106  quote_volume = "0";
107 }
108 
109 } } // 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:69
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)
optional< object_id_type > mto_id
std::string price_diff_percent_string(const graphene::protocol::price &old_price, const graphene::protocol::price &new_price)
Definition: util.cpp:104