Skip to content

Commit

Permalink
Ln/update get highest bid lowest ask (#702)
Browse files Browse the repository at this point in the history
* invert orders as necessary

* Change function call to quote/base and review

---------

Co-authored-by: diamondhands <[email protected]>
  • Loading branch information
lazynina and diamondhands0 authored Nov 13, 2024
1 parent a3e1d27 commit 6f666cc
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions routes/dao_coin_exchange_with_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -1001,18 +1001,18 @@ func (fes *APIServer) GetQuoteCurrencyPriceInUsd(
}

func (fes *APIServer) GetHighestBidAndLowestAskPriceFromPKIDs(
coin1PKID *lib.PKID,
coin2PKID *lib.PKID,
basePkid *lib.PKID,
quotePkid *lib.PKID,
utxoView *lib.UtxoView,
initialHighestBidPrice float64,
) (float64, float64, float64, error) {
ordersBuyingCoin1, err := utxoView.GetAllDAOCoinLimitOrdersForThisDAOCoinPair(
coin1PKID, coin2PKID)
basePkid, quotePkid)
if err != nil {
return 0, 0, 0, fmt.Errorf("GetDAOCoinLimitOrders: Error getting limit orders: %v", err)
}
ordersBuyingCoin2, err := utxoView.GetAllDAOCoinLimitOrdersForThisDAOCoinPair(
coin2PKID, coin1PKID)
quotePkid, basePkid)
if err != nil {
return 0, 0, 0, fmt.Errorf("GetDAOCoinLimitOrders: Error getting limit orders: %v", err)
}
Expand All @@ -1033,12 +1033,26 @@ func (fes *APIServer) GetHighestBidAndLowestAskPriceFromPKIDs(
if err != nil {
return 0, 0, 0, fmt.Errorf("GetQuoteCurrencyPriceInUsd: Error parsing price: %v", err)
}

// Flip orders as needed.
appliedOperationType := order.OperationType
if order.OperationType == lib.DAOCoinLimitOrderOperationTypeBID &&
order.BuyingDAOCoinCreatorPKID.Eq(quotePkid) {
priceFloat = 1.0 / priceFloat
appliedOperationType = lib.DAOCoinLimitOrderOperationTypeASK
}
if order.OperationType == lib.DAOCoinLimitOrderOperationTypeASK &&
order.SellingDAOCoinCreatorPKID.Eq(quotePkid) {
priceFloat = 1.0 / priceFloat
appliedOperationType = lib.DAOCoinLimitOrderOperationTypeBID
}

if appliedOperationType == lib.DAOCoinLimitOrderOperationTypeBID &&
priceFloat > highestBidPrice {

highestBidPrice = priceFloat
}
if order.OperationType == lib.DAOCoinLimitOrderOperationTypeASK &&
if appliedOperationType == lib.DAOCoinLimitOrderOperationTypeASK &&
priceFloat < lowestAskPrice {

lowestAskPrice = priceFloat
Expand Down

0 comments on commit 6f666cc

Please sign in to comment.