orderbook

package
v0.0.0-...-59eeb30 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

README

Orderbook module


Requirements

This module defines the required components for orderbook. Orderbook works by matching the ask and bid orders.

State
  • Order state
    • Open: means order is still pending
    • Done: means order has been executed
    • Cancel: means order has been cancelled
  • Side
    • Ask: defines trader wants to buy
    • Bid defines trader wants to sell
  • Order
    • ID
    • Trader: identity of trader
    • OrderBookID: orderbook id of this order belongs to
    • Side: side of this order
    • OrderState: defines if order is done, cancelled, or open
    • OriginalOffer: amount of offer at the time of creation
    • RemainingOffer: amount of pending trade
    • Price: price of offer
    • TradeIDs: trades that have been executed
    • CreatedAt: creation time of offer
    • UpdatedAt: update time of offer. Updated whenever order state changes
  • Trade
    • ID
    • OrderBookID: ID of the orderbook trade happened at
    • OrderID: ID of order this trade is originated
    • Taker: identity of taker that accepted to buy
    • Maker: identity of maker that accepted to sell
    • MakerPaid: amount maker paid to settle the trade
    • TakerPaid: amount taker paid to settle the trade
    • ExecutedAt: defines the trade execution time
  • Order book
    • ID
    • MarketID: market this orderbook belongs to
    • AskTicker: Ticker of ask side
    • BidTicker: Ticker of bid side
    • TotalAskCount: number of available ask orders
    • TotalBidCount: number of available bid orders
  • Market
    • ID
    • Owner: identity of owner of this market
    • Name: name of the market
Messages
  • Post order
    • MarketID: market that order is posted to
    • AskTicker: Ticker of ask side
    • BidTicker: Ticker of bid side
  • Cancel order
    • OrderID: Order that wanted to be cancelled
Order and Trade relation

Trade is full/partial offer that happened between traders

Market and Orderbook relation

The blockchain may have multiple markets. Each market may have multiple orderbooks. Each token pair can only have one orderbook per market. There is no global chain owner, but each market has one that adds orderbooks and sets fees. This could be one person, a multisig, or a governance contract (Dao)

When adding an orderbook, market with given market id is checked, then look up the owner for that market. Rather than having one owner that can create orderbooks for all markets, each market stores who can update it.

Matching engine logic

First orders are sorted in ascending or descending order. Ask orders are sorted descendently so that the element with the highest index in the array has the lowest price and buy orders are sorted in ascending order so that the last element of the array has the highest price. When an order is posted it is inserted into one of the ask order or bid order arrays.

Strategies
  • Best price offer strategy
    • When a matching order by price and amount is found order is placed instantly.
  • Partially filled order
    • If an order cannot be fulfilled entirely in one transaction, the remaining lots become a “resting order” which is included in the order book. Resting orders are prioritised and fulfilled when matching orders are received.
  • No match
    • Recieved order becomes an resting order for future trades.
  • Multiple orders with same price
    • There are multiple ways to achieve this. This section is open for discussion

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthCodec = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowCodec   = fmt.Errorf("proto: integer overflow")
)
View Source
var OrderState_name = map[int32]string{
	0: "ORDER_STATE_INVALID",
	1: "ORDER_STATE_OPEN",
	2: "ORDER_STATE_DONE",
	3: "ORDER_STATE_CANCEL",
}
View Source
var OrderState_value = map[string]int32{
	"ORDER_STATE_INVALID": 0,
	"ORDER_STATE_OPEN":    1,
	"ORDER_STATE_DONE":    2,
	"ORDER_STATE_CANCEL":  3,
}
View Source
var Side_name = map[int32]string{
	0: "SIDE_INVALID",
	1: "SIDE_ASK",
	2: "SIDE_BID",
}
View Source
var Side_value = map[string]int32{
	"SIDE_INVALID": 0,
	"SIDE_ASK":     1,
	"SIDE_BID":     2,
}

Functions

func BuildMarketIDTickersIndex

func BuildMarketIDTickersIndex(orderbook *OrderBook) []byte

BuildMarketIDTickersIndex indexByteSize = 8(MarketID) + ask ticker size + bid ticker size

func BuildOpenOrderIndex

