Documentation
¶
Index ¶
- Constants
- Variables
- type BalanceNote
- type BookFeed
- type BookUpdate
- type Config
- type ConnEventNote
- type Core
- func (c *Core) AckNotes(ids []dex.Bytes)
- func (c *Core) AssetBalance(assetID uint32) (*WalletBalance, error)
- func (c *Core) AutoWalletConfig(assetID uint32) (map[string]string, error)
- func (c *Core) Book(dex string, base, quote uint32) (*OrderBook, error)
- func (c *Core) Cancel(pw []byte, oidB dex.Bytes) error
- func (c *Core) CloseWallet(assetID uint32) error
- func (c *Core) ConnectWallet(assetID uint32) error
- func (c *Core) CreateWallet(appPW, walletPW []byte, form *WalletForm) error
- func (c *Core) Exchanges() map[string]*Exchange
- func (c *Core) GetFee(dexAddr, certStr string) (uint64, error)
- func (c *Core) InitializeClient(pw []byte) error
- func (c *Core) IsInitialized() (bool, error)
- func (c *Core) Login(pw []byte) (*LoginResult, error)
- func (c *Core) Logout() error
- func (c *Core) Network() dex.Network
- func (c *Core) NewDepositAddress(assetID uint32) (string, error)
- func (c *Core) NotificationFeed() <-chan Notification
- func (c *Core) OpenWallet(assetID uint32, appPW []byte) error
- func (c *Core) Order(oidB dex.Bytes) (*Order, error)
- func (c *Core) Orders(filter *OrderFilter) ([]*Order, error)
- func (c *Core) PromptShutdown() bool
- func (c *Core) Ready() <-chan struct{}
- func (c *Core) ReconfigureWallet(appPW []byte, assetID uint32, cfg map[string]string) error
- func (c *Core) Register(form *RegisterForm) (*RegisterResult, error)
- func (c *Core) Run(ctx context.Context)
- func (c *Core) SetWalletPassword(appPW []byte, assetID uint32, newPW []byte) error
- func (c *Core) SupportedAssets() map[uint32]*SupportedAsset
- func (c *Core) SyncBook(host string, base, quote uint32) (*BookFeed, error)
- func (c *Core) Trade(pw []byte, form *TradeForm) (*Order, error)
- func (c *Core) User() *User
- func (c *Core) WalletSettings(assetID uint32) (map[string]string, error)
- func (c *Core) WalletState(assetID uint32) *WalletState
- func (c *Core) Wallets() []*WalletState
- func (c *Core) Withdraw(pw []byte, assetID uint32, value uint64, address string) (asset.Coin, error)
- type DEXAuthNote
- type DEXBrief
- type EpochNotification
- type Error
- type Exchange
- type ExpirationErr
- type FeeBreakdown
- type FeePaymentNote
- type LoginResult
- type Market
- type MarketOrderBook
- type Match
- type MiniOrder
- type Notification
- type Order
- type OrderBook
- type OrderFilter
- type OrderNote
- type RegisterForm
- type RegisterResult
- type RemainingUpdate
- type ServerNotifyNote
- type SupportedAsset
- type TradeForm
- type User
- type WalletBalance
- type WalletConfigNote
- type WalletForm
- type WalletState
- type WalletStateNote
- type WithdrawNote
Constants ¶
const ( NoteTypeFeePayment = "feepayment" NoteTypeWithdraw = "withdraw" NoteTypeOrder = "order" NoteTypeEpoch = "epoch" NoteTypeConnEvent = "conn" NoteTypeBalance = "balance" NoteTypeWalletConfig = "walletconfig" NoteTypeWalletState = "walletstate" NoteTypeServerNotify = "notify" )
Notifications should use the following note type strings.
const ( FreshBookAction = "book" BookOrderAction = "book_order" EpochOrderAction = "epoch_order" UnbookOrderAction = "unbook_order" )
const (
DefaultResponseTimeout = comms.DefaultResponseTimeout
)
DefaultResponseTimeout is the default timeout for responses after a request is successfully sent.
Variables ¶
var CertStore = map[string][]byte{
"dex.decred.org:7232": dexDotDecredCert,
"dex-test.ssgen.io:7232": dexTestSSGenCert,
}
Functions ¶
This section is empty.
Types ¶
type BalanceNote ¶
type BalanceNote struct { db.Notification AssetID uint32 `json:"assetID"` Balance *WalletBalance `json:"balance"` }
BalanceNote is an update to a wallet's balance.
type BookFeed ¶
type BookFeed struct { C chan *BookUpdate // contains filtered or unexported fields }
BookFeed manages a channel for receiving order book updates. The only exported field, C, is a channel on which to receive the updates as a series of *BookUpdate. It is imperative that the feeder (*BookFeed).Close() when no longer using the feed.
func NewBookFeed ¶
NewBookFeed is a constructor for a *BookFeed. The caller must Close() the feed when it's no longer being used.
type BookUpdate ¶
type BookUpdate struct { Action string `json:"action"` Host string `json:"host"` MarketID string `json:"marketID"` Payload interface{} `json:"payload"` }
BookUpdate is an order book update.
type Config ¶
type Config struct { // DBPath is a filepath to use for the client database. If the database does // not already exist, it will be created. DBPath string // Net is the current network. Net dex.Network // Logger is the Core's logger and is also used to create the sub-loggers // for the asset backends. Logger dex.Logger // TorProxy specifies the address of a Tor proxy server. TorProxy string // TorIsolation specifies whether to enable Tor circuit isolation. TorIsolation bool }
Config is the configuration for the Core.
type ConnEventNote ¶
type ConnEventNote struct { db.Notification Host string `json:"host"` Connected bool `json:"connected"` }
ConnEventNote is a notification regarding individual DEX connection status.
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core is the core client application. Core manages DEX connections, wallets, database access, match negotiation and more.
func (*Core) AssetBalance ¶
func (c *Core) AssetBalance(assetID uint32) (*WalletBalance, error)
AssetBalance retrieves and updates the current wallet balance.
func (*Core) AutoWalletConfig ¶
AutoWalletConfig attempts to load setting from a wallet package's asset.WalletInfo.DefaultConfigPath. If settings are not found, an empty map is returned.
func (*Core) Book ¶
Book fetches the order book. If a subscription doesn't exist, one will be attempted and immediately closed.
func (*Core) CloseWallet ¶
CloseWallet closes the wallet for the specified asset. The wallet cannot be closed if there are active negotiations for the asset.
func (*Core) ConnectWallet ¶
ConnectWallet connects to the wallet without unlocking.
func (*Core) CreateWallet ¶
func (c *Core) CreateWallet(appPW, walletPW []byte, form *WalletForm) error
CreateWallet creates a new exchange wallet.
func (*Core) Exchanges ¶
Exchanges returns a map of Exchange keyed by host, including a list of markets and their orders.
func (*Core) GetFee ¶
GetFee creates a connection to the specified DEX Server and fetches the registration fee. The connection is closed after the fee is retrieved. Returns an error if user is already registered to the DEX.
func (*Core) InitializeClient ¶
InitializeClient sets the initial app-wide password for the client.
func (*Core) IsInitialized ¶
IsInitialized checks if the app is already initialized.
func (*Core) Login ¶
func (c *Core) Login(pw []byte) (*LoginResult, error)
Login logs the user in, decrypting the account keys for all known DEXes.
func (*Core) NewDepositAddress ¶
NewDepositAddress retrieves a new deposit address from the specified asset's wallet, saves it to the database, and emits a notification.
func (*Core) NotificationFeed ¶
func (c *Core) NotificationFeed() <-chan Notification
NotificationFeed returns a new receiving channel for notifications. The channel has capacity 1024, and should be monitored for the lifetime of the Core. Blocking channels are silently ignored.
func (*Core) OpenWallet ¶
OpenWallet opens (unlocks) the wallet for use.
func (*Core) Orders ¶
func (c *Core) Orders(filter *OrderFilter) ([]*Order, error)
Orders fetches a batch of user orders, filtered with the provided OrderFilter.
func (*Core) PromptShutdown ¶
PromptShutdown checks if there are active orders and asks confirmation to shutdown if there are. The return value indicates if it is safe to stop Core or if the user has confirmed they want to shutdown with active orders.
func (*Core) Ready ¶
func (c *Core) Ready() <-chan struct{}
Ready returns a channel that is closed when Run completes its initialization tasks and Core becomes ready for use.
func (*Core) ReconfigureWallet ¶
ReconfigureWallet updates the wallet configuration settings.
func (*Core) Register ¶
func (c *Core) Register(form *RegisterForm) (*RegisterResult, error)
Register registers an account with a new DEX. If an error occurs while fetching the DEX configuration or creating the fee transaction, it will be returned immediately. A thread will be started to wait for the requisite confirmations and send the fee notification to the server. Any error returned from that thread is sent as a notification.
func (*Core) SetWalletPassword ¶
SetWalletPassword updates the (encrypted) password for the wallet.
func (*Core) SupportedAssets ¶
func (c *Core) SupportedAssets() map[uint32]*SupportedAsset
SupportedAssets returns a list of asset information for supported assets that may or may not have a wallet yet.
func (*Core) SyncBook ¶
SyncBook subscribes to the order book and returns the book and a BookFeed to receive order book updates. The BookFeed must be Close()d when it is no longer in use.
func (*Core) WalletSettings ¶
WalletSettings fetches the current wallet configuration details from the database.
func (*Core) WalletState ¶
func (c *Core) WalletState(assetID uint32) *WalletState
WalletState returns the *WalletState for the asset ID.
func (*Core) Wallets ¶
func (c *Core) Wallets() []*WalletState
Wallets creates a slice of WalletState for all known wallets.
type DEXAuthNote ¶
type DEXAuthNote struct { db.Notification Host string `json:"host"` Authenticated bool `json:"authenticated"` }
DEXAuthNote is a notification regarding individual DEX authentication status.
type DEXBrief ¶
type DEXBrief struct { Host string `json:"host"` AcctID string `json:"acctID"` Authed bool `json:"authed"` AuthErr string `json:"autherr,omitempty"` TradeIDs []string `json:"tradeIDs"` }
DEXBrief holds data returned from initializeDEXConnections.
type EpochNotification ¶
type EpochNotification struct { db.Notification Host string `json:"host"` MarketID string `json:"marketID"` Epoch uint64 `json:"epoch"` }
EpochNotification is a data notification that a new epoch has begun.
func (*EpochNotification) String ¶
func (on *EpochNotification) String() string
String supplements db.Notification's Stringer with the Epoch index.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is an error message and an error code.
type Exchange ¶
type Exchange struct { Host string `json:"host"` AcctID string `json:"acctID"` Markets map[string]*Market `json:"markets"` Assets map[uint32]*dex.Asset `json:"assets"` FeePending bool `json:"feePending"` Connected bool `json:"connected"` ConfsRequired uint32 `json:"confsrequired"` RegConfirms *uint32 `json:"confs,omitempty"` }
Exchange represents a single DEX with any number of markets.
type ExpirationErr ¶
type ExpirationErr string
ExpirationErr indicates that the wait.TickerQueue has expired a waiter, e.g. a reported coin was not found before the set expiration time.
func (ExpirationErr) Error ¶
func (err ExpirationErr) Error() string
Error satisfies the error interface for ExpirationErr.
type FeeBreakdown ¶
FeeBreakdown is categorized fee information.
type FeePaymentNote ¶
type FeePaymentNote struct { db.Notification Confirmations *uint32 `json:"confirmations,omitempty"` Dex string `json:"dex,omitempty"` }
FeePaymentNote is a notification regarding registration fee payment.
type LoginResult ¶
type LoginResult struct { Notifications []*db.Notification `json:"notifications"` DEXes []*DEXBrief `json:"dexes"` }
LoginResult holds data returned from Login.
type Market ¶
type Market struct { Name string `json:"name"` BaseID uint32 `json:"baseid"` BaseSymbol string `json:"basesymbol"` QuoteID uint32 `json:"quoteid"` QuoteSymbol string `json:"quotesymbol"` EpochLen uint64 `json:"epochlen"` StartEpoch uint64 `json:"startepoch"` MarketBuyBuffer float64 `json:"buybuffer"` Orders []*Order `json:"orders"` BaseOrderLocked uint64 `json:"baseorderlocked"` QuoteOrderLocked uint64 `json:"quoteorderlocked"` BaseContractLocked uint64 `json:"basecontractlocked"` QuoteContractLocked uint64 `json:"quotecontractlocked"` }
Market is market info.
type MarketOrderBook ¶
type MarketOrderBook struct { Base uint32 `json:"base"` Quote uint32 `json:"quote"` Book *OrderBook `json:"book"` }
MarketOrderBook is used as the BookUpdate's Payload with the FreshBookAction. The subscriber will likely need to translate into a JSON tagged type.
type Match ¶
type Match struct { MatchID dex.Bytes `json:"matchID"` Status order.MatchStatus `json:"status"` Revoked bool `json:"revoked"` Rate uint64 `json:"rate"` Qty uint64 `json:"qty"` Side order.MatchSide `json:"side"` FeeRate uint64 `json:"feeRate"` Swap dex.Bytes `json:"swap"` CounterSwap dex.Bytes `json:"counterSwap"` Redeem dex.Bytes `json:"redeem"` CounterRedeem dex.Bytes `json:"counterRedeem"` Refund dex.Bytes `json:"refund"` Stamp uint64 `json:"stamp"` IsCancel bool `json:"isCancel"` }
Match represents a match on an order. An order may have many matches.
type MiniOrder ¶
type MiniOrder struct { Qty float64 `json:"qty"` Rate float64 `json:"rate"` Epoch uint64 `json:"epoch,omitempty"` Sell bool `json:"sell"` Token string `json:"token"` }
MiniOrder is minimal information about an order in a market's order book.
type Notification ¶
type Notification interface { // Type is a string ID unique to the concrete type. Type() string // Subject is a short description of the notification contents. When displayed // to the user, the Subject will typically be given visual prominence. For // notifications with Severity < Poke (not meant for display), the Subject // field may be repurposed as a second-level category ID. Subject() string // Details should contain more detailed information. Details() string // Severity is the notification severity. Severity() db.Severity // Time is the notification timestamp. The timestamp is set in // db.NewNotification. Time is a UNIX timestamp, in milliseconds. Time() uint64 // Acked is true if the user has seen the notification. Acknowledgement is // recorded with (*Core).AckNotes. Acked() bool // ID should be unique, except in the case of identical copies of // db.Notification where the IDs should be the same. ID() dex.Bytes // Stamp sets the notification timestamp. If db.NewNotification is used to // construct the db.Notification, the timestamp will already be set. Stamp() // DBNote returns the underlying *db.Notification. DBNote() *db.Notification // String generates a compact human-readable representation of the // Notification that is suitable for logging. String() string }
Notification is an interface for a user notification. Notification is satisfied by db.Notification, so concrete types can embed the db type.
type Order ¶
type Order struct { Host string `json:"host"` BaseID uint32 `json:"baseID"` BaseSymbol string `json:"baseSymbol"` QuoteID uint32 `json:"quoteID"` QuoteSymbol string `json:"quoteSymbol"` MarketID string `json:"market"` Type order.OrderType `json:"type"` ID dex.Bytes `json:"id"` Stamp uint64 `json:"stamp"` Sig dex.Bytes `json:"sig"` Status order.OrderStatus `json:"status"` Epoch uint64 `json:"epoch"` Qty uint64 `json:"qty"` Sell bool `json:"sell"` Filled uint64 `json:"filled"` Matches []*Match `json:"matches"` Cancelling bool `json:"cancelling"` Canceled bool `json:"canceled"` FeesPaid *FeeBreakdown `json:"feesPaid"` FundingCoins []dex.Bytes `json:"fundingCoins"` LockedAmt uint64 `json:"lockedamt"` Rate uint64 `json:"rate"` // limit only TimeInForce order.TimeInForce `json:"tif"` // limit only }
Order is core's general type for an order. An order may be a market, limit, or cancel order. Some fields are only relevant to particular order types.
type OrderBook ¶
type OrderBook struct { Sells []*MiniOrder `json:"sells"` Buys []*MiniOrder `json:"buys"` Epoch []*MiniOrder `json:"epoch"` }
OrderBook represents an order book, which are sorted buys and sells, and unsorted epoch orders.
type OrderFilter ¶
type OrderFilter struct { N int `json:"n"` Offset dex.Bytes `json:"offset"` Hosts []string `json:"hosts"` Assets []uint32 `json:"assets"` Statuses []order.OrderStatus `json:"statuses"` }
OrderFilter is almost the same as db.OrderFilter, except the Offset order ID is a dex.Bytes instead of a order.OrderID.
type OrderNote ¶
type OrderNote struct { db.Notification Order *Order `json:"order"` }
OrderNote is a notification about an order or a match.
type RegisterForm ¶
type RegisterForm struct { Addr string `json:"url"` AppPass encode.PassBytes `json:"appPass"` Fee uint64 `json:"fee"` Cert string `json:"cert"` }
RegisterForm is information necessary to register an account on a DEX.
type RegisterResult ¶
RegisterResult holds data returned from Register.
type RemainingUpdate ¶
RemainingUpdate is an update to the quantity for an order on the order book.
type ServerNotifyNote ¶
type ServerNotifyNote struct {
db.Notification
}
ServerNotifyNote is a notification containing a server-originating message.
type SupportedAsset ¶
type SupportedAsset struct { ID uint32 `json:"id"` Symbol string `json:"symbol"` Wallet *WalletState `json:"wallet"` Info *asset.WalletInfo `json:"info"` }
SupportedAsset is data about an asset and possibly the wallet associated with it.
type TradeForm ¶
type TradeForm struct { Host string `json:"host"` IsLimit bool `json:"isLimit"` Sell bool `json:"sell"` Base uint32 `json:"base"` Quote uint32 `json:"quote"` Qty uint64 `json:"qty"` Rate uint64 `json:"rate"` TifNow bool `json:"tifnow"` }
TradeForm is used to place a market or limit order
type User ¶
type User struct { Exchanges map[string]*Exchange `json:"exchanges"` Initialized bool `json:"inited"` Assets map[uint32]*SupportedAsset `json:"assets"` }
User is information about the user's wallets and DEX accounts.
type WalletBalance ¶
type WalletBalance struct { *db.Balance // OrderLocked is the total amount of funds that is currently locked // for swap, but not actually swapped yet. This amount is also included // in the `Locked` balance value. OrderLocked uint64 `json:"orderlocked"` // ContractLocked is the total amount of funds locked in unspent // (i.e. unredeemed / unrefunded) swap contracts. ContractLocked uint64 `json:"contractlocked"` }
WalletBalance is an exchange wallet's balance which includes contractlocked amounts in addition to other balance details stored in db.
type WalletConfigNote ¶
type WalletConfigNote struct { db.Notification Wallet *WalletState `json:"wallet"` }
WalletConfigNote is a notification regarding a change in wallet configuration.
type WalletForm ¶
WalletForm is information necessary to create a new exchange wallet. The ConfigText, if provided, will be parsed for wallet connection settings.
type WalletState ¶
type WalletState struct { Symbol string `json:"symbol"` AssetID uint32 `json:"assetID"` Open bool `json:"open"` Running bool `json:"running"` Balance *WalletBalance `json:"balance"` Address string `json:"address"` Units string `json:"units"` Encrypted bool `json:"encrypted"` Synced bool `json:"synced"` SyncProgress float32 `json:"syncProgress"` }
WalletState is the current status of an exchange wallet.
type WalletStateNote ¶
type WalletStateNote WalletConfigNote
WalletStateNote is a notification regarding a change in wallet state, including: creation, locking, unlocking, and connect. This is intended to be a Data Severity notification.
type WithdrawNote ¶
type WithdrawNote struct {
db.Notification
}
WithdrawNote is a notification regarding a requested withdraw.