Skip to content

Commit

Permalink
Use coinbase price for DESO in dao-coin-limit-order (#690)
Browse files Browse the repository at this point in the history
  • Loading branch information
diamondhands0 authored Oct 25, 2024
1 parent 3961ca8 commit bbce609
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 14 additions & 2 deletions routes/dao_coin_exchange_with_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,13 @@ func (fes *APIServer) GetQuoteCurrencyPriceInUsdEndpoint(ww http.ResponseWriter,
func (fes *APIServer) GetQuoteCurrencyPriceInUsd(
quoteCurrencyPublicKey string) (_midmarket string, _bid string, _ask string, _err error) {
if IsDesoPkid(quoteCurrencyPublicKey) {
desoUsdCents := fes.GetExchangeDeSoPrice()
// 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.
}
Expand Down Expand Up @@ -936,7 +942,13 @@ func (fes *APIServer) GetQuoteCurrencyPriceInUsd(
} else if lowerUsername == "focus" ||
lowerUsername == "openfund" {

desoUsdCents := fes.GetExchangeDeSoPrice()
// 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")
}
pkid := utxoView.GetPKIDForPublicKey(pkBytes)
if pkid == nil {
return "", "", "", fmt.Errorf("GetQuoteCurrencyPriceInUsd: Error getting pkid for public key %v",
Expand Down
3 changes: 3 additions & 0 deletions routes/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,9 @@ func (fes *APIServer) GetNanosFromETH(eth *big.Float, feeBasisPoints uint64) uin
// GetNanosFromUSDCents - convert USD cents to DeSo nanos
func (fes *APIServer) GetNanosFromUSDCents(usdCents float64, feeBasisPoints uint64) uint64 {
// Get Exchange Price gets the max of price from blockchain.com and the reserve price.
// TODO: This function isn't using the Coinbase price. We should make it consistent with other
// places that use the Coinbase price, but it's fine for now because the places that call this
// function are deprecated.
usdCentsPerDeSo := fes.GetExchangeDeSoPrice()
conversionRateAfterFee := float64(usdCentsPerDeSo) * (1 + (float64(feeBasisPoints) / (100.0 * 100.0)))
nanosPurchased := uint64(usdCents * float64(lib.NanosPerUnit) / conversionRateAfterFee)
Expand Down

0 comments on commit bbce609

Please sign in to comment.