func BuildOpenOrderIndex(order *Order) ([]byte, error)

BuildOpenOrderIndex produces a compound index like:

(OrderBookID, Side, Price) WHERE order.OrderState = Open

Stored as - 8 bytes bigendian OrderBookID, 1 byte Side, 8 byte bigendian Price.Whole, 8 byte bigendian Price.Fractional We use Price.Lexographic() to produce a lexographic ordering, such than

A.Lexographic() < B.Lexographic == A < B

This is a very nice trick to get clean range queries over sensible value ranges in a key-value store

func BuildOrderBookTimeIndex

func BuildOrderBookTimeIndex(trade *Trade) ([]byte, error)

BuildOpenOrderIndex produces 8 bytes OrderBookID || big-endian ExecutedAt This allows lexographical searches over the time ranges (or earliest or latest) of all trades within one orderbook

func NewOrderBookHandler

func NewOrderBookHandler(auth x.Authenticator) weave.Handler

NewOrderBookHandler creates a handler that allows issuer to create orderbooks. Only owner/admin of the market can issue new orderbooks

func RegisterQuery

func RegisterQuery(qr weave.QueryRouter)

RegisterQuery registers exchange buckets for querying.

func RegisterRoutes

func RegisterRoutes(r weave.Registry, auth x.Authenticator)

RegisterRoutes registers handlers for orderbook message processing.

Types

type Amount

type Amount struct {
	// Whole coins, -10^15 < integer < 10^15
	Whole int64 `protobuf:"varint,1,opt,name=whole,proto3" json:"whole,omitempty"`
	// Billionth of coins. 0 <= abs(fractional) < 10^9
	// If fractional != 0, must have same sign as integer
	Fractional int64 `protobuf:"varint,2,opt,name=fractional,proto3" json:"fractional,omitempty"`
}

Amount is like a coin.Coin but without a ticker. We use it where a ticker is impossible (like quantity) For offers where ticker is implied, we still use coin.Coin as we inherit much math from there.

TODO: work out how to multiply Amount * Coin

func NewAmount

func NewAmount(whole int64, fractional int64) Amount

NewAmount takes whole and fractional, returns Amount struct

func NewAmountp

func NewAmountp(whole int64, fractional int64) *Amount

NewAmountp takes whole and fractional, returns Amount struct pointer

func (*Amount) Clone

func (a *Amount) Clone() *Amount

Clone copies values of Amount to a new Amount struct

func (*Amount) Descriptor

func (*Amount) Descriptor() ([]byte, []int)

func (*Amount) GetFractional

func (m *Amount) GetFractional() int64

func (*Amount) GetWhole

func (m *Amount) GetWhole() int64

func (*Amount) IsNegative

func (a *Amount) IsNegative() bool

IsNegative returns true if the value is less than 0

func (*Amount) IsPositive

func (a *Amount) IsPositive() bool

IsPositive returns true if the value is greater than 0

func (*Amount) Lexographic

func (a *Amount) Lexographic() ([]byte, error)

Lexographic produces a lexographic ordering, such than

A.Lexographic() < B.Lexographic == A < B

This is a very nice trick to get clean range queries over sensible value ranges in a key-value store It is defined as 8-byte-bigendian(Whole) || 8-byte-bigendian(Fractional)

Returns an error on nil or negative amounts (which would not be lexographically ordered)

func (*Amount) Marshal

func (m *Amount) Marshal() (dAtA []byte, err error)

func (*Amount) MarshalTo

func (m *Amount) MarshalTo(dAtA []byte) (int, error)

func (*Amount) ProtoMessage

func (*Amount) ProtoMessage()

func (*Amount) Reset

func (m *Amount) Reset()

func (*Amount) Size

func (m *Amount) Size() (n int)

func (*Amount) String

func (m *Amount) String() string

func (*Amount) Unmarshal

func (m *Amount) Unmarshal(dAtA []byte) error

func (*Amount) Validate

func (a *Amount) Validate() error

Validate "borrowed" from coin.Coin

func (*Amount) XXX_DiscardUnknown

func (m *Amount) XXX_DiscardUnknown()

func (*Amount) XXX_Marshal

func (m *Amount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Amount) XXX_Merge

