Skip to content

Commit

Permalink
Event Log and display status on page
Browse files Browse the repository at this point in the history
  • Loading branch information
martonp committed Jul 30, 2023
1 parent 827fce1 commit bb4dd0c
Show file tree
Hide file tree
Showing 33 changed files with 2,836 additions and 471 deletions.
32 changes: 23 additions & 9 deletions client/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ type LogConfig struct {
LocalLogs bool `long:"loglocal" description:"Use local time zone time stamps in log entries."`
}

// MMConfig encapsulates the settings related to market making.
type MMConfig struct {
EventLogDBPath string `long:"eventlogdb" description:"Event log database filepath. Database will be created if it does not exist."`
MMConfigPath string `long:"mmconfig" description:"Market making configuration filepath. File will be created if it does not exist."`
}

// Config is the common application configuration definition. This composite
// struct captures the configuration needed for core and both web and rpc
// servers, as well as some application-level directives.
Expand All @@ -127,6 +133,7 @@ type Config struct {
RPCConfig
WebConfig
LogConfig
MMConfig
// AppData and ConfigPath should be parsed from the command-line,
// as it makes no sense to set these in the config file itself. If no values
// are assigned, defaults will be used.
Expand Down Expand Up @@ -164,12 +171,10 @@ func (cfg *Config) Web(c *core.Core, mm *mm.MarketMaker, log dex.Logger, utc boo
keyFile = filepath.Join(cfg.AppData, "web.key")
}

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

return &webserver.Config{
Core: c,
MarketMaker: mm,
MMCfgPath: mmCfgPath,
MMCfgPath: cfg.MMConfigPath,
Addr: cfg.WebAddr,
CustomSiteDir: cfg.SiteDir,
Logger: log,
Expand Down Expand Up @@ -285,17 +290,17 @@ func ResolveConfig(appData string, cfg *Config) error {

cfg.AppData = appData

var defaultDBPath, defaultLogPath string
var defaultDBPath, defaultLogPath, defaultMMEventLogDBPath, defaultMMCfgFile string
switch {
case cfg.Testnet:
cfg.Net = dex.Testnet
defaultDBPath, defaultLogPath, _ = setNet(appData, "testnet")
defaultDBPath, defaultLogPath, defaultMMEventLogDBPath, defaultMMCfgFile = setNet(appData, "testnet")
case cfg.Simnet:
cfg.Net = dex.Simnet
defaultDBPath, defaultLogPath, _ = setNet(appData, "simnet")
defaultDBPath, defaultLogPath, defaultMMEventLogDBPath, defaultMMCfgFile = setNet(appData, "simnet")
default:
cfg.Net = dex.Mainnet
defaultDBPath, defaultLogPath, _ = setNet(appData, "mainnet")
defaultDBPath, defaultLogPath, defaultMMEventLogDBPath, defaultMMCfgFile = setNet(appData, "mainnet")
}
defaultHost := DefaultHostByNetwork(cfg.Net)

Expand Down Expand Up @@ -329,17 +334,26 @@ func ResolveConfig(appData string, cfg *Config) error {
cfg.NoEmbedSite = cfg.ReloadHTML
}

if cfg.MMConfigPath == "" {
cfg.MMConfigPath = defaultMMCfgFile
}

if cfg.EventLogDBPath == "" {
cfg.EventLogDBPath = defaultMMEventLogDBPath
}

return nil
}

// setNet sets the filepath for the network directory and some network specific
// 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, mmCfgPath string) {
func setNet(applicationDirectory, net string) (dbPath, logPath, mmEventLogDBPath, mmCfgPath string) {
netDirectory := filepath.Join(applicationDirectory, net)
logDirectory := filepath.Join(netDirectory, "logs")
logFilename := filepath.Join(logDirectory, "dexc.log")
mmEventLogDBPath = filepath.Join(netDirectory, "mm_eventlog.db")
mmCfgFilename := filepath.Join(netDirectory, "mm_cfg.json")
err := os.MkdirAll(netDirectory, 0700)
if err != nil {
Expand All @@ -351,7 +365,7 @@ func setNet(applicationDirectory, net string) (dbPath, logPath, mmCfgPath string
fmt.Fprintf(os.Stderr, "failed to create log directory: %v\n", err)
os.Exit(1)
}
return filepath.Join(netDirectory, "dexc.db"), logFilename, mmCfgFilename
return filepath.Join(netDirectory, "dexc.db"), logFilename, mmEventLogDBPath, mmCfgFilename
}

// DefaultHostByNetwork accepts configured network and returns the network
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 @@ -184,7 +184,7 @@ func mainCore() error {
if cfg.Experimental {
// TODO: on shutdown, stop market making and wait for trades to be
// canceled.
marketMaker, err = mm.NewMarketMaker(clientCore, logMaker.Logger("MM"))
marketMaker, err = mm.NewMarketMaker(clientCore, logMaker.Logger("MM"), cfg.EventLogDBPath)
if err != nil {
return fmt.Errorf("error creating market maker: %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 @@ -242,7 +242,7 @@ func mainCore() error {
if cfg.Experimental {
// TODO: on shutdown, stop market making and wait for trades to be
// canceled.
marketMaker, err = mm.NewMarketMaker(clientCore, logMaker.Logger("MM"))
marketMaker, err = mm.NewMarketMaker(clientCore, logMaker.Logger("MM"), cfg.EventLogDBPath)
if err != nil {
return fmt.Errorf("error creating market maker: %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 @@ -99,7 +99,7 @@ func runCore(cfg *app.Config) error {
if cfg.Experimental {
// TODO: on shutdown, stop market making and wait for trades to be
// canceled.
marketMaker, err = mm.NewMarketMaker(clientCore, logMaker.Logger("MM"))
marketMaker, err = mm.NewMarketMaker(clientCore, logMaker.Logger("MM"), cfg.EventLogDBPath)
if err != nil {
return fmt.Errorf("error creating market maker: %w", err)
}
Expand Down
8 changes: 0 additions & 8 deletions client/mm/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package mm

import (
"fmt"
)

// MarketMakingWithCEXConfig is the configuration for a market
// maker that places orders on both sides of the order book, but
// only if there is profitable counter-trade on the CEX
Expand Down Expand Up @@ -51,7 +47,3 @@ func (c *BotConfig) requiresPriceOracle() bool {
}
return false
}

func dexMarketID(host string, base, quote uint32) string {
return fmt.Sprintf("%s-%d-%d", host, base, quote)
}
Loading

0 comments on commit bb4dd0c

Please sign in to comment.