socialpredict icon indicating copy to clipboard operation
socialpredict copied to clipboard

Circular Import Between MarketBetsDisplayHandler() and GetPublicResponseMarketByID()

Open pwdel opened this issue 1 year ago • 0 comments

In MarketBetsDisplayHandler()...

When we go to processBetsForDisplay we have to enter the time that the market was created at. In order to do this we have to make a query to the database. What would be nicer is to use the pre-built GetPublicResponseMarketByID() however this results in a circular import.

	// Database connection
	db := util.GetDB()

	// Fetch bets for the market
	bets := GetBetsForMarket(marketIDUint)

	// feed in the time created
	// note we are not using GetPublicResponseMarketByID because of circular import
	var market models.Market
	result := db.Where("ID = ?", marketIdStr).First(&market)
	if result.Error != nil {
		// Handle error, for example:
		if errors.Is(result.Error, gorm.ErrRecordNotFound) {
			// Market not found
		} else {
			// Other error fetching market
		}
		return // Make sure to return or appropriately handle the error
	}

	// Process bets and calculate market probability at the time of each bet
	betsDisplayInfo := processBetsForDisplay(market.CreatedAt, bets, db)

pwdel avatar Feb 06 '24 18:02 pwdel