func (m *Amount) XXX_Merge(src proto.Message)

func (*Amount) XXX_Size

func (m *Amount) XXX_Size() int

func (*Amount) XXX_Unmarshal

func (m *Amount) XXX_Unmarshal(b []byte) error

type CancelOrderMsg

type CancelOrderMsg struct {
	Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	OrderID  []byte          `protobuf:"bytes,2,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"`
}

CancelOrderMsg will remove a standing order. It must be authorized by the trader who created the order. All remaining funds return to that address.

func (*CancelOrderMsg) Descriptor

func (*CancelOrderMsg) Descriptor() ([]byte, []int)

func (*CancelOrderMsg) GetMetadata

func (m *CancelOrderMsg) GetMetadata() *weave.Metadata

func (*CancelOrderMsg) GetOrderID

func (m *CancelOrderMsg) GetOrderID() []byte

func (*CancelOrderMsg) Marshal

func (m *CancelOrderMsg) Marshal() (dAtA []byte, err error)

func (*CancelOrderMsg) MarshalTo

func (m *CancelOrderMsg) MarshalTo(dAtA []byte) (int, error)

func (CancelOrderMsg) Path

func (CancelOrderMsg) Path() string

Path returns the routing path for this message.

func (*CancelOrderMsg) ProtoMessage

func (*CancelOrderMsg) ProtoMessage()

func (*CancelOrderMsg) Reset

func (m *CancelOrderMsg) Reset()

func (*CancelOrderMsg) Size

func (m *CancelOrderMsg) Size() (n int)

func (*CancelOrderMsg) String

func (m *CancelOrderMsg) String() string

func (*CancelOrderMsg) Unmarshal

func (m *CancelOrderMsg) Unmarshal(dAtA []byte) error

func (CancelOrderMsg) Validate

func (m CancelOrderMsg) Validate() error

Validate ensures the CancelOrderMsg is valid

func (*CancelOrderMsg) XXX_DiscardUnknown

func (m *CancelOrderMsg) XXX_DiscardUnknown()

func (*CancelOrderMsg) XXX_Marshal

func (m *CancelOrderMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*CancelOrderMsg) XXX_Merge

func (m *CancelOrderMsg) XXX_Merge(src proto.Message)

func (*CancelOrderMsg) XXX_Size

func (m *CancelOrderMsg) XXX_Size() int

func (*CancelOrderMsg) XXX_Unmarshal

func (m *CancelOrderMsg) XXX_Unmarshal(b []byte) error

type CreateOrderBookMsg

type CreateOrderBookMsg struct {
	Metadata  *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	MarketID  []byte          `protobuf:"bytes,2,opt,name=market_id,json=marketId,proto3" json:"market_id,omitempty"`
	AskTicker string          `protobuf:"bytes,3,opt,name=ask_ticker,json=askTicker,proto3" json:"ask_ticker,omitempty"`
	BidTicker string          `protobuf:"bytes,4,opt,name=bid_ticker,json=bidTicker,proto3" json:"bid_ticker,omitempty"`
}

CreateOrderBookMsg creates a new orderbook in an existing market. It must be executed by the owner of the market.

func (*CreateOrderBookMsg) Descriptor

func (*CreateOrderBookMsg) Descriptor() ([]byte, []int)

func (*CreateOrderBookMsg) GetAskTicker

func (m *CreateOrderBookMsg) GetAskTicker() string

func (*CreateOrderBookMsg) GetBidTicker

func (m *CreateOrderBookMsg) GetBidTicker() string

func (*CreateOrderBookMsg) GetMarketID

func (m *CreateOrderBookMsg) GetMarketID() []byte

func (*CreateOrderBookMsg) GetMetadata

func (m *CreateOrderBookMsg) GetMetadata() *weave.Metadata

func (*CreateOrderBookMsg) Marshal

func (m *CreateOrderBookMsg) Marshal() (dAtA []byte, err error)

func (*CreateOrderBookMsg) MarshalTo

func (m *CreateOrderBookMsg) MarshalTo(dAtA []byte) (int, error)

func (CreateOrderBookMsg) Path

func (CreateOrderBookMsg) Path() string

Path returns the routing path for this message.

