Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[order,matcher]: Define the Order type and begin matcher. #15

Merged
merged 11 commits into from
Sep 7, 2019
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ dcrdex
│ │ ├── admin # administrative tools and portal (may need RPC server too)
│ │ └── controller # controller for multiple markets, users, api, comms, etc.
│ ├── docs
│ ├── htttpapi # HTTP API
│ ├── market # market manager
│ │ └── order # the ubiquitous order type
│ ├── matcher # order matching engine
│ └── swap # the swap executor/coordinator
└── spec
Expand Down
20 changes: 20 additions & 0 deletions server/account/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package account

import (
"github.com/decred/dcrd/crypto/blake256"
"github.com/decred/dcrdex/server/account/pki"
)

var HashFunc = blake256.Sum256

const (
HashSize = blake256.Size
)

type AccountID [HashSize]byte

func New(pk [pki.PubKeySize]byte) AccountID {
// hash the pubkey hash(hash(pubkey))
h := HashFunc(pk[:])
return HashFunc(h[:])
}
8 changes: 8 additions & 0 deletions server/account/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/decred/dcrdex/server/account

go 1.12

require (
github.com/decred/dcrd/crypto/blake256 v1.0.0
github.com/decred/dcrd/dcrec/secp256k1 v1.0.2
)
8 changes: 8 additions & 0 deletions server/account/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dchest/blake256 v1.0.0/go.mod h1:xXNWCE1jsAP8DAjP+rKw2MbeqLczjI3TRx2VK+9OEYY=
github.com/decred/dcrd/chaincfg/chainhash v1.0.1/go.mod h1:OVfvaOsNLS/A1y4Eod0Ip/Lf8qga7VXCQjUQLbkY0Go=
github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0=
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/dcrec/secp256k1 v1.0.2 h1:awk7sYJ4pGWmtkiGHFfctztJjHMKGLV8jctGQhAbKe0=
github.com/decred/dcrd/dcrec/secp256k1 v1.0.2/go.mod h1:CHTUIVfmDDd0KFVFpNX1pFVCBUegxW387nN0IGwNKR0=
github.com/decred/dcrdex v0.0.0-20190820222222-0c633a45b26a h1:IkTp1kie2MKG5zf4nlcVsP9UXPghXUBLa8JB+T538UQ=
10 changes: 10 additions & 0 deletions server/account/pki/pki.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package pki

import "github.com/decred/dcrd/dcrec/secp256k1"

type PrivateKey = secp256k1.PrivateKey

const (
PrivKeySize = secp256k1.PrivKeyBytesLen
PubKeySize = secp256k1.PubKeyBytesLenCompressed
)
9 changes: 9 additions & 0 deletions server/market/epoch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package market

import "github.com/decred/dcrdex/server/market/order"

// TODO. PLACEHOLDER.

type EpochQueue struct {
Orders []order.Order
}
10 changes: 10 additions & 0 deletions server/market/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/decred/dcrdex/server/market

go 1.12

replace github.com/decred/dcrdex/server/account => ../account

require (
github.com/decred/dcrd/crypto/blake256 v1.0.0
github.com/decred/dcrdex/server/account v0.0.0-00010101000000-000000000000
)
9 changes: 9 additions & 0 deletions server/market/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dchest/blake256 v1.0.0/go.mod h1:xXNWCE1jsAP8DAjP+rKw2MbeqLczjI3TRx2VK+9OEYY=
github.com/decred/dcrd v1.3.0 h1:EEXm7BdiROfazDtuFsOu9mfotnyy00bgCuVwUqaszFo=
github.com/decred/dcrd/chaincfg/chainhash v1.0.1/go.mod h1:OVfvaOsNLS/A1y4Eod0Ip/Lf8qga7VXCQjUQLbkY0Go=
github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0=
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/dcrec/secp256k1 v1.0.2 h1:awk7sYJ4pGWmtkiGHFfctztJjHMKGLV8jctGQhAbKe0=
github.com/decred/dcrd/dcrec/secp256k1 v1.0.2/go.mod h1:CHTUIVfmDDd0KFVFpNX1pFVCBUegxW387nN0IGwNKR0=
github.com/decred/dcrdex v0.0.0-20190820222222-0c633a45b26a h1:IkTp1kie2MKG5zf4nlcVsP9UXPghXUBLa8JB+T538UQ=
32 changes: 32 additions & 0 deletions server/market/market.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// This code is available on the terms of the project LICENSE.md file,
// also available online at https://blueoakcouncil.org/license/1.0.0.

package market

// The Market[Manager] will:
// - Cycle the epochs. Epoch timing, the current epoch index, etc.
// - Manage multiple epochs (one active and others in various states of
// matching, swapping, or archival).
// - Receiving and validating new order data (amounts vs. lot size, check fees,
// utxos, sufficient market buy buffer, etc. with help from asset backends).
// - Putting incoming orders into the current epoch queue, which must implement
// matcher.Booker so that the order matching engine can work with it.
// - Possess an order book manager, which must also implement matcher.Booker.
// - Initiate order matching via matcher.Match(book, currentQueue)
// - During and/or after matching:
// * update the book (remove orders, add new standing orders, etc.)
chappjc marked this conversation as resolved.
Show resolved Hide resolved
// * retire/archive the epoch queue
// * publish the matches (and order book changes?)
// * initiate swaps for each match (possibly groups of related matches)
// - Continually update the order book based on data from the swap executors
// (e.g. failed swaps, partial fills?, etc.), communications hub (i.e. dropped
// clients), and other sources.
// - Recording all events with the archivist

// The Market manager should not be overly involved with details of accounts and
// authentication. Via the account package it should request account status with
// new orders, verification of order signatures. The Market should also perform
// various account package callbacks such as order status updates so that the
// account package code can keep various data up-to-date, including order
// status, history, cancellation statistics, etc.
type Market struct{} // TODO
19 changes: 19 additions & 0 deletions server/market/order/match.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This code is available on the terms of the project LICENSE.md file,
// also available online at https://blueoakcouncil.org/license/1.0.0.

package order

// Match represents the result of matching a single Taker order from the epoch
// queue with one or more standing limit orders from the book, the Makers. The
// Amounts and Rates of each limit order paired with the taker order are stored.
// The Rates slice is for convenience as each rate must match with the Maker's
// rates. However, one of the Amounts may be less than the full quantity of the
// corresponding limit order, indicating a partial fill of the Maker. The sum of
// the amounts, Total, is provided for convenience.
type Match struct {
Taker Order
Makers []*LimitOrder
Amounts []uint64
Rates []uint64
Total uint64
}
Loading