asset market_order::get_quote_quantity( const price& relative )const { switch( order_type_enum( type ) ) { case relative_bid_order: case bid_order: { // balance is in USD divide by price return get_balance(); } case relative_ask_order: case ask_order: { // balance is in USD divide by price return get_balance() * get_price(relative); } case short_order: { return get_balance() * get_price(relative); } case cover_order: { return get_balance(); } default: FC_ASSERT( false, "Not Implemented" ); } // NEVER GET HERE..... // return get_balance() * get_price(); }
asset market_order::get_quantity( const price& relative )const { switch( order_type_enum( type ) ) { case relative_bid_order: case bid_order: { // balance is in USD divide by price return get_balance() * get_price(relative); } case relative_ask_order: case ask_order: { // balance is in USD divide by price return get_balance(); } case short_order: { return get_balance(); } case cover_order: { return asset( (*collateral * BTS_BLOCKCHAIN_MCALL_D2C_NUMERATOR) / BTS_BLOCKCHAIN_MCALL_D2C_DENOMINATOR ); } default: FC_ASSERT( false, "Not Implemented" ); } // NEVER GET HERE..... //return get_balance() * get_price(); }
price market_order::get_price( const price& relative )const { try { switch( order_type_enum(type) ) { case relative_bid_order: { price abs_price; if( relative != price() ) abs_price = market_index.order_price * relative; else abs_price = market_index.order_price; if( state.limit_price ) abs_price = std::min( abs_price, *state.limit_price ); return abs_price; } case relative_ask_order: { price abs_price; if( relative != price() ) abs_price = market_index.order_price * relative; else abs_price = market_index.order_price; if( state.limit_price ) abs_price = std::max( abs_price, *state.limit_price ); return abs_price; } case short_order: if( relative == price() ) return market_index.order_price; if( state.limit_price ) return std::min( *state.limit_price, relative ); return relative; case bid_order: case ask_order: case cover_order: return market_index.order_price; case null_order: FC_ASSERT( false, "Null Order" ); } FC_ASSERT( false, "Should not reach this line" ); } catch( const bts::blockchain::price_multiplication_undefined& ) { return price(); } catch( const bts::blockchain::price_multiplication_overflow& ) { return price(); } catch( const bts::blockchain::price_multiplication_underflow& ) { return price(); } FC_CAPTURE_AND_RETHROW( (*this)(relative) ) }
asset market_order::get_balance()const { asset_id_type asset_id; switch( order_type_enum( type ) ) { case bid_order: asset_id = market_index.order_price.quote_asset_id; break; case ask_order: asset_id = market_index.order_price.base_asset_id; break; case null_order: FC_ASSERT( false, "Null Order" ); } return asset( state.balance, asset_id ); }
price market_order::get_price( const price& relative )const { try { switch( order_type_enum(type) ) { case bid_order: case ask_order: case null_order: FC_ASSERT( false, "Null Order" ); } FC_ASSERT( false, "Should not reach this line" ); } catch( const bts::blockchain::price_multiplication_undefined& ) { return price(); } catch( const bts::blockchain::price_multiplication_overflow& ) { return price(); } catch( const bts::blockchain::price_multiplication_underflow& ) { return price(); } FC_CAPTURE_AND_RETHROW( (*this)(relative) ) }