orders

package
v0.0.0-...-25c745f Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Loader

type Loader interface {
	Read(ctx context.Context, input io.Reader) ([]*Order, error)
	Write(ctx context.Context, output io.Writer, input []*Order) error
}

Loader reads and writes the Order data to the desired format. There are several loaders to choose from, each of which are self-contained with their own schemas: 1. CSV 2. Avro 3. Proto

func NewAvroLoader

func NewAvroLoader() Loader

func NewCSVLoader

func NewCSVLoader() Loader

func NewJsonNewLineLoader

func NewJsonNewLineLoader() Loader

func NewProtoLoader

func NewProtoLoader() Loader

type Order

type Order struct {
	// UnixTime the order was placed, for back-testing we will assume all orders are filled immediately.
	UnixTime int64 `csv:"time" avro:"time" json:"time"`
	// OrderItems are all of the items that are purchased or sold
	OrderItems []*OrderItem `csv:"items" avro:"items" json:"items"`
}

Order represents a collection of the items that are purchased or sold in a single batch

func NewOrder

func NewOrder(t time.Time, items ...*OrderItem) *Order

func (*Order) AddItem

func (s *Order) AddItem(index int, item *OrderItem)

func (*Order) Append

func (s *Order) Append(item *OrderItem)

func (*Order) Clone

func (s *Order) Clone() *Order

func (*Order) RemoveItem

func (s *Order) RemoveItem(index int)

type OrderItem

type OrderItem struct {
	// Direction - are we buying or selling?
	constants.Direction `csv:"direction" avro:"direction" json:"direction"`

	// ItemType - what type of item is this?
	constants.ItemType `csv:"item_type" avro:"item_type" json:"item_type"`

	// Symbol or ID of the item we are buying or selling
	Symbol string `csv:"symbol" avro:"symbol" json:"symbol"`

	// Amount - How many of the items are you buying or selling?
	// Ex 100 shares of stock, or 1x option contract
	Amount float64 `csv:"amount" avro:"amount" json:"amount"`

	// QuantityPerAmount - how many items are included amount we buy or sell?
	// Stock == 1
	// Option == 10, 100, or some other customer number
	// Crypto == Variable, depending on the currency
	QuantityPerAmount float64 `csv:"quantity_per_amount" avro:"quantity_per_amount" json:"quantity_per_amount"`

	// Price - How much is it per item?
	// 1. A stock is $10 so it's $10 per share
	// 2. An option is $1 per 100 shares, so it's $100 for the contract
	Price float64 `csv:"price" avro:"price" json:"price"`
}

func NewCryptoOrderItem

func NewCryptoOrderItem(direction constants.Direction, symbol string, amount, price float64) *OrderItem

func NewOptionOrderItem

func NewOptionOrderItem(direction constants.Direction, symbol string, amount, price float64) *OrderItem

func NewStockOrderItem

func NewStockOrderItem(direction constants.Direction, symbol string, amount, price float64) *OrderItem

func NewUSDOrderItem

func NewUSDOrderItem(direction constants.Direction, symbol string, amount, price float64) *OrderItem

func (*OrderItem) CalculatePrice

func (s *OrderItem) CalculatePrice(exchangeFee, perOrderFee, perUnitFee float64) float64

func (*OrderItem) Clone

func (s *OrderItem) Clone() *OrderItem

func (*OrderItem) MarginRequirement

func (s *OrderItem) MarginRequirement() float64

Jump to

Keyboard shortcuts

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