trading

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OrderSideSell = "sell"
	OrderSideBuy  = "buy"

	OrderStatusPlaced    = "placed"
	OrderStatusCanceled  = "canceled"
	OrderStatusCompleted = "completed"
)
View Source
const (
	LSSDConnectionProblem = "connect: connection refused"
)

Variables

This section is empty.

Functions

func BackupCache

func BackupCache()

func GetMyOrdersCache

func GetMyOrdersCache() *cache.Cache

func InitLSSD

func InitLSSD() error

func IsLSSDConnProblem

func IsLSSDConnProblem(err error) bool

func PeriodicOrderListener

func PeriodicOrderListener(bot *Bot, tradingPair string, withOwnOrders bool, interval time.Duration, logger *logrus.Entry)

func PeriodicPing

func PeriodicPing(interval time.Duration, entry *logrus.Entry)

Periodically perform request to check if LSSD is running Its using "enableTradingPair" instead of an actual ping endpoint but its just for the concept

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile will read the content of a given filepath, e.g. the certificate contents

func SetLogger

func SetLogger(logLvl string)

func SetupCache

func SetupCache(tradingBot *Bot)

SetupCache func will read previously used cache files to get back to the order state it was before shutting down

func ValidateCurrency

func ValidateCurrency(currency string) bool

ValidateCurrency checks if the given currency is allowed or not

Types

type Bot

type Bot struct {
	OrderClient       lssdrpc.OrdersClient
	SwapClient        lssdrpc.SwapsClient
	CurrencyClient    lssdrpc.CurrenciesClient
	TradingPairClient lssdrpc.TradingPairsClient

	LNDConfig LNDConfig
	Log       *logrus.Entry
	LogLevel  string

	OrderLimit int
	Timeout    time.Duration

	SentryDSN string
}

Bot struct holds all the gRPC client connections, the resolved config and the logger

func NewBot

NewBot func will create a new Bot object based on all the lssd client connections and the resolved config

func (*Bot) AddCurrencies

func (t *Bot) AddCurrencies() error

AddCurrencies func will register all the currencies by performing a lssd grpc request for all certificates are specified in the config

func (*Bot) CancelOrder

func (t *Bot) CancelOrder(tradingPair string, orderID string) (*lssdrpc.CancelOrderResponse, error)

CancelOrder func will perform a lssd gRPC request to the PlaceOrder endpoint of the Orders service for a specified trading pair and order settings

func (*Bot) EnableTradingPair

func (t *Bot) EnableTradingPair(pair string) error

EnableTradingPair func will enable the given tradingPair

func (*Bot) Init

func (t *Bot) Init() error

Init func will read the contents of the given certificate paths

func (*Bot) ListOrders

func (t *Bot) ListOrders(tradingPair string, myOrders bool, printCLI bool) ([]lssdrpc.Order, error)

ListOrders func will perform a lssd gRPC request to the ListOrders endpoint of the Orders service for a specified trading pair

func (*Bot) PlaceOrder

func (t *Bot) PlaceOrder(tradingPair string, price int64, funds int64, side lssdrpc.OrderSide, orderType string, label string) (*lssdrpc.PlaceOrderResponse, error)

PlaceOrder func will perform a lssd gRPC request to the PlaceOrder endpoint of the Orders service for a specified trading pair and order settings

func (*Bot) SubscribeOrders

func (t *Bot) SubscribeOrders() error

SubscribeOrders func will subscribe to orders

func (*Bot) SubscribeSwaps

func (t *Bot) SubscribeSwaps() error

SubscribeSwaps func will subscribe to swaps

type Connection

type Connection struct {
	Host string
	Port int
}

Connection struct holds connection data

func (*Connection) Format

func (c *Connection) Format() string

Format func will format in a common host:port scheme

type LNDConfig

type LNDConfig struct {
	TLSPaths    map[string]string     // map[LTC]-> /path/to/lnd_ltc.tls.cert
	Certs       map[string]string     // map[LTC]-> -----BEGIN CERTIFICATE-----...
	Connections map[string]Connection // map[LTC]{Host: localhost, Port: 10001}
}

LNDConfig holds mandatory information how to connection / authenticate with a LND

func NewConfig

func NewConfig() LNDConfig

NewConfig func will create a config with initialized maps

func (*LNDConfig) Add

func (c *LNDConfig) Add(currency string, certPath string, host string, port int) error

Add will add a new currency config to the LNDConfig

func (*LNDConfig) IsEmpty

func (c *LNDConfig) IsEmpty() bool

IsEmpty func checks whether there are certificate paths already specified

type Order

type Order struct {
	PairId    string `json:"pairId"`
	OrderId   string `json:"orderId"`
	Price     int64  `json:"price"` //satoshis
	Funds     int64  `json:"funds"` //satoshis
	CreatedAt uint64 `json:"createdAt"`
	Side      string `json:"side"`
	Status    string `json:"status"`
	OrderType string `json:"type"`
	Label     string `json:"label,omitempty"`
	IsOwn     bool   `json:"isOwn"`
}

func GetFromCacheByOrderId

func GetFromCacheByOrderId(c *cache.Cache, tradingPair string, orderId string) *Order

func GetMyOrderByID

func GetMyOrderByID(tradingPair string, orderId string) *Order

type OrderCollection

type OrderCollection []Order

func GetMemoryEnrichedMyOrders

func GetMemoryEnrichedMyOrders(tp string) OrderCollection

func (*OrderCollection) Add

func (o *OrderCollection) Add(order Order) *OrderCollection

func (*OrderCollection) GetByOrderID

func (o *OrderCollection) GetByOrderID(orderId string) *Order

func (*OrderCollection) GetPriceTopOrdersSorted

func (o *OrderCollection) GetPriceTopOrdersSorted(side string, limit int, excludingMyOrders bool) *OrderCollection

func (*OrderCollection) SumFunds

func (o *OrderCollection) SumFunds(status string) (sum int64)

func (*OrderCollection) Unique

func (o *OrderCollection) Unique() *OrderCollection

Jump to

Keyboard shortcuts

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