openpredictionmarkets / socialpredict

Easy to Deploy Prediction Market Platform
https://github.com/openpredictionmarkets/socialpredict
MIT License
63 stars 11 forks source link

Add IsClosed method to Market type for CheckMarketStatus #275

Closed ajlacey closed 2 months ago

ajlacey commented 2 months ago

@pwdel what is the distinction we're making between Market.ResolutionDateTime and Market.FinalResolutionDateTime? Is the former indicating a scheduled close and the ladder indicating an early close? If so, I think we can consolidate them into a single field.

That said, it looks like the ResolveMarkethandler only sets the FinalResolutionDateTime field, but we check the ResolutionDateTime field to see if a market is still open.

pwdel commented 2 months ago

@pwdel what is the distinction we're making between Market.ResolutionDateTime and Market.FinalResolutionDateTime? Is the former indicating a scheduled close and the ladder indicating an early close? If so, I think we can consolidate them into a single field.

That said, it looks like the ResolveMarkethandler only sets the FinalResolutionDateTime field, but we check the ResolutionDateTime field to see if a market is still open.

I put this on Discord but also putting it here for reference.

Is there a way to insert these descriptions into the model in Golang or reduced versions of these to be more explicit?

ID (int64):

    The unique identifier for each market, serving as the primary key in the database.

QuestionTitle (string):

    The main question or statement that the market is predicting, which users will bet on.

Description (string):

    A detailed explanation of the market, providing context, rules, and any other relevant information.

OutcomeType (string):

    Specifies the type of outcome the market is based on. Currently, only Yes/No categorical outcomes are supported.

ResolutionDateTime (time.Time):

    The scheduled date and time when the market's outcome will be determined.

FinalResolutionDateTime (time.Time):

    The actual date and time when the market was resolved, regardless of the originally scheduled resolution date.

UTCOffset (int):

    The offset from Coordinated Universal Time (UTC) for the market's time zone, indicating the local time zone difference.

IsResolved (bool):

    A flag indicating whether the market has been resolved (true) or is still open for trading (false).

ResolutionResult (string):

    The final outcome or result of the market, typically recorded after the resolution date, such as "Yes," "No," or another specified result.

InitialProbability (float64):

    The initial probability assigned to the market's outcome at the time of its creation, representing the starting point for betting.

CreatorUsername (string):

    The username of the user who created the market, linking the market to its creator.

Creator (User):

    A reference to the User struct, establishing a relationship between the market and its creator based on the CreatorUsername.
pwdel commented 2 months ago

@ajlacey got the following backend error when attempting to run this branch.

It seems that we need to modify the public response type for the market.

Likely this will effect the front end.

As far as I can tell via a search in VSCode, this function is used in:

Some of the above functions may make use of the ResolutionDateTime field and we will have to percolate our changes up through into the frontend.

The server has those functions listed at:

https://github.com/openpredictionmarkets/socialpredict/blob/main/backend/server/server.go

We can search those functions in the front end by for example searching:

v0/markets/

Which brings up for example BetsActivity.jsx, used as follows:

const BetsActivityLayout = ({ marketId }) => {
    const [bets, setBets] = useState([]);

    useEffect(() => {
        const fetchBets = async () => {
            const response = await fetch(`${API_URL}/api/v0/markets/bets/${marketId}`, {
            });
            if (response.ok) {
                const data = await response.json();
                setBets(data.sort((a, b) => new Date(b.placedAt) - new Date(a.placedAt)));
            } else {
                console.error('Error fetching bets:', response.statusText);
            }
        };
        fetchBets();
    }, [marketId]);

Though that specific field doesn't seem to be used in the front end here on that function.

However, I found where this field is used in the frontend by searching, resolutiondatetime ... and see that it's used under MarketDetailsLayout.jsx here:

        {[
          { label: 'Users', value: `${numUsers}`, icon: '👤' },
          { label: 'Volume', value: `${totalVolume.toFixed(2)}`, icon: '📊' },
          { label: 'Comments', value: '0', icon: '💬' },
          {
            label: 'Closes',
            value: market.isResolved
              ? 'Closed'
              : formatResolutionDate(market.resolutionDateTime),
            icon: '📅',
          },

So, also that field, isResolved is being used, so we would hypothetically need to change that to, isClosed per what you are suggesting and then the resolutionDateTime would need to be re-instated to where it can be reported again.

I'm realizing that perhaps the entire logic is confusing and maybe we need to document what we want the outcome to be first.

  1. Markets get started with a SCHEDULED_CLOSED_DATE
  2. They can be CLOSED < SCHEDULED_CLOSE_DATE which prevents betting on the market, "CLOSED EARLY"
  3. If DATE > SCHEDULED_CLOSE_DATE this triggers an automatic prevention of betting on the market.
  4. Hypothetically we can allow users to change the SCHEDULED_CLOSE_DATE to a future date again, either after or prior to the original SCHEDULED_CLOSE_DATE.
  5. Once a market is RESOLVED it is also CLOSED, no bets can be made, and the SCHEDULED_CLOSE_DATE can no longer be changed, as it has been RESOLVED. RESOLVED is more final than CLOSED.

Error below.


socialpredict-backend-container   | Setting up watches.  Beware: since -r was given, this may take a while!
socialpredict-backend-container   | Watches established.
socialpredict-backend-container   | # socialpredict/handlers/marketpublicresponse
socialpredict-backend-container   | handlers/marketpublicresponse/publicresponsemarket.go:47:35: market.ResolutionDateTime undefined (type models.Market has no field or method ResolutionDateTime)
socialpredict-backend-container   | # socialpredict/handlers/marketpublicresponse
socialpredict-backend-container   | handlers/marketpublicresponse/publicresponsemarket.go:47:35: market.ResolutionDateTime undefined (type models.Market has no field or method ResolutionDateTime)
socialpredict-backend-container   | # socialpredict/handlers/marketpublicresponse
socialpredict-backend-container   | handlers/marketpublicresponse/publicresponsemarket.go:47:35: market.ResolutionDateTime undefined (type models.Market has no field or method ResolutionDateTime)