cxdbsql

package
v0.0.0-...-7ad0b1f Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: MIT Imports: 17 Imported by: 0

README

cxdbsql

Build Status License GoDoc

The cxdbsql packages implements any storage interfaces defined in cxdb, as well as some interfaces in match using MySQL. We may want to move all remaining interfaces from cxdb to match

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateAuctionEngine

func CreateAuctionEngine(pair *match.Pair) (engine match.AuctionEngine, err error)

CreateAuctionEngine creates a SQL Auction Engine as an auction matching engine, with the default conf

func CreateAuctionEngineMap

func CreateAuctionEngineMap(pairList []*match.Pair) (aucMap map[match.Pair]match.AuctionEngine, err error)

CreateAuctionEngineMap creates a map of pair to auction engine, given a list of pairs.

func CreateAuctionEngineWithConf

func CreateAuctionEngineWithConf(pair *match.Pair, conf *dbsqlConfig) (engine match.AuctionEngine, err error)

CreateAuctionEngineWithConf creates an auction engine, sets up the connection and tables, and returns the auctionengine interface.

func CreateAuctionOrderbook

func CreateAuctionOrderbook(pair *match.Pair) (book match.AuctionOrderbook, err error)

CreateAuctionOrderbook creates a auction orderbook based on a pair

func CreateAuctionOrderbookMap

func CreateAuctionOrderbookMap(pairList []*match.Pair) (aucMap map[match.Pair]match.AuctionOrderbook, err error)

CreateAuctionOrderbookMap creates a map of pair to auction engine, given a list of pairs.

func CreateDepositStore

func CreateDepositStore(coin *coinparam.Params) (store cxdb.DepositStore, err error)

func CreateDepositStoreMap

func CreateDepositStoreMap(coinList []*coinparam.Params) (depositMap map[*coinparam.Params]cxdb.DepositStore, err error)

CreateDepositStoreMap creates a map of pair to deposit store, given a list of pairs.

func CreateLimitEngine

func CreateLimitEngine(pair *match.Pair) (engine match.LimitEngine, err error)

CreateLimitEngine creates a limit matching engine that operates using SQL as a database

func CreateLimitEngineMap

func CreateLimitEngineMap(pairList []*match.Pair) (limMap map[match.Pair]match.LimitEngine, err error)

CreateLimitEngineMap creates a map of pair to limit engine, given a list of pairs.

func CreateLimitEngineWithConf

func CreateLimitEngineWithConf(pair *match.Pair, conf *dbsqlConfig) (engine match.LimitEngine, err error)

func CreateLimitOrderbook

func CreateLimitOrderbook(pair *match.Pair) (book match.LimitOrderbook, err error)

CreateLimitOrderbook creates a limit orderbook based on a pair

func CreateLimitOrderbookMap

func CreateLimitOrderbookMap(pairList []*match.Pair) (orderbookMap map[match.Pair]match.LimitOrderbook, err error)

CreateLimitOrderbookMap creates a map of pair to deposit store, given a list of pairs.

func CreatePuzzleStore

func CreatePuzzleStore(pair *match.Pair) (store cxdb.PuzzleStore, err error)

CreatePuzzleStore creates a puzzle store for a specific coin.

func CreatePuzzleStoreMap

func CreatePuzzleStoreMap(pairList []*match.Pair) (pzMap map[match.Pair]cxdb.PuzzleStore, err error)

CreatePuzzleStoreMap creates a map of pair to pair list, given a list of pairs.

func CreateSettlementEngine

func CreateSettlementEngine(coin *coinparam.Params) (engine match.SettlementEngine, err error)

CreateSettlementEngine creates a settlement engine for a specific coin

func CreateSettlementEngineMap

func CreateSettlementEngineMap(coins []*coinparam.Params) (setMap map[*coinparam.Params]match.SettlementEngine, err error)

CreateSettlementEngineMap creates a map of coin to settlement engine, given a list of coins.

func CreateSettlementStore

func CreateSettlementStore(coin *coinparam.Params) (store cxdb.SettlementStore, err error)

