Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

Commit

Permalink
Compare best short to best bid
Browse files Browse the repository at this point in the history
  • Loading branch information
theoreticalbts committed Mar 17, 2015
1 parent 0f34cb3 commit 371343c
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions libraries/blockchain/market_engine_v7.cpp
Expand Up @@ -622,19 +622,33 @@ namespace bts { namespace blockchain { namespace detail {

bool market_engine_v7::get_next_short_v064()
{
// if top-of-book short is better than _current_bid:
// write short into _current_bid
// move _short_itr
// return true
if( _short_itr.valid() )
{
auto bid = market_order( short_order,
_short_itr.key(),
_short_itr.value(),
_short_itr.value().balance,
_short_itr.key().order_price );
if( bid.get_price().quote_asset_id == _quote_id &&
bid.get_price().base_asset_id == _base_id )

// we don't use get_price(*_feed_price) here because
// this is checking whether the index might have moved into
// another market, which might not have a valid feed
if( (bid.get_price().quote_asset_id != _quote_id) ||
(bid.get_price().base_asset_id != _base_id) )
return false;

if(
(!_current_bid.valid()) ||
(bid.get_price(*_feed_price) > _current_bid->get_price(*_feed_price))
)
{
--_short_itr;
_current_bid = bid;
return _current_bid.valid();
return true;
}
}
return false;
Expand All @@ -653,14 +667,15 @@ namespace bts { namespace blockchain { namespace detail {
auto bid = market_order( bid_order, _bid_itr.key(), _bid_itr.value() );
if( bid.get_price().quote_asset_id == _quote_id &&
bid.get_price().base_asset_id == _base_id )
{
if( _feed_price.valid() && bid.get_price() < *_feed_price && get_next_short() )
return _current_bid.valid();

_current_bid = bid;

if( _feed_price.valid() && bid.get_price() < *_feed_price && get_next_short() )
return true;

if( _current_bid.valid() )
--_bid_itr;
return _current_bid.valid();
}

return _current_bid.valid();
}
get_next_short();
return _current_bid.valid();
Expand Down

0 comments on commit 371343c

Please sign in to comment.