func (*CreateOrderBookMsg) ProtoMessage

func (*CreateOrderBookMsg) ProtoMessage()

func (*CreateOrderBookMsg) Reset

func (m *CreateOrderBookMsg) Reset()

func (*CreateOrderBookMsg) Size

func (m *CreateOrderBookMsg) Size() (n int)

func (*CreateOrderBookMsg) String

func (m *CreateOrderBookMsg) String() string

func (*CreateOrderBookMsg) Unmarshal

func (m *CreateOrderBookMsg) Unmarshal(dAtA []byte) error

func (CreateOrderBookMsg) Validate

func (m CreateOrderBookMsg) Validate() error

Validate ensures the CreateOrderBookMsg is valid

func (*CreateOrderBookMsg) XXX_DiscardUnknown

func (m *CreateOrderBookMsg) XXX_DiscardUnknown()

func (*CreateOrderBookMsg) XXX_Marshal

func (m *CreateOrderBookMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*CreateOrderBookMsg) XXX_Merge

func (m *CreateOrderBookMsg) XXX_Merge(src proto.Message)

func (*CreateOrderBookMsg) XXX_Size

func (m *CreateOrderBookMsg) XXX_Size() int

func (*CreateOrderBookMsg) XXX_Unmarshal

func (m *CreateOrderBookMsg) XXX_Unmarshal(b []byte) error

type CreateOrderMsg

type CreateOrderMsg struct {
	Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	// Trader is the Address that will pay the offer, and get the matches.
	// Defaults to x.MainSigner() if left blank
	Trader github_com_iov_one_weave.Address `protobuf:"bytes,2,opt,name=trader,proto3,casttype=github.com/iov-one/weave.Address" json:"trader,omitempty"`
	// OrderBookID must support Offer.Ticker as one of the two sides,
	// Which side this order will be, is automatically inferred
	OrderBookID []byte `protobuf:"bytes,3,opt,name=order_book_id,json=orderBookId,proto3" json:"order_book_id,omitempty"`
	// Offer is how much will be paid
	Offer *coin.Coin `protobuf:"bytes,4,opt,name=offer,proto3" json:"offer,omitempty"`
	// Price is how much is requested for each unit of the offer token
	Price *Amount `protobuf:"bytes,5,opt,name=price,proto3" json:"price,omitempty"`
}

CreateOrderMsg will offer to sell some currency on an orderbook at a given price.

func (*CreateOrderMsg) Descriptor

func (*CreateOrderMsg) Descriptor() ([]byte, []int)

func (*CreateOrderMsg) GetMetadata

func (m *CreateOrderMsg) GetMetadata() *weave.Metadata

func (*CreateOrderMsg) GetOffer

func (m *CreateOrderMsg) GetOffer() *coin.Coin

func (*CreateOrderMsg) GetOrderBookID

func (m *CreateOrderMsg) GetOrderBookID() []byte

func (*CreateOrderMsg) GetPrice

func (m *CreateOrderMsg) GetPrice() *Amount

func (*CreateOrderMsg) GetTrader

func (*CreateOrderMsg) Marshal

func (m *CreateOrderMsg) Marshal() (dAtA []byte, err error)

func (*CreateOrderMsg) MarshalTo

func (m *CreateOrderMsg) MarshalTo(dAtA []byte) (int, error)

func (CreateOrderMsg) Path

func (CreateOrderMsg) Path() string

Path returns the routing path for this message.

func (*CreateOrderMsg) ProtoMessage

func (*CreateOrderMsg) ProtoMessage()

func (*CreateOrderMsg) Reset

func (m *CreateOrderMsg) Reset()

func (*CreateOrderMsg) Size

func (m *CreateOrderMsg) Size() (n int)

func (*CreateOrderMsg) String

func (m *CreateOrderMsg) String() string

func (*CreateOrderMsg) Unmarshal

func (m *CreateOrderMsg) Unmarshal(dAtA []byte) error

func (CreateOrderMsg) Validate

func (m CreateOrderMsg) Validate() error

Validate ensures the CreateOrderMsg is valid

func (*CreateOrderMsg) XXX_DiscardUnknown

func (m *CreateOrderMsg) XXX_DiscardUnknown()

