Documentation ¶
Index ¶
- Constants
- Variables
- type Amount
- func (a *Amount) Add(x, y *Amount) *Amount
- func (a Amount) Cmp(b *Amount) int
- func (a *Amount) Div(x, y *Amount) *Amount
- func (a *Amount) Dup() *Amount
- func (a Amount) Float() *big.Float
- func (a Amount) IsZero() bool
- func (a *Amount) MarshalJSON() ([]byte, error)
- func (a *Amount) Mul(x, y *Amount) (*Amount, big.Accuracy)
- func (a Amount) Reciprocal() (*Amount, big.Accuracy)
- func (a *Amount) SetExp(e int) *Amount
- func (a Amount) Sign() int
- func (a Amount) String() string
- func (a *Amount) Sub(x, y *Amount) *Amount
- func (a *Amount) UnmarshalJSON(b []byte) error
- type Order
- func (o *Order) Deduct(t *Trade) bool
- func (o *Order) Dup() *Order
- func (o *Order) IsValid() error
- func (a *Order) Matches(b *Order) *Trade
- func (o *Order) Meta() *OrderMeta
- func (a *Order) NominalAmount(amountExp int) *Amount
- func (o *Order) Reverse() *Order
- func (o *Order) SetId(orderId, brokerId string) *Order
- func (o *Order) String() string
- func (a *Order) TradeAmount(b *Order) *Amount
- type OrderFlags
- type OrderMeta
- type OrderStatus
- type OrderType
- type PairName
- type Signature
- type SignatureHeader
- type SignedObject
- type TimeId
- type TimeIdUnique
- type Trade
Constants ¶
const TimeIdDataLen = 16 // number of bytes in a timeid
Variables ¶
var ( ErrOrderIdMissing = errors.New("order id is required") ErrBrokerIdMissing = errors.New("broker id is required") ErrOrderTypeNotValid = errors.New("order type is not valid") ErrOrderStatusNotValid = errors.New("order status is not valid") ErrOrderNeedsAmount = errors.New("order amount or spend limit is required") )
Functions ¶
This section is empty.
Types ¶
type Amount ¶
type Amount struct {
// contains filtered or unexported fields
}
Amount is a fixed point value
func NewAmountFromFloat ¶
NewAmountFromFloat return a new Amount initialized with the value f stored with the specified number of decimals
func NewAmountFromFloat64 ¶
NewAmountFromFloat64 return a new Amount initialized with the value f stored with the specified number of decimals
func NewAmountFromString ¶
NewAmountFromString return a new Amount initialized with the passed string value
func (*Amount) Dup ¶ added in v0.0.11
Dup returns a copy of the Amount object so that modifying one won't affect the other
func (*Amount) MarshalJSON ¶
func (Amount) Reciprocal ¶
Reciprocal returns 1/a in a newly allocated Amount
func (*Amount) SetExp ¶ added in v0.0.2
SetExp sets the number of decimals (exponent) of the amount, truncating or adding zeroes as needed
func (*Amount) UnmarshalJSON ¶ added in v0.0.2
type Order ¶
type Order struct { OrderId string `json:"id"` // order ID assigned by the broker BrokerId string `json:"iss"` // id of the broker RequestTime uint64 `json:"iat"` // unix timestamp when the order was placed Unique *TimeId `json:"uniq,omitempty"` // unique ID allocated on order igress Pair PairName `json:"pair"` // the name of the pair the order is on Type OrderType `json:"type"` // type of order (buy or sell) Status OrderStatus `json:"status"` // new orders will always be in "pending" state Flags OrderFlags `json:"flags,omitempty"` // order flags Amount *Amount `json:"amount,omitempty"` // optional amount, if nil SpendLimit must be set Price *Amount `json:"price,omitempty"` // price, if nil this will be a market order SpendLimit *Amount `json:"spend_limit,omitempty"` // optional spending limit, if nil Amount must be set StopPrice *Amount `json:"stop_price,omitempty"` // ignored if flag Stop is not set }
func (*Order) Deduct ¶ added in v0.0.11
Deduct deducts the trade's value from the order, and return true if this order is fully consumed. Note that even if an order isn't fully consumed, it might be too low to be executed.
func (*Order) Dup ¶ added in v0.0.14
Dup returns a copy of Order including objects such as Amount duplicated
func (*Order) Matches ¶ added in v0.0.11
Matches returns a Trade if a can consume b Because b is assumed to be an open order, it must have a Price
func (*Order) NominalAmount ¶ added in v0.0.12
NominalAmount returns the order's maximum amount if one can be computed, or nil
func (*Order) TradeAmount ¶ added in v0.0.11
TradeAmount returns the order's trade amount in case it matches against b
type OrderFlags ¶
type OrderFlags int
const ( FlagImmediateOrCancel OrderFlags = 1 << iota // do not create an open order after execution FlagFillOrKill // if order can't be fully executed, cancel FlagStop )
func (OrderFlags) MarshalJSON ¶
func (f OrderFlags) MarshalJSON() ([]byte, error)
func (*OrderFlags) UnmarshalJSON ¶
func (f *OrderFlags) UnmarshalJSON(j []byte) error
type OrderStatus ¶
type OrderStatus int
const ( OrderInvalid OrderStatus = -1 OrderPending OrderStatus = iota OrderRunning OrderOpen OrderStop // pending for a trigger OrderDone OrderCancel // cancelled or overwritten order )
func OrderStatusByString ¶
func OrderStatusByString(s string) OrderStatus
func (OrderStatus) IsValid ¶
func (s OrderStatus) IsValid() bool
func (OrderStatus) MarshalJSON ¶ added in v0.0.4
func (s OrderStatus) MarshalJSON() ([]byte, error)
func (OrderStatus) String ¶
func (s OrderStatus) String() string
func (*OrderStatus) UnmarshalJSON ¶ added in v0.0.4
func (s *OrderStatus) UnmarshalJSON(b []byte) error
type OrderType ¶
type OrderType int
func OrderTypeByString ¶
func (OrderType) MarshalJSON ¶ added in v0.0.3
func (*OrderType) UnmarshalJSON ¶ added in v0.0.3
type PairName ¶
type PairName [2]string
func ParsePairName ¶ added in v0.0.13
func (*PairName) Hash ¶ added in v0.0.9
Hash returns a 32 bytes hash (sha256) representing the pair name with a nil character between the two names
func (*PairName) UnmarshalJSON ¶ added in v0.0.8
type SignatureHeader ¶ added in v0.0.7
type SignedObject ¶ added in v0.0.7
type TimeId ¶
type TimeId struct { Type string `json:"type"` // order | trade Unix uint64 `json:"unix"` // unix timestamp in seconds Nano uint32 `json:"nano"` // [0, 999999999] Index uint32 `json:"idx"` // index if multiple ids are generated with the same unix/nano values }
func NewUniqueTimeId ¶ added in v0.0.2
func NewUniqueTimeId() *TimeId
NewUniqueTimeId returns a unique (in the local process) TimeId
func (TimeId) Bytes ¶
func (t TimeId) Bytes() [TimeIdDataLen]byte
Bytes returns a 128bits bigendian sortable version of this TimeId
func (TimeId) Cmp ¶ added in v0.0.10
Cmp returns an integer comparing two TimeId time point. The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
func (TimeId) MarshalJSON ¶ added in v0.0.6
func (*TimeId) UnmarshalJSON ¶ added in v0.0.6
type TimeIdUnique ¶ added in v0.0.2
type TimeIdUnique struct {
Last TimeId
}
func (*TimeIdUnique) Unique ¶ added in v0.0.2
func (u *TimeIdUnique) Unique(t *TimeId)
Unique ensures the provided TimeId is always higher than the latest one and will update it if not the case
type Trade ¶
type Trade struct { Id *TimeId `json:"id"` // trade id Pair PairName `json:"pair"` Bid *OrderMeta `json:"bid"` Ask *OrderMeta `json:"ask"` Type OrderType `json:"type"` // taker's order type Amount *Amount `json:"amount"` Price *Amount `json:"price"` }
Trade represents a trade that happened, where two orders matched