Documentation ¶
Index ¶
- func GetHash(option *Option) (string, error)
- func NodeComparator(a, b interface{}) int
- type Book
- func (book *Book) CancelOrder(orderID uuid.UUID) (*Order, error)
- func (book *Book) CheckInitialMargin(user common.Address) (bool, decimal.Decimal, error)
- func (book *Book) CheckInitialMarginNewOrder(creator common.Address, isBuy bool, quantity decimal.Decimal, option *Option) (bool, decimal.Decimal, error)
- func (book *Book) CheckMaintenanceMargin(user common.Address) (buffer decimal.Decimal, check bool, err error)
- func (book *Book) CheckMaintenanceMarginAllAccounts() (users []common.Address, buffers []decimal.Decimal, checks []bool, err error)
- func (book *Book) CreateLimitOrder(creator common.Address, isBuy bool, quantity decimal.Decimal, ...) (order *Order, quantityLeft decimal.Decimal, err error)
- func (book *Book) CreateMarketOrder(creator common.Address, isBuy bool, quantity decimal.Decimal, option *Option, ...) (quantityLeft decimal.Decimal, err error)
- func (book *Book) GetAccount(user common.Address) (decimal.Decimal, decimal.Decimal, decimal.Decimal, decimal.Decimal, ...)
- func (book *Book) GetActiveAnnualizedTau() float64
- func (book *Book) GetActiveExpiry() uint64
- func (book *Book) GetActiveUsers() []common.Address
- func (book *Book) GetAskManager(option *Option) (*Manager, bool)
- func (book *Book) GetBidManager(option *Option) (*Manager, bool)
- func (book *Book) GetDepth(option *Option) (asks, bids []*PriceLevel, err error)
- func (book *Book) GetGreeks(isCall bool, strikeLevel shared.StrikeLevel) (decimal.Decimal, decimal.Decimal, decimal.Decimal, decimal.Decimal, ...)
- func (book *Book) GetInitialMarginNewOrder(isBuy bool, quantity decimal.Decimal, option *Option) (decimal.Decimal, error)
- func (book *Book) GetInitialMarginOrders(instance *margin.Margin, user common.Address) (decimal.Decimal, error)
- func (book *Book) GetInitialMarginPositions(instance *margin.Margin, user common.Address, decimals uint8) (decimal.Decimal, error)
- func (book *Book) GetInterestRate() (decimal.Decimal, error)
- func (book *Book) GetMaintenanceMarginPositions(instance *margin.Margin, user common.Address, decimals uint8) (decimal.Decimal, error)
- func (book *Book) GetMarginAccountBalance(instance *margin.Margin, user common.Address, decimals uint8) (decimal.Decimal, error)
- func (book *Book) GetMarginContract() (*margin.Margin, *ethclient.Client, error)
- func (book *Book) GetMark(isCall bool, strikeLevel shared.StrikeLevel, spot decimal.Decimal, ...) decimal.Decimal
- func (book *Book) GetMinQuantity() decimal.Decimal
- func (book *Book) GetOracleContract() (*oracle.Oracle, error)
- func (book *Book) GetOrderByID(orderID uuid.UUID) (*Order, error)
- func (book *Book) GetOrders(user common.Address) (orders []*Order, err error)
- func (book *Book) GetPositions(user common.Address) (positions []margin.DerivativeOrder, err error)
- func (book *Book) GetPrice(isBuy bool, quantity decimal.Decimal, option *Option) (price decimal.Decimal, err error)
- func (book *Book) GetSigma(strikeLevel shared.StrikeLevel) float64
- func (book *Book) GetSpot() (decimal.Decimal, error)
- func (book *Book) GetStrikes() [11]decimal.Decimal
- func (book *Book) GetUnderlying() shared.Underlying
- func (book *Book) GetUnrealizedPnL(instance *margin.Margin, user common.Address, decimals uint8) (decimal.Decimal, error)
- func (book *Book) IsEmpty() bool
- func (book *Book) IsValidOption(option *Option) error
- func (book *Book) LevelToStrike(level shared.StrikeLevel) decimal.Decimal
- func (book *Book) PauseOrders() error
- func (book *Book) PostMatchedOrderOnchain(requestor common.Address, isBuy bool, isTaker bool, ...) error
- func (book *Book) ProcessOrder(requestor common.Address, isBuy bool, isTaker bool, queue *Queue, ...) (partial *Order, quantityLeft decimal.Decimal, err error)
- func (book *Book) PruneOrders() error
- func (book *Book) ResetVolManager(initSigma float64, minMoneyness float64, maxMoneyness float64) error
- func (book *Book) RolloverOnchain(users []common.Address, privateKeyHex string, chainID int64) error
- func (book *Book) SetAskManager(option *Option, manager *Manager)
- func (book *Book) SetBidManager(option *Option, manager *Manager)
- func (book *Book) SettleOnchain(privateKeyHex string, chainID int64) error
- func (book *Book) UnpauseOrders() error
- func (book *Book) UpdateMarginContractData() error
- func (book *Book) UpdateVolatility(spot decimal.Decimal, interestRate decimal.Decimal, order *Order) error
- type Derivative
- func (derivative *Derivative) Append(order *Order) (*list.Element, error)
- func (derivative *Derivative) GetManager(isBuy bool, option *Option) (*Manager, bool)
- func (derivative *Derivative) Remove(ptr *list.Element) (*Order, error)
- func (derivative *Derivative) SetManager(isBuy bool, option *Option, manager *Manager)
- type Manager
- func (manager *Manager) Append(order *Order) (*list.Element, error)
- func (manager *Manager) LeftNeighborQueue(price decimal.Decimal) *Queue
- func (manager *Manager) Len() int
- func (manager *Manager) MarshalJSON() ([]byte, error)
- func (manager *Manager) MaxPriceQueue() *Queue
- func (manager *Manager) MinPriceQueue() *Queue
- func (manager *Manager) Remove(ptr *list.Element) (*Order, error)
- func (manager *Manager) RightNeighborQueue(price decimal.Decimal) *Queue
- func (manager *Manager) UnmarshalJSON(data []byte) error
- type MarginContractData
- type Option
- type OracleContractData
- type Order
- type PriceLevel
- type Queue
- func (queue *Queue) Append(order *Order) (*list.Element, error)
- func (queue *Queue) Head() *list.Element
- func (queue *Queue) Len() int
- func (queue *Queue) MarshalJSON() ([]byte, error)
- func (queue *Queue) Remove(ptr *list.Element) (*Order, error)
- func (queue *Queue) Tail() *list.Element
- func (queue *Queue) UnmarshalJSON(data []byte) error
- func (queue *Queue) Update(ptr *list.Element, order *Order) (*list.Element, error)
- type Side
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NodeComparator ¶
func NodeComparator(a, b interface{}) int
NodeComparator - Order function for RB tree
Types ¶
type Book ¶
type Book struct { // The underlying asset for this book Underlying shared.Underlying // Mapping from identifier to order pointer. These orders are across // all derivatives, sides, managers, and queues Orders map[uuid.UUID]*list.Element // Mapping from user address to open order UUIDs. Given a UUID, the pointer // can be found in "orders" UserOrderIds map[common.Address]map[uuid.UUID]bool // Storage of user addresses that enter in positions in the current round UsersWithPositions map[common.Address]bool // Pointers to the two sides Calls *Derivative Puts *Derivative // True if the book is paused Paused bool // True if the book is setteld Settled bool // Margin contract data MarginContract *MarginContractData // Oracle contract data OracleContract *OracleContractData // Volatility data VolManager *controller.VolatilityManager }
Book - Data structure for an order book Notes:
A "Book" contains two "Derivatives", one for calls and one for puts A "Derivative" contains two "Sides", one to buy and one to sell A "Side" is made up many "Managers", organized by unique option A "Manager" is made up of many "Queues", organized by price A "Queue" is made up of many "Orders", sorted by time An "Order" contains an "Option"
func CreateBook ¶
func CreateBook( underlying shared.Underlying, marginContractAddress common.Address, oracleContractAddress common.Address, ) (*Book, error)
CreateBook - Creates new book. Returns a pointer
func (*Book) CancelOrder ¶
CancelOrder - Removes order with id from order book The `orderID` must be the identifier of the order to cancel Orders can be cancelled when paused / @dev Since IM on open orders is purely additive (no netting) / we do not need to perform margin checks
func (*Book) CheckInitialMargin ¶
CheckInitialMargin - Check if the user has enough balance in their margin account on the smart contract for their open orders and positions Returns:
satisifed - true (passes check) or false (fails check) availableBalance - Amount of extra balance minus unrealized losses and margin reqs
func (*Book) CheckInitialMarginNewOrder ¶
func (book *Book) CheckInitialMarginNewOrder( creator common.Address, isBuy bool, quantity decimal.Decimal, option *Option, ) (bool, decimal.Decimal, error)
CheckInitialMarginNewOrder - Check if the user has enough margin: available balance must be higher than the margin requirements for this new order Arguments:
creator - Address of the option creator isBuy - true if buying, else false if selling quantity - Amount of the option the user is trying to buy/sell option - Option under consideration
func (*Book) CheckMaintenanceMargin ¶
func (book *Book) CheckMaintenanceMargin(user common.Address) ( buffer decimal.Decimal, check bool, err error, )
CheckMaintenanceMargin - Get the liquidation buffers for a single user Returns
buffer - Liquidation buffers for each user check - Whether user passes checks err - Error
func (*Book) CheckMaintenanceMarginAllAccounts ¶
func (book *Book) CheckMaintenanceMarginAllAccounts() ( users []common.Address, buffers []decimal.Decimal, checks []bool, err error, )
CheckMaintenanceMarginAllAccounts - Get the liquidation buffers for all active accounts Returns
users - List of active users buffers - List of liquidation buffers for each user checks - List of whether user passes checks err - Error
func (*Book) CreateLimitOrder ¶
func (book *Book) CreateLimitOrder( creator common.Address, isBuy bool, quantity decimal.Decimal, price decimal.Decimal, option *Option, privateKeyHex string, chainID int64, ) ( order *Order, quantityLeft decimal.Decimal, err error, )
CreateLimitOrder - A limit order potentially adds a new order to the book. We must check that no match exists first. If so, fulfill before adding Notes:
https://www.schwab.com/learn/story/3-order-types-market-limit-and-stop-orders
Dev:
Calls `ProcessOrder` under the hood
Arguments:
creator - Address for the creator isBuy - true (buy) or false (sell) quantity - Amount to buy or sell price - Limit price: either the maximum price to be paid or the minimum price to be received. If such a price does not exist, then no match will be executed option - A pointer to an Option object privateKeyHex - String of the master private key chainID - Ethereum chain ID
Returns:
quantityLeft - Amount of quantity in order that is not automatically fulfilled. This is the amount of quantity actually placed in the limit order err - Not nil if something went wrong internally
func (*Book) CreateMarketOrder ¶
func (book *Book) CreateMarketOrder( creator common.Address, isBuy bool, quantity decimal.Decimal, option *Option, privateKeyHex string, chainID int64, ) ( quantityLeft decimal.Decimal, err error, )
CreateMarketOrder - A market order immediately fulfills a limit order on the book Notes:
Finds the best price: buy @ lowest or sell @ highest Keeps matching until order fully fulfilled
Dev:
Calls `ProcessOrder` under the hood
Arguments:
creator - Address for the creator isBuy - true (buy) or false (sell) quantity - Amount to buy or sell option - A pointer to an Option object privateKeyHex - String of the master private key chainID - Ethereum chain ID
Returns:
quantityLeft - Amount of quantity in order that is not fulfilled err - Not nil if something went wrong internally
func (*Book) GetAccount ¶
func (book *Book) GetAccount(user common.Address) ( decimal.Decimal, decimal.Decimal, decimal.Decimal, decimal.Decimal, decimal.Decimal, decimal.Decimal, decimal.Decimal, error, )
GetAccount - Get various statistics on account health Arguments:
user (common.Address) - Address for the account to measure health of
Returns:
balance (decimal.Decimal) - Balance in margin account upnl (decimal.Decimal) - Unrealized P&L orderIM (decimal.Decimal) - Initial margin for orders positionIM (decimal.Decimal) - Initial margin for positions positionMM (deimal.Decimal) - Maintenance margin for positions availableBalance (decimal.Decimal) - Available balance for new orderes liquidationBuffer (decimal.Decimal) - Buffer until liquidation
func (*Book) GetActiveAnnualizedTau ¶
GetActiveAnnualizedTau - Get the (annualized) time to expiry
func (*Book) GetActiveExpiry ¶
GetActiveExpiry - Get the current active expiry
func (*Book) GetActiveUsers ¶
GetActiveUsers - Get all the active users
func (*Book) GetAskManager ¶
GetAskManager - Retrieves the manager for asks from underlying derivative
func (*Book) GetBidManager ¶
GetBidManager - Retrieves the manager for bids from underlying derivative
func (*Book) GetDepth ¶
func (book *Book) GetDepth(option *Option) ( asks, bids []*PriceLevel, err error, )
GetDepth - For a specific option, returns all unique prices and volumes
func (*Book) GetGreeks ¶
func (book *Book) GetGreeks( isCall bool, strikeLevel shared.StrikeLevel, ) ( decimal.Decimal, decimal.Decimal, decimal.Decimal, decimal.Decimal, decimal.Decimal, error, )
GetGreeks - Get the Black Scholes greeks Arguments:
isCall (bool) - Pricing for call or put? strikeLevel (StrikeLevel) - Chosen strike level
Returns:
delta (decimal.Decimal) gamma (decimal.Decimal) theta (decimal.Decimal) vega (decimal.Decimal) rho (decimal.Decimal)
Dev:
Spot price is fetched using the "SpotManager" Expiry is fetched from the active expiry
func (*Book) GetInitialMarginNewOrder ¶
func (book *Book) GetInitialMarginNewOrder( isBuy bool, quantity decimal.Decimal, option *Option, ) (decimal.Decimal, error)
GetInitialMarginNewOrder - Get the initial margin requirements for new order Arguments:
isBuy - true if buying, else false if selling quantity - Amount of the option the user is trying to buy/sell option - Option under consideration
func (*Book) GetInitialMarginOrders ¶
func (book *Book) GetInitialMarginOrders( instance *margin.Margin, user common.Address, ) (decimal.Decimal, error)
GetInitialMarginOrders - Get initial margin of all unmatched orders in orderbook These are NOT netted on purpose: it is expensive to open many orders. Only positions have netted margining
func (*Book) GetInitialMarginPositions ¶
func (book *Book) GetInitialMarginPositions( instance *margin.Margin, user common.Address, decimals uint8, ) (decimal.Decimal, error)
GetInitialMarginPositions - Get initial margin of all matched orders (positions) @dev Requires a smart contract call
func (*Book) GetInterestRate ¶
GetInterestRate - Get the interest rate for USDC in the book Calls the oracle smart contract through a read request
Returns:
rate (decimal.Decimal) - Median rate over data sources
func (*Book) GetMaintenanceMarginPositions ¶
func (book *Book) GetMaintenanceMarginPositions( instance *margin.Margin, user common.Address, decimals uint8, ) (decimal.Decimal, error)
GetMaintenanceMarginPositions - Get maintenance margin of all matched orders (positions) @dev Requires a smart contract call
func (*Book) GetMarginAccountBalance ¶
func (book *Book) GetMarginAccountBalance( instance *margin.Margin, user common.Address, decimals uint8, ) (decimal.Decimal, error)
GetMarginAccountBalance - Get the amount of USDC in user's margin account @dev Requires a smart contract call Arguments:
instance - Margin account instance user - Account user
func (*Book) GetMarginContract ¶
GetMarginContract - Return an instance of the margin contract
func (*Book) GetMark ¶
func (book *Book) GetMark( isCall bool, strikeLevel shared.StrikeLevel, spot decimal.Decimal, interestRate decimal.Decimal, ) decimal.Decimal
GetMark - Get the Black Scholes mark price Arguments:
isCall (bool) - Pricing for call or put? strikeLevel (StrikeLevel) - Chosen strike level spot (decimal.Decimal) - Spot price interestRate (decimal.Decimal) - Interest rate
Returns:
mark (decimal.Decimal) - Mark price
Dev:
Spot price is fetched using the "SpotManager" Expiry is fetched from the active expiry
func (*Book) GetMinQuantity ¶
GetMinQuantity - Get the minimum order quantity
func (*Book) GetOracleContract ¶
GetOracleContract - Return an instance of the oracle contract
func (*Book) GetOrderByID ¶
GetOrderByID - Returns an order by identifier
func (*Book) GetOrders ¶
GetOrders - Return unmatched order by user Arguments:
user - Address of user to look up
func (*Book) GetPositions ¶
GetPositions - Return positions (matched orders) by user Arguments:
user - Hex string of address to look up
func (*Book) GetPrice ¶
func (book *Book) GetPrice( isBuy bool, quantity decimal.Decimal, option *Option, ) ( price decimal.Decimal, err error, )
GetPrice - Gets market price for requested quantity of asset Dev:
- Simulate prices you would get over orders
- This is critically different than the Black Scholes mark price
func (*Book) GetSigma ¶
func (book *Book) GetSigma(strikeLevel shared.StrikeLevel) float64
GetSigma - Get the implied volatility for underlying in book Arguments:
strikeLevel (StrikeLevel) - Chosen strike level
Returns:
sigma (float64) - Implied volatility from nearest point in surface
Dev:
Spot price is fetched using the "SpotManager" Expiry is fetched from the active expiry
func (*Book) GetSpot ¶
GetSpot - Get the spot price for underlying in the book Calls the oracle smart contract through a read request Returns:
price (decimal.Decimal) - Median price over spot oracles
func (*Book) GetStrikes ¶
GetStrikes - Get strike prices Returns:
strikes ([11]decimal.Decimal) - 11 strike prices for current expiry
func (*Book) GetUnderlying ¶
func (book *Book) GetUnderlying() shared.Underlying
GetUnderlying - Returns the underlying asset address
func (*Book) GetUnrealizedPnL ¶
func (book *Book) GetUnrealizedPnL( instance *margin.Margin, user common.Address, decimals uint8, ) (decimal.Decimal, error)
GetUnrealizedPnL - Get realized profit and losses (losses only) @dev Requires a smart contract call
func (*Book) IsValidOption ¶
IsValidOption - Check the option object has expected underlying
func (*Book) LevelToStrike ¶
func (book *Book) LevelToStrike(level shared.StrikeLevel) decimal.Decimal
LevelToStrike - Convert strike level to decimal price
func (*Book) PostMatchedOrderOnchain ¶
func (book *Book) PostMatchedOrderOnchain( requestor common.Address, isBuy bool, isTaker bool, matchedQuantity decimal.Decimal, matchedOrder *Order, privateKeyHex string, chainID int64, ) error
PostMatchedOrderOnchain - Call smart contract function to post on-chain Arguments:
requestor - Address of the requestor isBuy - Is the request to buy or to sell isTaker - Did the request make a market order (true) or limit order (false) matchedQuantity - Amount of the order that was matched matchedOrder - The `order` object that was matched with request order - Matched order to be posted on chain privateKeyHex - String of the master private key to post on-chain chainID - Which chain to post to (int64)
func (*Book) ProcessOrder ¶
func (book *Book) ProcessOrder( requestor common.Address, isBuy bool, isTaker bool, queue *Queue, quantityRequested decimal.Decimal, option *Option, privateKeyHex string, chainID int64, ) ( partial *Order, quantityLeft decimal.Decimal, err error, )
ProcessOrder - Helper function to process an order Notes:
Called by `CreateMarketOrder` and `CreateLimitOrder` Performs a single match between request and book. If the top order does not fully satisfy the request, it does NOT automatically match next order. One should loop and call this function repeatedly if they wish to fulfill fully. A matched order in the book must also match the requested option
Arguments:
requestor - Owner of either a market or limit order that was matched with an existing order isBuy - Whether the requestor is buying or selling isTaker - Whether the requestor is making a limit or market order queue - Queue or orders at a single price quantityRequested - Amount requested to be fulfilled option - A pointer to an Option object privateKeyHex - String of the master private key chainID - Ethereum chain ID
Returns:
partial - If `quantityLeft > 0`, returns pointer to a new order that replaces the matched order. Set to nil if matched order is fulfilled fully quantityLeft - Amount in the matched order not used up by request Set to zero if matched order is fulfilled fully err - not nil if something went wrong
Dev:
Updates the volatility surface
func (*Book) PruneOrders ¶
PruneOrders - Loop through and remove expired orders
func (*Book) ResetVolManager ¶
func (book *Book) ResetVolManager( initSigma float64, minMoneyness float64, maxMoneyness float64, ) error
ResetVolManager - Hard reset for volatility manager (and the surface) By default, volatility surfaces are propagated to the next expiry
func (*Book) RolloverOnchain ¶
func (book *Book) RolloverOnchain( users []common.Address, privateKeyHex string, chainID int64, ) error
RolloverOnchain - Call `rollover` function on-chain
func (*Book) SetAskManager ¶
SetAskManager - Sets the manager for a certain ask
func (*Book) SetBidManager ¶
SetBidManager - Sets the manager for a certain bid
func (*Book) SettleOnchain ¶
SettleOnchain - Call `settle` function on-chain
func (*Book) UnpauseOrders ¶
UnpauseOrders - Unpause the order book
func (*Book) UpdateMarginContractData ¶
UpdateMarginContractData - Call margin contract to update active expiry & strike selection The book has no internal storage of either
type Derivative ¶
Derivative - Data structure representing calls and puts A single derivative holds asks and bids ("Sides")
func CreateDerivative ¶
func CreateDerivative() *Derivative
CreateDerivative - Creates a new derivative. Returns a pointer A "Derivative" object stores two sides: asks and bids
func (*Derivative) Append ¶
func (derivative *Derivative) Append(order *Order) (*list.Element, error)
Append - Add new order to derivative, and to the correct side underneat
func (*Derivative) GetManager ¶
func (derivative *Derivative) GetManager(isBuy bool, option *Option) (*Manager, bool)
GetManager - Retrieve a manager from the right side
func (*Derivative) Remove ¶
func (derivative *Derivative) Remove(ptr *list.Element) (*Order, error)
Remove - Remove an existing order
func (*Derivative) SetManager ¶
func (derivative *Derivative) SetManager(isBuy bool, option *Option, manager *Manager)
SetManager - Set the manager
type Manager ¶
type Manager struct { // Map from price (as a string) to queue Prices map[string]*Queue `json:"prices"` // Total volume in all queues Volume decimal.Decimal `json:"volume"` // Total number of orders in all queues NumOrders int `json:"numOrders"` // Amount of unique prices (size of prices map) Depth int `json:"depth"` // contains filtered or unexported fields }
Manager - A manager is responsible for an entire side of the market Controls the queues at all prices for a side
func CreateManager ¶
func CreateManager() *Manager
CreateManager - Creates new manager. Returns a pointer
func (*Manager) LeftNeighborQueue ¶
LeftNeighborQueue - Returns nearest queue with price less than threshold
func (*Manager) MarshalJSON ¶
MarshalJSON - Function to serialize queue into JSON
func (*Manager) MaxPriceQueue ¶
MaxPriceQueue - Returns queue of orders at the max price Returns nil when nothing is found
func (*Manager) MinPriceQueue ¶
MinPriceQueue - Returns queue of orders at the min price Returns nil when nothing is found
func (*Manager) RightNeighborQueue ¶
RightNeighborQueue - Returns nearest queue with price greater than threshold
func (*Manager) UnmarshalJSON ¶
UnmarshalJSON - Function to de-serialize manager from JSON
type MarginContractData ¶
type MarginContractData struct { // Address of contract DeployedAddress common.Address // The active expiry for new options ActiveExpiry int64 // The strikes for the current round RoundStrikes [11]decimal.Decimal // Minimum order size MinQuantity decimal.Decimal // Collateral decimals CollateralDecimals uint8 }
MarginContractData - Stores data from smart contracts
type Option ¶
type Option struct { // Enum of underlying Underlying shared.Underlying `json:"underlying"` // Level chosen by user Strike shared.StrikeLevel `json:"strike"` // Expiry timestamp in epoch time Expiry uint64 `json:"expiry"` // Store if this is a put or call option IsCall bool `json:"isCall"` }
Option - Stores option information
func CreateOption ¶
func CreateOption( underlying shared.Underlying, strike shared.StrikeLevel, expiry uint64, isCall bool, ) *Option
CreateOption - Create a new `Option` object, returns pointer
func (*Option) TauAnnualized ¶
TauAnnualized - Return time to expiry in years If < 0, returns 0
type OracleContractData ¶
OracleContractData - Stores data from smart contracts
type Order ¶
type Order struct { // Address of the creator Creator common.Address `json:"creator"` // Denotes buy or sell IsBuy bool `json:"isBuy"` // Unique identifier for the order ID uuid.UUID `json:"id"` // Time the order was placed in epoch time Timestamp uint64 `json:"timestamp"` // Amount in order Quantity decimal.Decimal `json:"quantity"` // Price within the order Price decimal.Decimal `json:"price"` // Contains option information Option *Option `json:"option"` // contains filtered or unexported fields }
Order - Stores order information. Wraps around an Option
func CreateOrder ¶
func CreateOrder( id uuid.UUID, creator common.Address, isBuy bool, quantity decimal.Decimal, price decimal.Decimal, timestamp uint64, option *Option, ) *Order
CreateOrder - Create a new order containing an option
type PriceLevel ¶
type PriceLevel struct { Price decimal.Decimal `json:"price"` Quantity decimal.Decimal `json:"quantity"` }
PriceLevel - Data structure used in reporting depth
type Queue ¶
type Queue struct { // List of orders sorted by timestamp Orders *list.List `json:"orders"` // Total quantity in list Volume decimal.Decimal `json:"volume"` // Price of orders in the queue Price decimal.Decimal `json:"price"` }
Queue - A queue will store orders at a single price & on one side of the market
func CreateQueue ¶
CreateQueue - Create a new `Queue` object, returns pointer
func (*Queue) Append ¶
Append - Append new order to queue. Returns pointer to new element Returns a second argument that is nil if no errors
func (*Queue) MarshalJSON ¶
MarshalJSON - Function to serialize queue into JSON
func (*Queue) Remove ¶
Remove - Removes order from queue using pointer Returns a second argument that is nil if no errors
func (*Queue) UnmarshalJSON ¶
UnmarshalJSON - Function to de-serialize queue from JSON
type Side ¶
Side - Data structure to hold managers of different expiries/strikes
func (*Side) GetManager ¶
GetManager - Given an option, look up the manager for it
func (*Side) SetManager ¶
SetManager - Set the manager for a side