func (*CreateOrderMsg) XXX_Marshal

func (m *CreateOrderMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*CreateOrderMsg) XXX_Merge

func (m *CreateOrderMsg) XXX_Merge(src proto.Message)

func (*CreateOrderMsg) XXX_Size

func (m *CreateOrderMsg) XXX_Size() int

func (*CreateOrderMsg) XXX_Unmarshal

func (m *CreateOrderMsg) XXX_Unmarshal(b []byte) error

type Market

type Market struct {
	Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	ID       []byte          `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
	// Owner is allowed to create new orderbooks in this Market
	Owner github_com_iov_one_weave.Address `protobuf:"bytes,3,opt,name=owner,proto3,casttype=github.com/iov-one/weave.Address" json:"owner,omitempty"`
	// Market name
	Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"`
}

A market holds many Orderbooks and is just a grouping for now. Probably we only want one market on a chain, but we could add additional rules to each market and then allow multiple.

Currently Markets can only be created in the genesis file

func (*Market) Copy

func (m *Market) Copy() orm.CloneableData

Copy produces a new copy to fulfill the Model interface

func (*Market) Descriptor

func (*Market) Descriptor() ([]byte, []int)

func (*Market) GetID

func (m *Market) GetID() []byte

func (*Market) GetMetadata

func (m *Market) GetMetadata() *weave.Metadata

func (*Market) GetName

func (m *Market) GetName() string

func (*Market) GetOwner

func (m *Market) GetOwner() github_com_iov_one_weave.Address

func (*Market) Marshal

func (m *Market) Marshal() (dAtA []byte, err error)

func (*Market) MarshalTo

func (m *Market) MarshalTo(dAtA []byte) (int, error)

func (*Market) ProtoMessage

func (*Market) ProtoMessage()

func (*Market) Reset

func (m *Market) Reset()

func (*Market) SetID

func (m *Market) SetID(id []byte) error

SetID is a minimal implementation, useful when the ID is a separate protobuf field

func (*Market) Size

func (m *Market) Size() (n int)

func (*Market) String

func (m *Market) String() string

func (*Market) Unmarshal

func (m *Market) Unmarshal(dAtA []byte) error

func (*Market) Validate

func (m *Market) Validate() error

Validate is always succesful

func (*Market) XXX_DiscardUnknown

func (m *Market) XXX_DiscardUnknown()

func (*Market) XXX_Marshal

func (m *Market) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Market) XXX_Merge

func (m *Market) XXX_Merge(src proto.Message)

func (*Market) XXX_Size

func (m *Market) XXX_Size() int

func (*Market) XXX_Unmarshal

func (m *Market) XXX_Unmarshal(b []byte) error

type MarketBucket

type MarketBucket struct {
	morm.ModelBucket
}

func NewMarketBucket

func NewMarketBucket() *MarketBucket

type Order

