Skip to content

Commit

Permalink
better balance range
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Jan 17, 2024
1 parent 6db3b1a commit 8e17781
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 22 deletions.
73 changes: 52 additions & 21 deletions dex/testing/loadbot/loadbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"flag"
"fmt"
"math"
"math/rand"
"net"
"os"
Expand Down Expand Up @@ -78,6 +79,8 @@ const (
// TODO: Consider returning a separate msgjson error from server for
// this case.
missedCancelErrStr = "target order not known:"

tradingTier = 100 // ~ 50 DCR
)

var (
Expand Down Expand Up @@ -116,6 +119,7 @@ var (
orderCounter, matchCounter, baseID, quoteID, regAsset uint32
epochDuration uint64
lotSize uint64
parcelSize uint64
rateStep uint64
rateShift, rateIncrease int64
conversionFactors = make(map[string]uint64)
Expand Down Expand Up @@ -460,6 +464,7 @@ func run() error {
rateStep = mkt.RateStep
epochDuration = mkt.Duration
marketBuyBuffer = mkt.MBBuffer
parcelSize = uint64(mkt.ParcelSize)
break
}

Expand Down Expand Up @@ -712,12 +717,13 @@ func run() error {
// marketsDotJSON models the server's markets.json configuration file.
type marketsDotJSON struct {
Markets []*struct {
Base string `json:"base"`
Quote string `json:"quote"`
LotSize uint64 `json:"lotSize"`
RateStep uint64 `json:"rateStep"`
Duration uint64 `json:"epochDuration"`
MBBuffer float64 `json:"marketBuyBuffer"`
Base string `json:"base"`
Quote string `json:"quote"`
LotSize uint64 `json:"lotSize"`
ParcelSize uint32 `json:"parcelSize"`
RateStep uint64 `json:"rateStep"`
Duration uint64 `json:"epochDuration"`
MBBuffer float64 `json:"marketBuyBuffer"`
} `json:"markets"`
Assets map[string]*dexsrv.AssetConf `json:"assets"`
}
Expand All @@ -739,24 +745,49 @@ func loadNodeConfig(symbol, node string) map[string]string {
return cfg
}

var xcRates = map[string]float64{
"bch": 244,
"btc": 42_000,
"dash": 29,
"dcr": 17,
"dgb": 0.0083,
"doge": 0.081,
"eth": 2_500,
"dextt.eth": 1,
"usdc.eth": 1,
"firo": 1.75,
"ltc": 69.1,
"polygon": 0.85,
"dextt.polygon": 1,
"usdc.polygon": 1,
"weth.polygon": 2_500,
"wbtc.polygon": 42_000,
"zcl": 0.086,
"zec": 22.92,
}

func getXCRate(symbol string) float64 {
if r, found := xcRates[symbol]; found {
return r
}
return 1
}

func symmetricWalletConfig(numCoins int, midGap uint64) (
minBaseQty, maxBaseQty, minQuoteQty, maxQuoteQty uint64) {

minBaseQty = uint64(maxOrderLots) * uint64(numCoins) * lotSize
minQuoteQty = calc.BaseToQuote(midGap, minBaseQty)
// Ensure enough for registration fees.
minBaseQty += 50e8
minQuoteQty += 50e8
// eth fee estimation calls for more reserves.
// TODO: polygon and tokens
if quoteSymbol == eth {
add := (ethRedeemFee + ethInitFee) * uint64(maxOrderLots)
minQuoteQty += add
}
if baseSymbol == eth {
add := (ethRedeemFee + ethInitFee) * uint64(maxOrderLots)
minBaseQty += add
}
bui, _ := asset.UnitInfo(baseID)
qui, _ := asset.UnitInfo(quoteID)
minBaseQty = lotSize * parcelSize * tradingTier * 5 / 4
minBaseConventional := float64(minBaseQty) / float64(bui.Conventional.ConversionFactor)
xcB, xcQ := getXCRate(baseSymbol), getXCRate(quoteSymbol)
minQuoteConventional := minBaseConventional * xcQ / xcB
minQuoteQty = uint64(math.Round(minQuoteConventional * float64(qui.Conventional.ConversionFactor)))

// Add registration fees.
minBaseQty += tradingTier * baseAssetCfg.BondAmt
minQuoteQty += tradingTier * quoteAssetCfg.BondAmt

maxBaseQty, maxQuoteQty = minBaseQty*2, minQuoteQty*2
return
}
Expand Down
1 change: 0 additions & 1 deletion dex/testing/loadbot/mantle.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func runTrader(t Trader, name string) {
return
}

const tradingTier = 100 // ~ 50 DCR
maintain := true
_, err = m.PostBond(&core.PostBondForm{
Addr: hostAddr,
Expand Down

0 comments on commit 8e17781

Please sign in to comment.