Skip to content

Commit

Permalink
client/{webserver,app}: Update Market Making UI
Browse files Browse the repository at this point in the history
Updates the market making UI to reflect the updated way in which market
making works. A JSON configuration file, the same that would be used by
the RPC server, is stored on disk, and the UI gives users an interactive
way to read/update the config file, and also to start/stop market making.

The updated UI includes two screens, `/mm` and `/mmsettings`. `/mm` allows
users to see each of the market for which a market maker is configured,
allows the user to add/remove market makers, and links to the `/mmsettings`
page of each market maker. The `/mmsettings` page allows users to configure
each setting of each of the market makers.

The markets page is also updated to not allow users to place orders manually
while market making is running.
  • Loading branch information
martonp committed Aug 30, 2023
1 parent c34c89e commit 0ebfe4c
Show file tree
Hide file tree
Showing 32 changed files with 3,124 additions and 1,310 deletions.
17 changes: 11 additions & 6 deletions client/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ type Config struct {
// Web creates a configuration for the webserver. This is a Config method
// instead of a WebConfig method because Language is an app-level setting used
// by both core and rpcserver.
func (cfg *Config) Web(c *core.Core, log dex.Logger, utc bool) *webserver.Config {
func (cfg *Config) Web(c *core.Core, mm *mm.MarketMaker, log dex.Logger, utc bool) *webserver.Config {
addr := cfg.WebAddr
host, _, err := net.SplitHostPort(addr)
if err == nil && host != "" {
Expand All @@ -166,8 +166,12 @@ func (cfg *Config) Web(c *core.Core, log dex.Logger, utc bool) *webserver.Config
keyFile = filepath.Join(cfg.AppData, "web.key")
}

_, _, mmCfgPath := setNet(cfg.AppData, cfg.Net.String())

return &webserver.Config{
Core: c,
MarketMaker: mm,
MMCfgPath: mmCfgPath,
Addr: cfg.WebAddr,
CustomSiteDir: cfg.SiteDir,
Logger: log,
Expand Down Expand Up @@ -288,13 +292,13 @@ func ResolveConfig(appData string, cfg *Config) error {
switch {
case cfg.Testnet:
cfg.Net = dex.Testnet
defaultDBPath, defaultLogPath = setNet(appData, "testnet")
defaultDBPath, defaultLogPath, _ = setNet(appData, "testnet")
case cfg.Simnet:
cfg.Net = dex.Simnet
defaultDBPath, defaultLogPath = setNet(appData, "simnet")
defaultDBPath, defaultLogPath, _ = setNet(appData, "simnet")
default:
cfg.Net = dex.Mainnet
defaultDBPath, defaultLogPath = setNet(appData, "mainnet")
defaultDBPath, defaultLogPath, _ = setNet(appData, "mainnet")
}
defaultHost := DefaultHostByNetwork(cfg.Net)

Expand Down Expand Up @@ -335,10 +339,11 @@ func ResolveConfig(appData string, cfg *Config) error {
// files. It returns a suggested path for the database file and a log file. If
// using a file rotator, the directory of the log filepath as parsed by
// filepath.Dir is suitable for use.
func setNet(applicationDirectory, net string) (dbPath, logPath string) {
func setNet(applicationDirectory, net string) (dbPath, logPath, mmCfgPath string) {
netDirectory := filepath.Join(applicationDirectory, net)
logDirectory := filepath.Join(netDirectory, "logs")
logFilename := filepath.Join(logDirectory, "dexc.log")
mmCfgFilename := filepath.Join(netDirectory, "mm_cfg.json")
err := os.MkdirAll(netDirectory, 0700)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create net directory: %v\n", err)
Expand All @@ -349,7 +354,7 @@ func setNet(applicationDirectory, net string) (dbPath, logPath string) {
fmt.Fprintf(os.Stderr, "failed to create log directory: %v\n", err)
os.Exit(1)
}
return filepath.Join(netDirectory, "dexc.db"), logFilename
return filepath.Join(netDirectory, "dexc.db"), logFilename, mmCfgFilename
}

// DefaultHostByNetwork accepts configured network and returns the network
Expand Down
26 changes: 22 additions & 4 deletions client/asset/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,36 @@ var (
multiFundingOpts = []*asset.ConfigOption{
{
Key: multiSplitKey,
DisplayName: "External fee rate estimates",
DisplayName: "Allow multi split",
Description: "Allow split funding transactions that pre-size outputs to " +
"prevent excessive overlock.",
IsBoolean: true,
DefaultValue: true,
},
{
Key: multiSplitBufferKey,
DisplayName: "External fee rate estimates",
DisplayName: "Multi split buffer",
Description: "Add an integer percent buffer to split output amounts to " +
"facilitate output reuse",
DefaultValue: true,
"facilitate output reuse. This is only required for quote assets.",
DefaultValue: 5,
QuoteAssetOnly: true,
DependsOn: multiSplitKey,
Range: &asset.XYRange{
Start: asset.XYRangePoint{
Label: "0%",
X: 0,
Y: 0,
},
End: asset.XYRangePoint{
Label: "100%",
X: 100,
Y: 100,
},
XUnit: "%",
YUnit: "%",
RoundX: true,
RoundY: true,
},
},
}

Expand Down
26 changes: 22 additions & 4 deletions client/asset/dcr/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,36 @@ var (
multiFundingOpts = []*asset.ConfigOption{
{
Key: multiSplitKey,
DisplayName: "External fee rate estimates",
DisplayName: "Allow multi split",
Description: "Allow split funding transactions that pre-size outputs to " +
"prevent excessive overlock.",
IsBoolean: true,
DefaultValue: true,
},
{
Key: multiSplitBufferKey,
DisplayName: "External fee rate estimates",
DisplayName: "Multi split buffer",
Description: "Add an integer percent buffer to split output amounts to " +
"facilitate output reuse",
DefaultValue: true,
"facilitate output reuse. This is only required for quote assets.",
DefaultValue: 5,
QuoteAssetOnly: true,
DependsOn: multiSplitKey,
Range: &asset.XYRange{
Start: asset.XYRangePoint{
Label: "0%",
X: 0,
Y: 0,
},
End: asset.XYRangePoint{
Label: "100%",
X: 100,
Y: 100,
},
XUnit: "%",
YUnit: "%",
RoundX: true,
RoundY: true,
},
},
}

Expand Down
9 changes: 7 additions & 2 deletions client/asset/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,13 @@ type ConfigOption struct {
Repeatable string `json:"repeatable"`
// RepeatN signals how many times text input should be repeated, replicating
// this option N times.
RepeatN int32 `json:"repeatN"`
Required bool `json:"required"`
RepeatN int32 `json:"repeatN"`
Required bool `json:"required"`
QuoteAssetOnly bool `json:"quoteAssetOnly"`
// DependsOn is the key of another config option that if is set to true,
// this config option will be shown.
DependsOn string `json:"dependsOn"`
Range *XYRange `json:"range"`

// ShowByDefault to show or not options on "hide advanced options".
ShowByDefault bool `json:"showByDefault,omitempty"`
Expand Down
10 changes: 6 additions & 4 deletions client/asset/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ type BooleanConfig struct {
// linear, e.g. y = mx + b. The value submitted to FundOrder/Swap/Redeem should
// specify the x value.
type XYRange struct {
Start XYRangePoint `json:"start"`
End XYRangePoint `json:"end"`
XUnit string `json:"xUnit"`
YUnit string `json:"yUnit"`
Start XYRangePoint `json:"start"`
End XYRangePoint `json:"end"`
XUnit string `json:"xUnit"`
YUnit string `json:"yUnit"`
RoundX bool `json:"roundX"`
RoundY bool `json:"roundY"`
}

// XYRangePoint is a point specifying the start or end of an XYRange.
Expand Down
2 changes: 1 addition & 1 deletion client/cmd/dexc-desktop/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func mainCore() error {
}()
}

webSrv, err := webserver.New(cfg.Web(clientCore, logMaker.Logger("WEB"), utc))
webSrv, err := webserver.New(cfg.Web(clientCore, marketMaker, logMaker.Logger("WEB"), utc))
if err != nil {
return fmt.Errorf("failed creating web server: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion client/cmd/dexc-desktop/app_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func mainCore() error {

// Default to serving the web interface over TLS.
cfg.WebTLS = true
webSrv, err := webserver.New(cfg.Web(clientCore, logMaker.Logger("WEB"), utc))
webSrv, err := webserver.New(cfg.Web(clientCore, marketMaker, logMaker.Logger("WEB"), utc))
if err != nil {
return fmt.Errorf("failed creating web server: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion client/cmd/dexc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func runCore(cfg *app.Config) error {
}

if !cfg.NoWeb {
webSrv, err := webserver.New(cfg.Web(clientCore, logMaker.Logger("WEB"), utc))
webSrv, err := webserver.New(cfg.Web(clientCore, marketMaker, logMaker.Logger("WEB"), utc))
if err != nil {
return fmt.Errorf("failed creating web server: %w", err)
}
Expand Down
Loading

0 comments on commit 0ebfe4c

Please sign in to comment.