type Order struct {
	Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	ID       []byte          `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
	// Address of trader that created order (ad gets paid from it)
	Trader      github_com_iov_one_weave.Address `protobuf:"bytes,3,opt,name=trader,proto3,casttype=github.com/iov-one/weave.Address" json:"trader,omitempty"`
	OrderBookID []byte                           `protobuf:"bytes,4,opt,name=order_book_id,json=orderBookId,proto3" json:"order_book_id,omitempty"`
	Side        Side                             `protobuf:"varint,5,opt,name=side,proto3,enum=orderbook.Side" json:"side,omitempty"`
	OrderState  OrderState                       `protobuf:"varint,6,opt,name=order_state,json=orderState,proto3,enum=orderbook.OrderState" json:"order_state,omitempty"`
	// The amount maker want to sell/buy
	OriginalOffer *coin.Coin `protobuf:"bytes,7,opt,name=original_offer,json=originalOffer,proto3" json:"original_offer,omitempty"`
	// Remaning offer. (This part enables partially filled orders)
	RemainingOffer *coin.Coin `protobuf:"bytes,8,opt,name=remaining_offer,json=remainingOffer,proto3" json:"remaining_offer,omitempty"`
	// Price for each unit (in tickers of the opposite currency from our side)
	Price *Amount `protobuf:"bytes,9,opt,name=price,proto3" json:"price,omitempty"`
	// Executed trades (referenced ids)
	TradeIds [][]byte `protobuf:"bytes,10,rep,name=trade_ids,json=tradeIds,proto3" json:"trade_ids,omitempty"`
	// created_at defines create time of an order
	CreatedAt github_com_iov_one_weave.UnixTime `` /* 133-byte string literal not displayed */
	// updated_at defines update time of an order
	UpdatedAt github_com_iov_one_weave.UnixTime `` /* 133-byte string literal not displayed */
}

Order is a request to make a trade. We create an order for every trade request, even if it settles immediately, in order to provide history and clean auditability of the market.

func (*Order) Copy

func (o *Order) Copy() orm.CloneableData

Copy produces a new copy to fulfill the Model interface

func (*Order) Descriptor

func (*Order) Descriptor() ([]byte, []int)

func (*Order) GetCreatedAt

func (m *Order) GetCreatedAt() github_com_iov_one_weave.UnixTime

func (*Order) GetID

func (m *Order) GetID() []byte

func (*Order) GetMetadata

func (m *Order) GetMetadata() *weave.Metadata

func (*Order) GetOrderBookID

func (m *Order) GetOrderBookID() []byte

func (*Order) GetOrderState

func (m *Order) GetOrderState() OrderState

func (*Order) GetOriginalOffer

func (m *Order) GetOriginalOffer() *coin.Coin

func (*Order) GetPrice

func (m *Order) GetPrice() *Amount

func (*Order) GetRemainingOffer

func (m *Order) GetRemainingOffer() *coin.Coin

func (*Order) GetSide

func (m *Order) GetSide() Side

func (*Order) GetTradeIds

func (m *Order) GetTradeIds() [][]byte

func (*Order) GetTrader

func (m *Order) GetTrader() github_com_iov_one_weave.Address

func (*Order) GetUpdatedAt

func (m *Order) GetUpdatedAt() github_com_iov_one_weave.UnixTime

func (*Order) Marshal

func (m *Order) Marshal() (dAtA []byte, err error)

func (*Order) MarshalTo

func (m *Order) MarshalTo(dAtA []byte) (int, error)

func (*Order) ProtoMessage

func (*Order) ProtoMessage()

func (*Order) Reset

func (m *Order) Reset()

func (*Order) SetID

func (o *Order) SetID(id []byte) error

SetID is a minimal implementation, useful when the ID is a separate protobuf field

func (*Order) Size

func (m *Order) Size() (n int)

func (*Order) String

func (m *Order) String() string

func (*Order) Unmarshal

func (m *Order) Unmarshal(dAtA []byte) error

func (*Order) Validate

func (o *Order) Validate() error

Validate is always succesful

func (*Order) XXX_DiscardUnknown

func (m *Order) XXX_DiscardUnknown()

func (*Order) XXX_Marshal

func (m *Order) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Order) XXX_Merge

func (m *Order) XXX_Merge(src proto.Message)

func (*Order) XXX_Size

func (m *Order) XXX_Size() int

func (*Order) XXX_Unmarshal

func (m *Order) XXX_Unmarshal(b []byte) error

type OrderBook

type OrderBook struct {
	Metadata  *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	ID        []byte          `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
	MarketID  []byte          `protobuf:"bytes,3,opt,name=market_id,json=marketId,proto3" json:"market_id,omitempty"`
	AskTicker string          `protobuf:"bytes,4,opt,name=ask_ticker,json=askTicker,proto3" json:"ask_ticker,omitempty"`
	BidTicker string          `protobuf:"bytes,5,opt,name=bid_ticker,json=bidTicker,proto3" json:"bid_ticker,omitempty"`
	// repeated Order ask_orders = 5;
	TotalAskCount int64 `protobuf:"varint,6,opt,name=total_ask_count,json=totalAskCount,proto3" json:"total_ask_count,omitempty"`
	// repeated Order bid_orders = 7;
	TotalBidCount int64 `protobuf:"varint,7,opt,name=total_bid_count,json=totalBidCount,proto3" json:"total_bid_count,omitempty"`
}