CreateSettlementStore creates a settlement store for a specific coin.

func CreateSettlementStoreMap

func CreateSettlementStoreMap(coins []*coinparam.Params) (setMap map[*coinparam.Params]cxdb.SettlementStore, err error)

CreateSettlementStoreMap creates a map of coin to settlement engine, given a list of coins.

Types

type SQLAuctionEngine

type SQLAuctionEngine struct {
	DBHandler *sql.DB
	// contains filtered or unexported fields
}

SQLAuctionEngine is the representation of a matching engine for SQL

func CreateAucEngineStructWithConf

func CreateAucEngineStructWithConf(pair *match.Pair, conf *dbsqlConfig) (engine *SQLAuctionEngine, err error)

CreateAucEngineStructWithConf creates an auction engine but instead of returning an interface, it returns a struct.

func (*SQLAuctionEngine) CancelAuctionOrder

func (ae *SQLAuctionEngine) CancelAuctionOrder(orderID *match.OrderID) (cancelled *match.CancelledOrder, cancelSettlement *match.SettlementExecution, err error)

CancelAuctionOrder cancels an auction order, this assumes that the auction order actually exists

func (*SQLAuctionEngine) DestroyHandler

func (ae *SQLAuctionEngine) DestroyHandler() (err error)

DestroyHandler closes the DB handler that we created, and makes it nil

func (*SQLAuctionEngine) MatchAuctionOrders

func (ae *SQLAuctionEngine) MatchAuctionOrders(auctionID *match.AuctionID) (orderExecs []*match.OrderExecution, settlementExecs []*match.SettlementExecution, err error)

MatchAuction calculates a single clearing price to execute orders at, and executes at that price.

func (*SQLAuctionEngine) PlaceAuctionOrder

func (ae *SQLAuctionEngine) PlaceAuctionOrder(order *match.AuctionOrder, auctionID *match.AuctionID) (idRes *match.AuctionOrderIDPair, err error)

PlaceAuctionOrder places an order in the unencrypted datastore. This assumes that the order is valid.

type SQLAuctionOrderbook

type SQLAuctionOrderbook struct {
	DBHandler *sql.DB
	// contains filtered or unexported fields
}

SQLAuctionOrderbook is the representation of a auction orderbook for SQL

func (*SQLAuctionOrderbook) CalculatePrice

func (ao *SQLAuctionOrderbook) CalculatePrice(auctionID *match.AuctionID) (price float64, err error)

CalculatePrice takes in a pair and returns the calculated price based on the orderbook.

func (*SQLAuctionOrderbook) GetOrder

func (ao *SQLAuctionOrderbook) GetOrder(orderID *match.OrderID) (aucOrder *match.AuctionOrderIDPair, err error)

GetOrder gets an order from an OrderID

func (*SQLAuctionOrderbook) GetOrdersForPubkey

func (ao *SQLAuctionOrderbook) GetOrdersForPubkey(pubkey *koblitz.PublicKey) (orders map[float64][]*match.AuctionOrderIDPair, err error)

GetOrdersForPubkey gets orders for a specific pubkey.

func (*SQLAuctionOrderbook) UpdateBookCancel

func (ao *SQLAuctionOrderbook) UpdateBookCancel(cancel *match.CancelledOrder) (err error)

UpdateBookCancel takes in an order cancellation and updates the orderbook.

func (*SQLAuctionOrderbook) UpdateBookExec

func (ao *SQLAuctionOrderbook) UpdateBookExec(exec *match.OrderExecution) (err error)

UpdateBookExec takes in an order execution and updates the orderbook.

func (*SQLAuctionOrderbook) UpdateBookPlace

func (ao *SQLAuctionOrderbook) UpdateBookPlace(auctionIDPair *match.AuctionOrderIDPair) (err error)

UpdateBookPlace takes in an order, ID, auction ID, and adds the order to the orderbook.

func (*SQLAuctionOrderbook) ViewAuctionOrderBook

