Skip to content

Commit

Permalink
remove experimental. a couple other mm things (decred#2879)
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 authored Jul 24, 2024
1 parent a11d829 commit 13007eb
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 157 deletions.
12 changes: 5 additions & 7 deletions client/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,11 @@ type CoreConfig struct {

// WebConfig encapsulates the configuration needed for the web server.
type WebConfig struct {
WebAddr string `long:"webaddr" description:"HTTP server address"`
WebTLS bool `long:"webtls" description:"Use a self-signed certificate for HTTPS with the web server. This is implied for a publicly routable (not loopback or private subnet) webaddr. When changing webaddr, you mean need to delete web.cert and web.key."`
SiteDir string `long:"sitedir" description:"Path to the 'site' directory with packaged web files. Unspecified = default is good in most cases."`
NoEmbedSite bool `long:"no-embed-site" description:"Use on-disk UI files instead of embedded resources. This also reloads the html template with every request. For development purposes."`
HTTPProfile bool `long:"httpprof" description:"Start HTTP profiler on /pprof."`
Experimental bool `long:"experimental" description:"Enable experimental features"`
WebAddr string `long:"webaddr" description:"HTTP server address"`
WebTLS bool `long:"webtls" description:"Use a self-signed certificate for HTTPS with the web server. This is implied for a publicly routable (not loopback or private subnet) webaddr. When changing webaddr, you mean need to delete web.cert and web.key."`
SiteDir string `long:"sitedir" description:"Path to the 'site' directory with packaged web files. Unspecified = default is good in most cases."`
NoEmbedSite bool `long:"no-embed-site" description:"Use on-disk UI files instead of embedded resources. This also reloads the html template with every request. For development purposes."`
HTTPProfile bool `long:"httpprof" description:"Start HTTP profiler on /pprof."`
}

// LogConfig encapsulates the logging-related settings.
Expand Down Expand Up @@ -193,7 +192,6 @@ func (cfg *Config) Web(c *core.Core, mm *mm.MarketMaker, log dex.Logger, utc boo
NoEmbed: cfg.NoEmbedSite,
HttpProf: cfg.HTTPProfile,
Language: cfg.Language,
Experimental: cfg.Experimental,
}
}

Expand Down
29 changes: 13 additions & 16 deletions client/cmd/bisonw-desktop/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,23 +187,20 @@ func mainCore() error {
wg.Wait() // no-op with clean setup and shutdown
}()

var marketMaker *mm.MarketMaker
if cfg.Experimental {
// TODO: on shutdown, stop market making and wait for trades to be
// canceled.
marketMaker, err = mm.NewMarketMaker(clientCore, cfg.MMConfig.EventLogDBPath, cfg.BotConfigPath, logMaker.Logger("MM"))
if err != nil {
return fmt.Errorf("error creating market maker: %w", err)
}
cm := dex.NewConnectionMaster(marketMaker)
if err := cm.ConnectOnce(appCtx); err != nil {
return fmt.Errorf("error connecting market maker")
}
defer func() {
cancel()
cm.Wait()
}()
// TODO: on shutdown, stop market making and wait for trades to be
// canceled.
marketMaker, err := mm.NewMarketMaker(clientCore, cfg.MMConfig.EventLogDBPath, cfg.BotConfigPath, logMaker.Logger("MM"))
if err != nil {
return fmt.Errorf("error creating market maker: %w", err)
}
cm := dex.NewConnectionMaster(marketMaker)
if err := cm.ConnectOnce(appCtx); err != nil {
return fmt.Errorf("error connecting market maker")
}
defer func() {
cancel()
cm.Wait()
}()

if cfg.RPCOn {
rpcSrv, err := rpcserver.New(cfg.RPC(clientCore, marketMaker, logMaker.Logger("RPC")))
Expand Down
30 changes: 14 additions & 16 deletions client/cmd/bisonw-desktop/app_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,24 +270,22 @@ func mainCore() error {

<-clientCore.Ready()

var marketMaker *mm.MarketMaker
if cfg.Experimental {
// TODO: on shutdown, stop market making and wait for trades to be
// canceled.
marketMaker, err = mm.NewMarketMaker(clientCore, cfg.MMConfig.EventLogDBPath, cfg.MMConfig.BotConfigPath, logMaker.Logger("MM"))
if err != nil {
return fmt.Errorf("error creating market maker: %w", err)
}
cm := dex.NewConnectionMaster(marketMaker)
if err := cm.ConnectOnce(appCtx); err != nil {
return fmt.Errorf("error connecting market maker")
}
defer func() {
cancel()
cm.Wait()
}()
// TODO: on shutdown, stop market making and wait for trades to be
// canceled.
marketMaker, err := mm.NewMarketMaker(clientCore, cfg.MMConfig.EventLogDBPath, cfg.MMConfig.BotConfigPath, logMaker.Logger("MM"))
if err != nil {
return fmt.Errorf("error creating market maker: %w", err)
}
cm := dex.NewConnectionMaster(marketMaker)
if err := cm.ConnectOnce(appCtx); err != nil {
return fmt.Errorf("error connecting market maker")
}

defer func() {
cancel()
cm.Wait()
}()

if cfg.RPCOn {
rpcSrv, err := rpcserver.New(cfg.RPC(clientCore, marketMaker, logMaker.Logger("RPC")))
if err != nil {
Expand Down
11 changes: 3 additions & 8 deletions client/cmd/bisonw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,9 @@ func runCore(cfg *app.Config) error {
return fmt.Errorf("error creating client core: %w", err)
}

var marketMaker *mm.MarketMaker
if cfg.Experimental {
// TODO: on shutdown, stop market making and wait for trades to be
// canceled.
marketMaker, err = mm.NewMarketMaker(clientCore, cfg.MMConfig.EventLogDBPath, cfg.MMConfig.BotConfigPath, logMaker.Logger("MM"))
if err != nil {
return fmt.Errorf("error creating market maker: %w", err)
}
marketMaker, err := mm.NewMarketMaker(clientCore, cfg.MMConfig.EventLogDBPath, cfg.MMConfig.BotConfigPath, logMaker.Logger("MM"))
if err != nil {
return fmt.Errorf("error creating market maker: %w", err)
}

// Catch interrupt signal (e.g. ctrl+c), prompting to shutdown if the user
Expand Down
8 changes: 7 additions & 1 deletion client/mm/mm.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,14 @@ func (m *MarketMaker) Connect(ctx context.Context) (*sync.WaitGroup, error) {
m.ctx = ctx
cfg := m.defaultConfig()
for _, cexCfg := range cfg.CexConfigs {
if _, err := m.loadCEX(ctx, cexCfg); err != nil {
if c, err := m.loadCEX(ctx, cexCfg); err != nil {
m.log.Errorf("Error adding %s: %v", cexCfg.Name, err)
} else {
// Try to connect so we can update our balances and set the
// connected flag, but ignore errors.
if err := m.connectCEX(ctx, c); err != nil {
m.log.Infof("Could not connect to %q: %w", cexCfg.Name, err)
}
}
}

Expand Down
36 changes: 0 additions & 36 deletions client/rpcserver/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,12 +885,6 @@ func handleNotifications(s *RPCServer, params *RawParams) *msgjson.ResponsePaylo
}

func handleMMAvailableBalances(s *RPCServer, params *RawParams) *msgjson.ResponsePayload {
if s.mm == nil {
errMsg := "experimental flag must be set to use market making"
resErr := msgjson.NewError(msgjson.RPCStartMarketMakingError, errMsg)
return createResponse(mmAvailableBalancesRoute, nil, resErr)
}

form, err := parseMMAvailableBalancesArgs(params)
if err != nil {
return usage(mmAvailableBalancesRoute, err)
Expand All @@ -915,12 +909,6 @@ func handleMMAvailableBalances(s *RPCServer, params *RawParams) *msgjson.Respons
}

func handleStartBot(s *RPCServer, params *RawParams) *msgjson.ResponsePayload {
if s.mm == nil {
errMsg := "experimental flag must be set to use market making"
resErr := msgjson.NewError(msgjson.RPCStartMarketMakingError, errMsg)
return createResponse(startBotRoute, nil, resErr)
}

form, err := parseStartBotArgs(params)
if err != nil {
return usage(startBotRoute, err)
Expand All @@ -937,12 +925,6 @@ func handleStartBot(s *RPCServer, params *RawParams) *msgjson.ResponsePayload {
}

func handleStopBot(s *RPCServer, params *RawParams) *msgjson.ResponsePayload {
if s.mm == nil {
errMsg := "experimental flag must be set to use market making"
resErr := msgjson.NewError(msgjson.RPCStopMarketMakingError, errMsg)
return createResponse(stopBotRoute, nil, resErr)
}

mkt, err := parseStopBotArgs(params)
if err != nil {
return usage(startBotRoute, err)
Expand All @@ -959,12 +941,6 @@ func handleStopBot(s *RPCServer, params *RawParams) *msgjson.ResponsePayload {
}

func handleUpdateRunningBotCfg(s *RPCServer, params *RawParams) *msgjson.ResponsePayload {
if s.mm == nil {
errMsg := "experimental flag must be set to use market making"
resErr := msgjson.NewError(msgjson.RPCUpdateRunningBotCfgError, errMsg)
return createResponse(updateRunningBotCfgRoute, nil, resErr)
}

form, err := parseUpdateRunningBotArgs(params)
if err != nil {
return usage(updateRunningBotCfgRoute, err)
Expand Down Expand Up @@ -1010,12 +986,6 @@ func handleUpdateRunningBotCfg(s *RPCServer, params *RawParams) *msgjson.Respons
}

func handleUpdateRunningBotInventory(s *RPCServer, params *RawParams) *msgjson.ResponsePayload {
if s.mm == nil {
errMsg := "experimental flag must be set to use market making"
resErr := msgjson.NewError(msgjson.RPCUpdateRunningBotInvError, errMsg)
return createResponse(updateRunningBotCfgRoute, nil, resErr)
}

form, err := parseUpdateRunningBotInventoryArgs(params)
if err != nil {
return usage(updateRunningBotCfgRoute, err)
Expand All @@ -1032,12 +1002,6 @@ func handleUpdateRunningBotInventory(s *RPCServer, params *RawParams) *msgjson.R
}

func handleMMStatus(s *RPCServer, params *RawParams) *msgjson.ResponsePayload {
if s.mm == nil {
errMsg := "experimental flag must be set to use market making"
resErr := msgjson.NewError(msgjson.RPCMMStatusError, errMsg)
return createResponse(mmStatusRoute, nil, resErr)
}

status := s.mm.RunningBotsStatus()
return createResponse(mmStatusRoute, status, nil)
}
Expand Down
26 changes: 12 additions & 14 deletions client/webserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1531,21 +1531,19 @@ func (s *WebServer) apiUser(w http.ResponseWriter, r *http.Request) {
}

response := struct {
User *core.User `json:"user"`
Lang string `json:"lang"`
Langs []string `json:"langs"`
Inited bool `json:"inited"`
OK bool `json:"ok"`
Experimental bool `json:"experimental"`
MMStatus *mm.Status `json:"mmStatus"`
User *core.User `json:"user"`
Lang string `json:"lang"`
Langs []string `json:"langs"`
Inited bool `json:"inited"`
OK bool `json:"ok"`
MMStatus *mm.Status `json:"mmStatus"`
}{
User: u,
Lang: s.lang.Load().(string),
Langs: s.langs,
Inited: s.core.IsInitialized(),
OK: true,
Experimental: s.experimental,
MMStatus: mmStatus,
User: u,
Lang: s.lang.Load().(string),
Langs: s.langs,
Inited: s.core.IsInitialized(),
OK: true,
MMStatus: mmStatus,
}
writeJSON(w, response)
}
Expand Down
10 changes: 4 additions & 6 deletions client/webserver/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,15 @@ func (s *WebServer) sendTemplate(w http.ResponseWriter, tmplID string, data any)
// CommonArguments are common page arguments that must be supplied to every
// page to populate the <title> and <header> elements.
type CommonArguments struct {
UserInfo *userInfo
Title string
Experimental bool
UserInfo *userInfo
Title string
}

// Create the CommonArguments for the request.
func (s *WebServer) commonArgs(r *http.Request, title string) *CommonArguments {
return &CommonArguments{
UserInfo: extractUserInfo(r),
Title: title,
Experimental: s.experimental,
UserInfo: extractUserInfo(r),
Title: title,
}
}

Expand Down
9 changes: 4 additions & 5 deletions client/webserver/live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2689,11 +2689,10 @@ func TestServer(t *testing.T) {
cfg: &mm.MarketMakingConfig{},
runningBots: make(map[mm.MarketWithHost]int64),
},
Experimental: true,
Addr: "127.0.0.3:54321",
Logger: logger,
NoEmbed: true, // use files on disk, and reload on each page load
HttpProf: true,
Addr: "127.0.0.3:54321",
Logger: logger,
NoEmbed: true, // use files on disk, and reload on each page load
HttpProf: true,
})
if err != nil {
t.Fatalf("error creating server: %v", err)
Expand Down
2 changes: 0 additions & 2 deletions client/webserver/site/src/html/bodybuilder.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,10 @@
<span class="ico-settings fs16 me-2"></span>
[[[Order History]]]
</a>
{{if .Experimental}}
<a href="/mm" class="demi hoverbright plainlink d-flex align-items-center py-1 authed-only">
<span class="ico-barchart fs16 me-2"></span>
[[[Market Making]]]
</a>
{{end}}
<a href="/settings" class="demi hoverbright plainlink d-flex align-items-center py-1">
<span class="ico-settings fs16 me-2"></span>
[[[Settings]]]
Expand Down
3 changes: 0 additions & 3 deletions client/webserver/site/src/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ interface UserResponse extends APIResponse {
lang: string
langs: string[]
inited: boolean
experimental: boolean
mmStatus: MarketMakingStatus
}

Expand Down Expand Up @@ -154,7 +153,6 @@ export default class Application {
pokes: CoreNotePlus[]
langs: string[]
lang: string
experimental: boolean
mmStatus: MarketMakingStatus
inited: boolean
authed: boolean
Expand Down Expand Up @@ -311,7 +309,6 @@ export default class Application {
this.authed = Boolean(resp.user)
this.lang = resp.lang
this.langs = resp.langs
this.experimental = resp.experimental
this.mmStatus = resp.mmStatus
if (!resp.user) return
const user = resp.user
Expand Down
11 changes: 5 additions & 6 deletions client/webserver/site/src/js/mm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ class Bot extends BotMarket {
autoRebalanceSettings (): AutoRebalanceConfig {
const {
proj: { bProj, qProj, alloc }, baseFeeID, quoteFeeID, cfg: { uiConfig: { baseConfig, quoteConfig } },
baseID, quoteID, cexName, mktID, bui, qui
baseID, quoteID, cexName, mktID
} = this

const totalBase = alloc[baseID]
Expand All @@ -770,11 +770,10 @@ class Bot extends BotMarket {
}
const cex = app().mmStatus.cexes[cexName]
const mkt = cex.markets[mktID]
const [baseMinWithdraw, quoteMinWithdraw] = [mkt.baseMinWithdraw * bui.conventional.conversionFactor, mkt.quoteMinWithdraw * qui.conventional.conversionFactor]
const [minB, maxB] = [baseMinWithdraw, Math.max(baseMinWithdraw * 2, maxBase)]
const minBaseTransfer = minB + baseConfig.transferFactor * (maxB - minB)
const [minQ, maxQ] = [quoteMinWithdraw, Math.max(quoteMinWithdraw * 2, maxQuote)]
const minQuoteTransfer = minQ + quoteConfig.transferFactor * (maxQ - minQ)
const [minB, maxB] = [mkt.baseMinWithdraw, Math.max(mkt.baseMinWithdraw * 2, maxBase)]
const minBaseTransfer = Math.round(minB + baseConfig.transferFactor * (maxB - minB))
const [minQ, maxQ] = [mkt.quoteMinWithdraw, Math.max(mkt.quoteMinWithdraw * 2, maxQuote)]
const minQuoteTransfer = Math.round(minQ + quoteConfig.transferFactor * (maxQ - minQ))
return { minBaseTransfer, minQuoteTransfer }
}

Expand Down
1 change: 0 additions & 1 deletion client/webserver/site/src/js/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,6 @@ export interface Application {
assets: Record<number, SupportedAsset>
seedGenTime: number
user: User
experimental: boolean
mmStatus: MarketMakingStatus
header: HTMLElement
headerSpace: HTMLElement
Expand Down
Loading

0 comments on commit 13007eb

Please sign in to comment.