market_ticker market_history_api_impl::get_ticker() const { market_ticker result; auto db = app.chain_database(); const auto& bucket_idx = db->get_index_type< bucket_index >().indices().get< by_bucket >(); auto itr = bucket_idx.lower_bound( boost::make_tuple( 86400, db->head_block_time() - 86400 ) ); if( itr != bucket_idx.end() ) { auto open = ( asset( itr->open_sbd, SBD_SYMBOL ) / asset( itr->open_steem, STEEM_SYMBOL ) ).to_real(); result.latest = ( asset( itr->close_sbd, SBD_SYMBOL ) / asset( itr->close_steem, STEEM_SYMBOL ) ).to_real(); result.percent_change = ( ( result.latest - open ) / open ) * 100; } else { result.latest = 0; result.percent_change = 0; } auto orders = get_order_book( 1 ); if( orders.bids.size() ) result.highest_bid = orders.bids[0].price; if( orders.asks.size() ) result.lowest_ask = orders.asks[0].price; auto volume = get_volume(); result.steem_volume = volume.steem_volume; result.sbd_volume = volume.sbd_volume; return result; }
inline void order_processor::send_market_order(const ats::market_order& order) { auto it = orders_.insert(std::make_pair(order.id(), std::make_shared<ats::order>(order))).first; order_status_handlers_(ats::order_status_pending_new_message(order.id(), current_time())); const ats::symbol_key& symbol = portfolio_->get_symbol_key(order.symbol()); const ats::exchange_order_book* book = get_order_book(symbol).get(order.exchange()); if (book == nullptr) { std::string reason = "Order book for symbol '" << order.symbol() << "' and exchange '" + order.exchange() + "' does not exist."; if (!auto_clear_inactive_orders) it->second->set_status(ats::order_status::Rejected); else orders_.erase(it); order_status_handlers_(ats::order_status_rejected_message(order.id(), current_time(), reason)); return; } if (order.side() == ats::order_side::Buy || order.side() == ats::order_side::BuyCover) { if (!book->asks().empty()) { if (!auto_clear_inactive_orders) it->second->set_status(ats::order_status::Filled); else orders_.erase(it); order_status_handlers_(ats::order_status_filled_message(order.id(), current_time(), book->best_ask_price(), order.quantity())); } else { if (!auto_clear_inactive_orders) it->second->set_status(ats::order_status::Rejected); else orders_.erase(it); order_status_handlers_(ats::order_status_rejected_message(order.id(), current_time(), "No asks in order book")); } } else { if (!book->bids().empty()) { if (!auto_clear_inactive_orders) it->second->set_status(ats::order_status::Filled); else orders_.erase(it); order_status_handlers_(ats::order_status_filled_message(order.id(), current_time(), book->best_bid_price(), order.quantity())); } else { if (!auto_clear_inactive_orders) it->second->set_status(ats::order_status::Rejected); else orders_.erase(it); order_status_handlers_(ats::order_status_rejected_message(order.id(), current_time(), "No bids in order book")); } } }