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

Collection of market issues #1443

Open
18 of 23 tasks
theoreticalbts opened this issue Mar 16, 2015 · 7 comments
Open
18 of 23 tasks

Collection of market issues #1443

theoreticalbts opened this issue Mar 16, 2015 · 7 comments
Assignees

Comments

@theoreticalbts
Copy link
Contributor

This is a collection of market tickets that are still open. Some of these are already resolved in develop branch.

@theoreticalbts theoreticalbts self-assigned this Mar 16, 2015
@theoreticalbts theoreticalbts added this to the dvs/0.7.0 milestone Mar 16, 2015
@theoreticalbts theoreticalbts changed the title Collection of market issues for 0.8.0 Collection of market issues Mar 16, 2015
@vikramrajkumar vikramrajkumar modified the milestones: dvs/0.8.0, dvs/0.7.0 Mar 16, 2015
@vikramrajkumar
Copy link
Contributor

@theoreticalbts
Copy link
Contributor Author

If no order can match only in the current pass, does this need to be a continue rather than a break

There are actually two loops. The inner loop is a while loop that executes once for each order, the outer loop is a for loop that iterates through the 3 passes.

At this point in the code we want to stop the current pass and go on to the next pass. So break drops out of the inner loop, but the outer loop will go on to the next pass.

The indentation is not so clear that there are two loops, mostly because I didn't want to muddy the waters on this commit with a bunch of whitespace changes to otherwise untouched lines.

@theoreticalbts
Copy link
Contributor Author

The TODO at market_engine.cpp#L57 was a reminder to myself to review corner cases in the iterator logic. I'm replacing it with a comment containing my analysis, see f6d2d56

The TODO at market_engine.cpp#L138-142 was a note to myself that, while this termination check was not optional in the commit that introduced it, it would be made optional by a planned later commit. Indeed we can see that if limit_price < mtrx.ask_price then bid_price will be set to a value at least as small as limit_price, so if limit_price < ask_price then certainly bit_price < ask_price which will trigger the termination condition at market_engine.cpp#L194-198.

Actually on closer inspection, removing this check actually seems to fix a matching bug. With the check in place, ask_price might be high enough to trigger the check and terminate -- but in case of a called cover order, the code in the next if statement might "want" to update ask_price to force a match, but never run because of the check. End result, called cover orders would be unable to match against new shorts unless the short price actually overlapped the margin call price, contrary to the design intent. The commit that removes the check is 55aae58

With respect to the TODO at market_engine.cpp#L379-L382 -- this block of code was created in two places by 14d47ab, one was quickly removed in d076871. It seems that the intent was to dispatch to the logic to update _shorts_at_feed where this check is, but _shorts_at_feed is updated in store_feed_record() instead. So dispatching to this logic from the market engine is no longer necessary. I'm deleting the if statement and TODO in 7f9a60c

@theoreticalbts
Copy link
Contributor Author

About flagging chain_database.cpp#L2347-L2474 as a potential trouble spot -- nice code reviewing skills. @valzav yesterday reported a failing acceptance_test which, upon investigation, I determined to be failing due to incorrect logic in this section. It is now fixed in f93723d and everything else in this section seems to be correct.

@abitmore
Copy link
Member

//EDIT: the comment below is incorrect. Just leave it here for reference.

will this always return an empty iterator?

Should it be something like std::make_pair( *_feed_price * 0.9, market_index_key( current_pair ))?
same issue reported at #1315 (comment)

@theoreticalbts
Copy link
Contributor Author

@abitmore : _short_at_limit_itr is a reverse iterator so it starts at feed price and goes downwards (but excludes orders exactly at the feed price, those are covered by _short_at_feed_itr). When shorting into a margin call, what would happen is the cover price would be adjusted to consume more collateral at market_engine.cpp#L168-L184.

I think what you're missing here is that shorts can only execute on one side of the feed (which side this is depends on which flipped market you're thinking about). Shorts that are on the "wrong side" aren't inactivated, rather they are clamped to shorting at the feed value. Those clamped shorts are in _short_at_feed_itr. The whole point of these changes is that because these shorts have two modes of execution, they need to be indexed separately.

@abitmore
Copy link
Member

@theoreticalbts Thanks for reply. I didn't know how the reverse iterator works (now I know). I guessed that it would start from the nearest short below feed_price and go down, but incorrectly assumed it would end at the parameter passed into the constructor of reverse_iterator, and misunderstood the rend() call.
BTW I think I know how the shorts should match, just trying to understand the code.

@vikramrajkumar vikramrajkumar removed this from the dvs/0.10.0 milestone Jun 9, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants