Correctly compute amount left on sell offer when a crossing offer pays us more than we asked for.

This commit is contained in:
JoelKatz
2013-10-28 16:48:47 -07:00
parent 8e65d6288d
commit 4ddadb8792

View File

@@ -334,7 +334,15 @@ TER OfferCreateTransactor::takeOffers (
if (tesSUCCESS == terResult)
terResult = lesActive.accountSend (uTakerAccountID, uOfferOwnerID, saSubTakerPaid); // Taker pays offer owner.
if (!bSell)
if (bSell)
{
// Sell semantics:
// Reduce amount considered received to original offer's rate.
// Not by crossing rate, which is higher.
STAmount saEffectiveGot = STAmount::divide(saSubTakerPaid, saTakerRate, saTakerGets);
saSubTakerGot = std::min(saEffectiveGot, saSubTakerGot);
}
else
{
// Buy semantics: Reduce amount considered paid by taker's rate. Not by actual cost which is lower.
// That is, take less as to just satify our buy requirement.