decred.org/dcrdex@v1.0.5/client/mm/utils.go (about) 1 package mm 2 3 import ( 4 "errors" 5 "math" 6 7 "decred.org/dcrdex/client/core" 8 "decred.org/dcrdex/client/mm/libxc" 9 "decred.org/dcrdex/dex/msgjson" 10 ) 11 12 // steppedRate rounds the rate to the nearest integer multiple of the step. 13 // The minimum returned value is step. 14 func steppedRate(r, step uint64) uint64 { 15 steps := math.Round(float64(r) / float64(step)) 16 if steps == 0 { 17 return step 18 } 19 return uint64(math.Round(steps * float64(step))) 20 } 21 22 // updateBotProblemsBasedOnError updates BotProblems based on an error 23 // encountered during market making. 24 func updateBotProblemsBasedOnError(problems *BotProblems, err error) { 25 if err == nil { 26 return 27 } 28 29 if noPeersErr, is := err.(*core.WalletNoPeersError); is { 30 if problems.NoWalletPeers == nil { 31 problems.NoWalletPeers = make(map[uint32]bool) 32 } 33 problems.NoWalletPeers[noPeersErr.AssetID] = true 34 return 35 } 36 37 if noSyncErr, is := err.(*core.WalletSyncError); is { 38 if problems.WalletNotSynced == nil { 39 problems.WalletNotSynced = make(map[uint32]bool) 40 } 41 problems.WalletNotSynced[noSyncErr.AssetID] = true 42 return 43 } 44 45 if errors.Is(err, core.ErrAccountSuspended) { 46 problems.AccountSuspended = true 47 return 48 } 49 50 var mErr *msgjson.Error 51 if errors.As(err, &mErr) && mErr.Code == msgjson.OrderQuantityTooHigh { 52 problems.UserLimitTooLow = true 53 return 54 } 55 56 if errors.Is(err, errNoBasisPrice) { 57 problems.NoPriceSource = true 58 return 59 } 60 61 if errors.Is(err, libxc.ErrUnsyncedOrderbook) { 62 problems.CEXOrderbookUnsynced = true 63 return 64 } 65 66 if errors.Is(err, errOracleFiatMismatch) { 67 problems.OracleFiatMismatch = true 68 return 69 } 70 71 problems.UnknownError = err.Error() 72 }