orderbook

package
v0.0.0-...-1ca2487 Latest Latest
Warning

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

Go to latest
Published: May 29, 2020 License: MIT Imports: 12 Imported by: 0

README

GoCryptoTrader package Orderbook

Build Status Software License GoDoc Coverage Status Go Report Card

This orderbook package is part of the GoCryptoTrader codebase.

This is still in active development

You can track ideas, planned features and what's in progress on this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

Current Features for orderbook

  • This package facilitates orderbook generation.

  • Attaches methods to an orderbook

    • To Return total Bids
    • To Return total Asks
    • Update orderbooks
  • Gets a loaded orderbook by exchange, asset type and currency pair.

  • This package is primarily used in conjunction with but not limited to the exchange interface system set by exchange wrapper orderbook functions in "exchange"_wrapper.go.

Examples below:

ob, err := yobitExchange.FetchOrderbook()
if err != nil {
  // Handle error
}

// Find total asks which also returns total orderbook value
totalAsks, totalOrderbookVal := ob.CalculateTotalAsks()
  • or if you have a routine setting an exchange orderbook you can access it via the package itself.
ob, err := orderbook.Get(...)
if err != nil {
  // Handle error
}
Please click GoDocs chevron above to view current GoDoc information for this package

Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Code must adhere to our coding style.
  • Pull requests need to be based on and opened against the master branch.

Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SubscribeOrderbook

func SubscribeOrderbook(exchange string, p currency.Pair, a asset.Item) (dispatch.Pipe, error)

SubscribeOrderbook subcribes to an orderbook and returns a communication channel to stream orderbook data updates

func SubscribeToExchangeOrderbooks

func SubscribeToExchangeOrderbooks(exchange string) (dispatch.Pipe, error)

SubscribeToExchangeOrderbooks subcribes to all orderbooks on an exchange

Types

type Base

type Base struct {
	Pair         currency.Pair `json:"pair"`
	Bids         []Item        `json:"bids"`
	Asks         []Item        `json:"asks"`
	LastUpdated  time.Time     `json:"lastUpdated"`
	AssetType    asset.Item    `json:"assetType"`
	ExchangeName string        `json:"exchangeName"`
}

Base holds the fields for the orderbook base

func Get

func Get(exchange string, p currency.Pair, a asset.Item) (*Base, error)

Get checks and returns the orderbook given an exchange name and currency pair if it exists

func (*Base) Process

func (b *Base) Process() error

Process processes incoming orderbooks, creating or updating the orderbook list

func (*Base) SimulateOrder

func (b *Base) SimulateOrder(amount float64, buy bool) *OrderSimulationResult

SimulateOrder simulates an order

func (*Base) TotalAsksAmount

func (b *Base) TotalAsksAmount() (amountCollated, total float64)

TotalAsksAmount returns the total amount of asks and the total orderbook asks value

func (*Base) TotalBidsAmount

func (b *Base) TotalBidsAmount() (amountCollated, total float64)

TotalBidsAmount returns the total amount of bids and the total orderbook bids value

func (*Base) Update

func (b *Base) Update(bids, asks []Item)

Update updates the bids and asks

func (*Base) Verify

func (b *Base) Verify()

Verify ensures that the orderbook items are correctly sorted Bids should always go from a high price to a low price and asks should always go from a low price to a higher price

func (*Base) WhaleBomb

func (b *Base) WhaleBomb(priceTarget float64, buy bool) (*WhaleBombResult, error)

WhaleBomb finds the amount required to target a price

type Book

type Book struct {
	Main  uuid.UUID
	Assoc []uuid.UUID
	// contains filtered or unexported fields
}

Book defines an orderbook with its links to different dispatch outputs

type ByPrice

type ByPrice orderSummary

ByPrice used for sorting orders by order date

func (ByPrice) Len

func (b ByPrice) Len() int

func (ByPrice) Less

func (b ByPrice) Less(i, j int) bool

func (ByPrice) Swap

func (b ByPrice) Swap(i, j int)

type Item

type Item struct {
	Amount float64
	Price  float64
	ID     int64

	// Contract variables
	LiquidationOrders int64
	OrderCount        int64
}

Item stores the amount and price values

type OrderSimulationResult

type OrderSimulationResult WhaleBombResult

OrderSimulationResult returns the order simulation result

type Service

type Service struct {
	Books    map[string]map[*currency.Item]map[*currency.Item]map[asset.Item]*Book
	Exchange map[string]uuid.UUID

	sync.RWMutex
	// contains filtered or unexported fields
}

Service holds orderbook information for each individual exchange

func (*Service) GetAssociations

func (s *Service) GetAssociations(b *Base) ([]uuid.UUID, error)

GetAssociations links a singular book with it's dispatch associations

func (*Service) Retrieve

func (s *Service) Retrieve(exchange string, p currency.Pair, a asset.Item) (*Base, error)

Retrieve gets orderbook data from the slice

func (*Service) SetNewData

func (s *Service) SetNewData(b *Base) error

SetNewData sets new data

func (*Service) Update

func (s *Service) Update(b *Base) error

Update stores orderbook data

type WhaleBombResult

type WhaleBombResult struct {
	Amount               float64
	MinimumPrice         float64
	MaximumPrice         float64
	PercentageGainOrLoss float64
	Orders               orderSummary
	Status               string
}

WhaleBombResult returns the whale bomb result

Jump to

Keyboard shortcuts

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