Skip to content

Commit

Permalink
Add default entry when no trades and keep fix if latest trade is afte…
Browse files Browse the repository at this point in the history
…r closing date
  • Loading branch information
Daniel Sanchez committed Jan 30, 2020
1 parent 329be28 commit 76248a4
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions app/src/components/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,35 @@ const Graph = ({
...entries
];

// Logic to add last entry if necessary
const lastEntry = entries[entries.length - 1];
const noTrades = entries.length === 0;

const isBeforeResolutionDate = getMoment(resolutionDate).isAfter(
getMoment()
);
const isLastEntryBeforeResolutionDate = getMoment(
lastEntry.date
).isBefore(getMoment(resolutionDate));

if (isBeforeResolutionDate || isLastEntryBeforeResolutionDate) {
const isLastEntryBeforeResolutionDate =
!noTrades &&
getMoment(lastEntry.date).isBefore(getMoment(resolutionDate));

if (
isBeforeResolutionDate ||
noTrades ||
isLastEntryBeforeResolutionDate
) {
// Only add last entry (with current probabilities) if the market is not already resolved.
// When market is resolved, if latest trade is before selected resolution date, duplicate latest trade
// but adjust to show on resolution date (in some special cases there can be trades a bit after resolution date)
const newEntry = isBeforeResolutionDate
? {
outcomesProbability: currentProbability,
date: +new Date()
date: getMoment().valueOf()
}
: {
outcomesProbability: lastEntry.outcomesProbability,
outcomesProbability: noTrades
? initialOutcomesProbability
: lastEntry.outcomesProbability,
date: getMoment(resolutionDate).valueOf()
};
newData.push({
Expand Down

0 comments on commit 76248a4

Please sign in to comment.