An Orderbook lives in a market and represents a ask/bid pair. We only allow one orderbook for each pair. To avoid confusion, we enforce ask_ticker < bid_ticker so their cannot be two orderbooks for the same trading pair.

Orders and Trades must reference an orderbook and use those tickers as denominations

func (*OrderBook) Copy

func (o *OrderBook) Copy() orm.CloneableData

Copy produces a new copy to fulfill the Model interface

func (*OrderBook) Descriptor

func (*OrderBook) Descriptor() ([]byte, []int)

func (*OrderBook) GetAskTicker

func (m *OrderBook) GetAskTicker() string

func (*OrderBook) GetBidTicker

func (m *OrderBook) GetBidTicker() string

func (*OrderBook) GetID

func (m *OrderBook) GetID() []byte

func (*OrderBook) GetMarketID

func (m *OrderBook) GetMarketID() []byte

func (*OrderBook) GetMetadata

func (m *OrderBook) GetMetadata() *weave.Metadata

func (*OrderBook) GetTotalAskCount

func (m *OrderBook) GetTotalAskCount() int64

func (*OrderBook) GetTotalBidCount

func (m *OrderBook) GetTotalBidCount() int64

func (*OrderBook) Marshal

func (m *OrderBook) Marshal() (dAtA []byte, err error)

func (*OrderBook) MarshalTo

func (m *OrderBook) MarshalTo(dAtA []byte) (int, error)

func (*OrderBook) ProtoMessage

func (*OrderBook) ProtoMessage()

func (*OrderBook) Reset

func (m *OrderBook) Reset()

func (*OrderBook) SetID

func (o *OrderBook) SetID(id []byte) error

SetID is a minimal implementation, useful when the ID is a separate protobuf field

func (*OrderBook) Size

func (m *OrderBook) Size() (n int)

func (*OrderBook) String

func (m *OrderBook) String() string

func (*OrderBook) Unmarshal

func (m *OrderBook) Unmarshal(dAtA []byte) error

func (*OrderBook) Validate

func (o *OrderBook) Validate() error

Validate is always succesful

func (*OrderBook) XXX_DiscardUnknown

func (m *OrderBook) XXX_DiscardUnknown()

func (*OrderBook) XXX_Marshal

func (m *OrderBook) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*OrderBook) XXX_Merge

func (m *OrderBook) XXX_Merge(src proto.Message)

func (*OrderBook) XXX_Size

func (m *OrderBook) XXX_Size() int

func (*OrderBook) XXX_Unmarshal

func (m *OrderBook) XXX_Unmarshal(b []byte) error

type OrderBookBucket

type OrderBookBucket struct {
	morm.ModelBucket
}

func NewOrderBookBucket

func NewOrderBookBucket() *OrderBookBucket

NewOrderBookBucket initates orderbook with required indexes/ TODO remove marketIDindexer if proven unnecessary

type OrderBookHandler

type OrderBookHandler struct {
	// contains filtered or unexported fields
}

OrderBookHandler will handle creating orderbooks

func (OrderBookHandler) Check

Check just verifies it is properly formed and returns the cost of executing it.

func (OrderBookHandler) Deliver

Deliver creates an orderbook and saves if all preconditions are met

type OrderBucket

type OrderBucket struct {
	morm.ModelBucket
}

func NewOrderBucket

func NewOrderBucket() *OrderBucket

type OrderState

type OrderState int32

OrderState defines if the proposal is active

const (
	OrderState_Invalid OrderState = 0
	// Open orders can create trades
	OrderState_Open OrderState = 1
	// Done orders have been fulfilled and are empty
	OrderState_Done OrderState = 2
	// Cancelled orders were closed at the makers request before they were fulfilled
	OrderState_Cancel OrderState = 3
)

func (OrderState) EnumDescriptor

func (OrderState) EnumDescriptor() ([]byte, []int)

func (OrderState) String

func (x OrderState) String() string

type Side

type Side int32

Side determines which side of the orderbook we are on (ask or bid) This defines the appropriate ticker (ask_ticker or bid_ticker)

const (
	Side_Invalid Side = 0
	Side_Ask     Side = 1
	Side_Bid     Side = 2
)

func (Side) EnumDescriptor

func (Side) EnumDescriptor() ([]byte, []int)

