Skip to content

Commit

Permalink
update quote currency price in usd endpoint to use dex for price of deso
Browse files Browse the repository at this point in the history
  • Loading branch information
lazynina committed Oct 30, 2024
1 parent 6f22d88 commit cf4079c
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions routes/dao_coin_exchange_with_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,22 +908,31 @@ const FOCUS_FLOOR_PRICE_DESO_NANOS = 166666

func (fes *APIServer) GetQuoteCurrencyPriceInUsd(
quoteCurrencyPublicKey string) (_midmarket string, _bid string, _ask string, _err error) {
if IsDesoPkid(quoteCurrencyPublicKey) {
// TODO: We're taking the Coinbase price directly here, but ideally we would get it from
// a function that abstracts away the exchange we're getting it from. We do this for now
// in order to minimize discrepancies with other sources.
desoUsdCents := fes.MostRecentCoinbasePriceUSDCents
if desoUsdCents == 0 {
return "", "", "", fmt.Errorf("GetQuoteCurrencyPriceInUsd: Coinbase DESO price is zero")
}
price := fmt.Sprintf("%0.9f", float64(desoUsdCents)/100)
return price, price, price, nil // TODO: get real bid and ask prices.
}
utxoView, err := fes.backendServer.GetMempool().GetAugmentedUniversalView()
if err != nil {
return "", "", "", fmt.Errorf(
"GetQuoteCurrencyPriceInUsd: Error fetching mempool view: %v", err)
}
if IsDesoPkid(quoteCurrencyPublicKey) {
usdcProfileEntry := utxoView.GetProfileEntryForUsername([]byte("dusdc_"))
if usdcProfileEntry == nil {
return "", "", "", fmt.Errorf("GetQuoteCurrencyPriceInUsd: Could not find profile entry for dusdc_")
}

usdcPKID := utxoView.GetPKIDForPublicKey(usdcProfileEntry.PublicKey)
midMarketPrice, highestBidPrice, lowestAskPrice, err := fes.GetHighestBidAndLowestAskPriceFromPKIDs(
&lib.ZeroPKID, usdcPKID.PKID, utxoView, 0)
if err != nil {
return "", "", "", fmt.Errorf("GetQuoteCurrencyPriceInUsd: Error getting price for DESO: %v", err)
}
if highestBidPrice == 0.0 || lowestAskPrice == math.MaxFloat64 {
return "", "", "", fmt.Errorf("GetQuoteCurrencyPriceInUsd: Error calculating price for DESO")
}
return fmt.Sprintf("%0.9f", midMarketPrice),
fmt.Sprintf("%0.9f", highestBidPrice),
fmt.Sprintf("%0.9f", lowestAskPrice),
nil
}

pkBytes, _, err := lib.Base58CheckDecode(quoteCurrencyPublicKey)
if err != nil || len(pkBytes) != btcec.PubKeyBytesLenCompressed {
Expand Down

0 comments on commit cf4079c

Please sign in to comment.