func (ao *SQLAuctionOrderbook) ViewAuctionOrderBook() (book map[float64][]*match.AuctionOrderIDPair, err error)

ViewAuctionOrderbook takes in a trading pair and returns the orderbook as a map

type SQLDepositStore

type SQLDepositStore struct {
	DBHandler *sql.DB
	// contains filtered or unexported fields
}

func CreateDepositStoreStructWithConf

func CreateDepositStoreStructWithConf(coin *coinparam.Params, conf *dbsqlConfig) (ds *SQLDepositStore, err error)

func (*SQLDepositStore) DestroyHandler

func (ds *SQLDepositStore) DestroyHandler() (err error)

DestroyHandler closes the DB handler that we created, and makes it nil

func (*SQLDepositStore) GetDepositAddress

func (ds *SQLDepositStore) GetDepositAddress(pubkey *koblitz.PublicKey) (addr string, err error)

GetDepositAddress gets the deposit address for a pubkey and an asset.

func (*SQLDepositStore) GetDepositAddressMap

func (ds *SQLDepositStore) GetDepositAddressMap() (depAddrMap map[string]*koblitz.PublicKey, err error)

GetDepositAddressMap gets a map of the deposit addresses we own to pubkeys

func (*SQLDepositStore) RegisterUser

func (ds *SQLDepositStore) RegisterUser(pubkey *koblitz.PublicKey, address string) (err error)

RegisterUser takes in a pubkey, and an address for the pubkey, and puts the deposit address as the value for the user's pubkey key

func (*SQLDepositStore) UpdateDeposits

func (ds *SQLDepositStore) UpdateDeposits(deposits []match.Deposit, blockheight uint64) (depositExecs []*match.SettlementExecution, err error)

UpdateDeposits updates the deposits when a block comes in, and returns execs for deposits that are now confirmed

type SQLLimitEngine

type SQLLimitEngine struct {
	DBHandler *sql.DB
	// contains filtered or unexported fields
}

SQLLimitEngine is a struct that represents a limit matching engine with SQL as a db backend

func CreateLimEngineStructWithConf

func CreateLimEngineStructWithConf(pair *match.Pair, conf *dbsqlConfig) (engine *SQLLimitEngine, err error)

func (*SQLLimitEngine) CancelLimitOrder

func (le *SQLLimitEngine) CancelLimitOrder(orderID *match.OrderID) (cancelled *match.CancelledOrder, cancelSettlement *match.SettlementExecution, err error)

CancelLimitOrder cancels an auction order, this assumes that the auction order actually exists

func (*SQLLimitEngine) DestroyHandler

func (le *SQLLimitEngine) DestroyHandler() (err error)

DestroyHandler closes the DB handler that we created, and makes it nil

func (*SQLLimitEngine) MatchLimitOrders

func (le *SQLLimitEngine) MatchLimitOrders() (orderExecs []*match.OrderExecution, settlementExecs []*match.SettlementExecution, err error)

MatchLimitOrders matches limit orders based on price/time priority

func (*SQLLimitEngine) PlaceLimitOrder

func (le *SQLLimitEngine) PlaceLimitOrder(order *match.LimitOrder) (idRes *match.LimitOrderIDPair, err error)

PlaceLimitOrder places an order in the limit matching engine. This assumes that the order is valid and is for the same pair as the matching engine

type SQLLimitOrderbook

type SQLLimitOrderbook struct {
	DBHandler *sql.DB
	// contains filtered or unexported fields
}

SQLLimitOrderbook is the representation of a limit orderbook for SQL

func (*SQLLimitOrderbook) CalculatePrice

func (lo *SQLLimitOrderbook) CalculatePrice() (price float64, err error)

CalculatePrice takes in a pair and returns the calculated price based on the orderbook. This is based on the midpoint of the spread.

func (*SQLLimitOrderbook) GetOrder

func (lo *SQLLimitOrderbook) GetOrder(orderID *match.OrderID) (limOrder *match.LimitOrderIDPair, err error)