func (Side) String

func (x Side) String() string

type Trade

type Trade struct {
	Metadata    *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	ID          []byte          `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
	OrderBookID []byte          `protobuf:"bytes,3,opt,name=order_book_id,json=orderBookId,proto3" json:"order_book_id,omitempty"`
	OrderID     []byte          `protobuf:"bytes,4,opt,name=order_id,json=orderId,proto3" json:"order_id,omitempty"`
	// Address of taker (this is an order that was instantly fulfilled)
	Taker github_com_iov_one_weave.Address `protobuf:"bytes,5,opt,name=taker,proto3,casttype=github.com/iov-one/weave.Address" json:"taker,omitempty"`
	// Address of maker (this is an order that was stored first before fulfillment)
	Maker github_com_iov_one_weave.Address `protobuf:"bytes,6,opt,name=maker,proto3,casttype=github.com/iov-one/weave.Address" json:"maker,omitempty"`
	// this is how much each side paid (they got the opposite one)
	MakerPaid *coin.Coin `protobuf:"bytes,7,opt,name=maker_paid,json=makerPaid,proto3" json:"maker_paid,omitempty"`
	TakerPaid *coin.Coin `protobuf:"bytes,8,opt,name=taker_paid,json=takerPaid,proto3" json:"taker_paid,omitempty"`
	// executed_at defines execution time of an order
	ExecutedAt github_com_iov_one_weave.UnixTime `` /* 135-byte string literal not displayed */
}

Trade is a settled partial/full order We store these as independent entities to help with queries to map the prices over time. They are also referenced by the Orders, so we can see how much was fulfilled.

Ask and Bid tickers are "inherited" from the orderbook

func (*Trade) Copy

func (t *Trade) Copy() orm.CloneableData

Copy produces a new copy to fulfill the Model interface

func (*Trade) Descriptor

func (*Trade) Descriptor() ([]byte, []int)

func (*Trade) GetExecutedAt

func (m *Trade) GetExecutedAt() github_com_iov_one_weave.UnixTime

func (*Trade) GetID

func (m *Trade) GetID() []byte

func (*Trade) GetMaker

func (m *Trade) GetMaker() github_com_iov_one_weave.Address

func (*Trade) GetMakerPaid

func (m *Trade) GetMakerPaid() *coin.Coin

func (*Trade) GetMetadata

func (m *Trade) GetMetadata() *weave.Metadata

func (*Trade) GetOrderBookID

func (m *Trade) GetOrderBookID() []byte

func (*Trade) GetOrderID

func (m *Trade) GetOrderID() []byte

func (*Trade) GetTaker

func (m *Trade) GetTaker() github_com_iov_one_weave.Address

func (*Trade) GetTakerPaid

func (m *Trade) GetTakerPaid() *coin.Coin

func (*Trade) Marshal

func (m *Trade) Marshal() (dAtA []byte, err error)

func (*Trade) MarshalTo

func (m *Trade) MarshalTo(dAtA []byte) (int, error)

func (*Trade) ProtoMessage

func (*Trade) ProtoMessage()

func (*Trade) Reset

func (m *Trade) Reset()

func (*Trade) SetID

func (t *Trade) SetID(id []byte) error

SetID is a minimal implementation, useful when the ID is a separate protobuf field

func (*Trade) Size

func (m *Trade) Size() (n int)

func (*Trade) String

func (m *Trade) String() string

func (*Trade) Unmarshal

func (m *Trade) Unmarshal(dAtA []byte) error

func (*Trade) Validate

func (t *Trade) Validate() error

Validate is always succesful

func (*Trade) XXX_DiscardUnknown

func (m *Trade) XXX_DiscardUnknown()

func (*Trade) XXX_Marshal

func (m *Trade) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Trade) XXX_Merge

func (m *Trade) XXX_Merge(src proto.Message)

func (*Trade) XXX_Size

func (m *Trade) XXX_Size() int

func (*Trade) XXX_Unmarshal

func (m *Trade) XXX_Unmarshal(b []byte) error

type TradeBucket

type TradeBucket struct {
	morm.ModelBucket
}

func NewTradeBucket

func NewTradeBucket() *TradeBucket

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL