Documentation ¶
Index ¶
- Constants
- func DisableLog()
- func UseLogger(logger slog.Logger)
- type AssetConf
- type DBConf
- type DEX
- func (dm *DEX) AccountInfo(aid account.AccountID) (*db.Account, error)
- func (dm *DEX) Accounts() ([]*db.Account, error)
- func (dm *DEX) Asset(id uint32) (*asset.BackedAsset, error)
- func (dm *DEX) BookOrders(base, quote uint32) ([]*order.LimitOrder, error)
- func (dm *DEX) ConfigMsg() json.RawMessage
- func (dm *DEX) EnableDataAPI(yes bool)
- func (dm *DEX) EpochOrders(base, quote uint32) ([]order.Order, error)
- func (dm *DEX) ForgiveMatchFail(aid account.AccountID, mid order.MatchID) (forgiven, unbanned bool, err error)
- func (dm *DEX) MarketMatches(base, quote uint32) ([]*MatchData, error)
- func (dm *DEX) MarketMatchesStreaming(base, quote uint32, includeInactive bool, N int64, f func(*MatchData) error) (int, error)
- func (dm *DEX) MarketRunning(mktName string) (found, running bool)
- func (dm *DEX) MarketStatus(mktName string) *market.Status
- func (dm *DEX) MarketStatuses() map[string]*market.Status
- func (dm *DEX) Notify(acctID account.AccountID, msg *msgjson.Message)
- func (dm *DEX) NotifyAll(msg *msgjson.Message)
- func (dm *DEX) Penalize(aid account.AccountID, rule account.Rule, details string) error
- func (dm *DEX) ResumeMarket(name string, asSoonAs time.Time) (startEpoch int64, startTime time.Time, err error)
- func (dm *DEX) ScaleFeeRate(assetID uint32, rate uint64) uint64
- func (dm *DEX) SetFeeRateScale(assetID uint32, scale float64)
- func (dm *DEX) Stop()
- func (dm *DEX) SuspendMarket(name string, tSusp time.Time, persistBooks bool) (suspEpoch *market.SuspendEpoch, err error)
- func (dm *DEX) Unban(aid account.AccountID) error
- type DexConf
- type FeeManager
- type MatchData
- type RPCConfig
Constants ¶
const ( // PreAPIVersion covers all API iterations before versioning started. PreAPIVersion = iota // APIVersion is the current API version. APIVersion = PreAPIVersion )
Variables ¶
This section is empty.
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.
Types ¶
type AssetConf ¶
type AssetConf struct { Symbol string `json:"bip44symbol"` Network string `json:"network"` LotSize uint64 `json:"lotSize"` RateStep uint64 `json:"rateStep"` MaxFeeRate uint64 `json:"maxFeeRate"` SwapConf uint32 `json:"swapConf"` ConfigPath string `json:"configPath"` }
AssetConf is like dex.Asset except it lacks the BIP44 integer ID and implementation version, has Network and ConfigPath strings, and has JSON tags.
type DBConf ¶
type DBConf struct { DBName string User string Pass string Host string Port uint16 ShowPGConfig bool }
DBConf groups the database configuration parameters.
type DEX ¶
type DEX struct {
// contains filtered or unexported fields
}
DEX is the DEX manager, which creates and controls the lifetime of all components of the DEX.
func NewDEX ¶
NewDEX creates the dex manager and starts all subsystems. Use Stop to shutdown cleanly. The Context is used to abort setup.
- Validate each specified asset.
- Create CoinLockers for each asset.
- Create and start asset backends.
- Create the archivist and connect to the storage backend.
- Create the authentication manager.
- Create and start the Swapper.
- Create and start the markets.
- Create and start the book router, and create the order router.
- Create and start the comms server.
func (*DEX) AccountInfo ¶
AccountInfo returns data for an account.
func (*DEX) Asset ¶
func (dm *DEX) Asset(id uint32) (*asset.BackedAsset, error)
Asset retrieves an asset backend by its ID.
func (*DEX) BookOrders ¶ added in v0.2.0
func (dm *DEX) BookOrders(base, quote uint32) ([]*order.LimitOrder, error)
BookOrders returns booked orders for market with base and quote.
func (*DEX) ConfigMsg ¶
func (dm *DEX) ConfigMsg() json.RawMessage
Config returns the current dex configuration.
func (*DEX) EnableDataAPI ¶ added in v0.2.0
EnableDataAPI can be called via admin API to enable or disable the HTTP data API endpoints.
func (*DEX) EpochOrders ¶ added in v0.2.0
EpochOrders returns epoch orders for market with base and quote.
func (*DEX) ForgiveMatchFail ¶
func (dm *DEX) ForgiveMatchFail(aid account.AccountID, mid order.MatchID) (forgiven, unbanned bool, err error)
ForgiveMatchFail forgives a user for a specific match failure, potentially allowing them to resume trading if their score becomes passing.
func (*DEX) MarketMatches ¶ added in v0.2.0
MarketMatches returns matches for market with base and quote.
func (*DEX) MarketMatchesStreaming ¶ added in v0.2.0
func (dm *DEX) MarketMatchesStreaming(base, quote uint32, includeInactive bool, N int64, f func(*MatchData) error) (int, error)
MarketMatchesStreaming streams all matches for market with base and quote.
func (*DEX) MarketRunning ¶
TODO: for just market running status, the DEX manager should use its knowledge of Market subsystem state.
func (*DEX) MarketStatus ¶
MarketStatus returns the market.Status for the named market. If the market is unknown to the DEX, nil is returned.
func (*DEX) MarketStatuses ¶
MarketStatuses returns a map of market names to market.Status for all known markets.
func (*DEX) Penalize ¶
Penalize bans an account by canceling the client's orders and setting their rule status to rule.
func (*DEX) ResumeMarket ¶
func (dm *DEX) ResumeMarket(name string, asSoonAs time.Time) (startEpoch int64, startTime time.Time, err error)
ResumeMarket launches a stopped market subsystem as early as the given time. The actual time the market will resume depends on the configure epoch duration, as the market only starts at the beginning of an epoch.
func (*DEX) ScaleFeeRate ¶
ScaleFeeRate scales the provided fee rate with the given asset's swap fee rate scale factor, which is 1.0 by default.
func (*DEX) SetFeeRateScale ¶
SetFeeRateScale specifies a scale factor that the Swapper should use to scale the optimal fee rates for new swaps for for the specified asset. That is, values above 1 increase the fee rate, while values below 1 decrease it.
func (*DEX) Stop ¶
func (dm *DEX) Stop()
Stop shuts down the DEX. Stop returns only after all components have completed their shutdown.
func (*DEX) SuspendMarket ¶
func (dm *DEX) SuspendMarket(name string, tSusp time.Time, persistBooks bool) (suspEpoch *market.SuspendEpoch, err error)
SuspendMarket schedules a suspension of a given market, with the option to persist the orders on the book (or purge the book automatically on market shutdown). The scheduled final epoch and suspend time are returned. This is a passthrough to the OrderRouter. A TradeSuspension notification is broadcasted to all connected clients.
type DexConf ¶
type DexConf struct { DataDir string LogBackend *dex.LoggerMaker Markets []*dex.MarketInfo Assets []*AssetConf Network dex.Network DBConf *DBConf RegFeeXPub string RegFeeConfirms int64 RegFeeAmount uint64 BroadcastTimeout time.Duration CancelThreshold float64 Anarchy bool FreeCancels bool BanScore uint32 InitTakerLotLimit uint32 AbsTakerLotLimit uint32 DEXPrivKey *secp256k1.PrivateKey CommsCfg *RPCConfig NoResumeSwaps bool }
DexConf is the configuration data required to create a new DEX.
type FeeManager ¶ added in v0.2.0
type FeeManager struct {
// contains filtered or unexported fields
}
FeeManager manages fee fetchers and a fee cache.
func NewFeeManager ¶ added in v0.2.0
func NewFeeManager() *FeeManager
NewFeeManager is the constructor for a FeeManager.
func (*FeeManager) AddFetcher ¶ added in v0.2.0
func (m *FeeManager) AddFetcher(asset *asset.BackedAsset)
AddFetcher adds a fee fetcher (a *BackedAsset) and primes the cache. The asset's MaxFeeRate are used to limit the rates returned by the LastRate method as well as the rates returned by child FeeFetchers.
func (*FeeManager) FeeFetcher ¶ added in v0.2.0
func (m *FeeManager) FeeFetcher(assetID uint32) market.FeeFetcher
FeeFetcher creates and returns an asset-specific fetcher that satisfies market.FeeFetcher, implemented by *feeFetcher.
func (*FeeManager) LastRate ¶ added in v0.2.0
func (m *FeeManager) LastRate(assetID uint32) uint64
LastRate is the last rate cached for the specified asset.