GetOrder gets an order from an OrderID

func (*SQLLimitOrderbook) GetOrdersForPubkey

func (lo *SQLLimitOrderbook) GetOrdersForPubkey(pubkey *koblitz.PublicKey) (orders map[float64][]*match.LimitOrderIDPair, err error)

GetOrdersForPubkey gets orders for a specific pubkey.

func (*SQLLimitOrderbook) UpdateBookCancel

func (lo *SQLLimitOrderbook) UpdateBookCancel(cancel *match.CancelledOrder) (err error)

UpdateBookCancel takes in an order cancellation and updates the orderbook.

func (*SQLLimitOrderbook) UpdateBookExec

func (lo *SQLLimitOrderbook) UpdateBookExec(orderExec *match.OrderExecution) (err error)

UpdateBookExec takes in an order execution and updates the orderbook.

func (*SQLLimitOrderbook) UpdateBookPlace

func (lo *SQLLimitOrderbook) UpdateBookPlace(limitIDPair *match.LimitOrderIDPair) (err error)

UpdateBookPlace takes in an order, ID, timestamp, and adds the order to the orderbook.

func (*SQLLimitOrderbook) ViewLimitOrderBook

func (lo *SQLLimitOrderbook) ViewLimitOrderBook() (book map[float64][]*match.LimitOrderIDPair, err error)

ViewLimitOrderbook takes in a trading pair and returns the orderbook as a map

type SQLPuzzleStore

type SQLPuzzleStore struct {
	DBHandler *sql.DB
	// contains filtered or unexported fields
}

SQLPuzzleStore is a puzzle store representation for a SQL database

func (*SQLPuzzleStore) PlaceAuctionPuzzle

func (sp *SQLPuzzleStore) PlaceAuctionPuzzle(puzzledOrder *match.EncryptedAuctionOrder) (err error)

PlaceAuctionPuzzle puts an encrypted auction order in the datastore.

func (*SQLPuzzleStore) ViewAuctionPuzzleBook

func (sp *SQLPuzzleStore) ViewAuctionPuzzleBook(auctionID *match.AuctionID) (puzzles []*match.EncryptedAuctionOrder, err error)

ViewAuctionPuzzleBook takes in an auction ID, and returns encrypted auction orders, and puzzles. You don't know what auction IDs should be in the orders encrypted in the puzzle book, but this is what was submitted. This only selects "selected" orders, so while some could be censored and not shown, there is currently no functionality for censoring orders and setting the 'selected' flag to false.

type SQLSettlementEngine

type SQLSettlementEngine struct {
	DBHandler *sql.DB
	// contains filtered or unexported fields
}

func (*SQLSettlementEngine) ApplySettlementExecution

func (se *SQLSettlementEngine) ApplySettlementExecution(setExec *match.SettlementExecution) (setRes *match.SettlementResult, err error)

ApplySettlementExecution applies the settlementExecution, this assumes that the settlement execution is valid

func (*SQLSettlementEngine) CheckValid

func (se *SQLSettlementEngine) CheckValid(setExec *match.SettlementExecution) (valid bool, err error)

CheckValid returns true if the settlement execution would be valid

type SQLSettlementStore

type SQLSettlementStore struct {
	DBHandler *sql.DB
	// contains filtered or unexported fields
}

The SQLSettlementStore handles all client-viewable transactions relating to settlement. The difference between SettlementStore and SettlementEngine: SettlementStore is meant to be updated when the settlement engine returns, the settlement engine is the thing that actually handles validation. We do not care what this says if we want to place an order.

func (*SQLSettlementStore) GetBalance

func (ss *SQLSettlementStore) GetBalance(pubkey *koblitz.PublicKey) (balance uint64, err error)

GetBalance gets the balance for a pubkey and an asset.

func (*SQLSettlementStore) UpdateBalances

func (ss *SQLSettlementStore) UpdateBalances(settlementResults []*match.SettlementResult) (err error)

UpdateBalances updates the balances from the settlement executions

Jump to

Keyboard shortcuts

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