entities

package
v0.0.0-...-ae4d183 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BINANCE type
	BINANCE = iota
	// BITFINEX type
	BITFINEX
)
View Source
const (
	DoNothing = iota
	Buy
	Sell
)

actions

Variables

View Source
var IndicatorsOpts = map[string]func(Ticker) Indication{
	"Percent": CalculatePercent,
	"MACD":    MACD,
	"RSI":     RSI,
}

IndicatorsOpts full list of indicators

View Source
var MACD = func(ticker Ticker) Indication { return Indication{} }

MACD here the indicator calculations

View Source
var RSI = func(ticker Ticker) Indication { return Indication{} }

RSI here the indicator calculations

Functions

This section is empty.

Types

type APISec

type APISec struct {
	APIKey, SecretKey string
	AccessRule        int
}

APISec security informations to connect

type Account

type Account struct {
	Name       string
	Strategies []*Strategy
	KeyStore   map[string]*APISec

	Description Description
	Timestamp   time.Time
	// contains filtered or unexported fields
}

Account struct can have multiples clients of any exchanges accounts have personalized strategies beyond the standards

func NewAccount

func NewAccount(name string) *Account

NewAccount acc

func (*Account) AccessExchange

func (acc *Account) AccessExchange(accessID string, clientTp int) error

AccessExchange create new client connection

func (*Account) AddAccessKeys

func (acc *Account) AddAccessKeys(id, key, secret string)

AddAccessKeys insert api key in keystore

func (Account) Client

func (acc Account) Client(i int) Exchange

Client returns the client by pointer

func (Account) ClientByID

func (acc Account) ClientByID(id string) Exchange

ClientByID returns the client for the given id

func (Account) ClientOptions

func (acc Account) ClientOptions() []string

ClientOptions returns the id of all clients

func (Account) Clients

func (acc Account) Clients() []Exchange

Clients returns all connected clients

func (*Account) CreateStrategy

func (acc *Account) CreateStrategy(threshold, indWeight int, balance float64)

CreateStrategy adds a new strategy in acc Under tests...

func (Account) Key

func (acc Account) Key(key string) string

Key returns the api key

func (Account) KeyStoreOpts

func (acc Account) KeyStoreOpts() []string

KeyStoreOpts returns the api keys

func (Account) Secret

func (acc Account) Secret(key string) string

Secret returns the api secret

func (*Account) ShowBalances

func (acc *Account) ShowBalances()

ShowBalances all balances of each client

type Asset

type Asset struct {
	Symbol string
	Price  string
	Bids   float64
	Asks   float64
}

Asset table of best informations

type Balance

type Balance struct {
	Asset  string
	Free   string
	Locked string
}

Balance user acc

func (Balance) String

func (bl Balance) String() string

type Binance

type Binance struct {
	ID string

	Client *bi.Client
	Orders []Order

	Tp     int
	Active bool
	// contains filtered or unexported fields
}

Binance struct bot

func (*Binance) Account

func (b *Binance) Account()

Account of this client

func (*Binance) AccountService

func (b *Binance) AccountService()

AccountService acc informations

func (*Binance) AddAsset

func (b *Binance) AddAsset(symbol string)

AddAsset link an asset to the account

func (Binance) Assets

func (b Binance) Assets() []*Asset

Assets returns all linked assets to the exchange client

func (Binance) AssetsTable

func (b Binance) AssetsTable()

AssetsTable show all assets

func (Binance) Balances

func (b Binance) Balances() []Balance

Balances is total amount enabled to trade

func (*Binance) CancelOrder

func (b *Binance) CancelOrder(symbol string, orderID int64)

CancelOrder cancel the order

func (*Binance) CreateOrder

func (b *Binance) CreateOrder(symbol, price, qtd string)

CreateOrder new order

func (*Binance) Depth

func (b *Binance) Depth(symbol string)

Depth returns

func (Binance) GetID

func (b Binance) GetID() string

GetID get time from api server

func (*Binance) GetOrder

func (b *Binance) GetOrder(symbol string, orderID int64) Order

GetOrder opened order info

func (*Binance) InfoService

func (b *Binance) InfoService()

InfoService info of pairs service

func (*Binance) ListKlines

func (b *Binance) ListKlines(symbol, time string)

ListKlines candlesticks

func (*Binance) ListOpenOrders

func (b *Binance) ListOpenOrders(symbol string) []Order

ListOpenOrders returns opened orders

func (*Binance) NewHistoryTrades

func (b *Binance) NewHistoryTrades(symbol string)

NewHistoryTrades history of trades

func (*Binance) NewPriceChangeStatsService

func (b *Binance) NewPriceChangeStatsService()

NewPriceChangeStatsService info of ticker 24h

func (*Binance) OrdersBySymbol

func (b *Binance) OrdersBySymbol(symbol string)

OrdersBySymbol order by symbol

func (*Binance) TimeService

func (b *Binance) TimeService()

TimeService get time from api server

func (*Binance) UpdateTickerPrices

func (b *Binance) UpdateTickerPrices()

UpdateTickerPrices show prices

type Bitfinex

type Bitfinex struct {
	// contains filtered or unexported fields
}

Bitfinex struct bot

func (*Bitfinex) AccessExchange

func (b *Bitfinex) AccessExchange(account Account)

AccessExchange create new client connection

func (*Bitfinex) Account

func (b *Bitfinex) Account()

func (*Bitfinex) AccountName

func (b *Bitfinex) AccountName(accName string) string

func (*Bitfinex) CancelOrder

func (b *Bitfinex) CancelOrder(symbol string, orderID int64)

func (*Bitfinex) Client

func (b *Bitfinex) Client() *bfnx.Client

Client returns client of api

func (*Bitfinex) CreateOrder

func (b *Bitfinex) CreateOrder(symbol, price, qtd string)

func (*Bitfinex) GetOrder

func (b *Bitfinex) GetOrder(symbol string, orderID int64) Order

func (*Bitfinex) GetOrdersBySymbol

func (b *Bitfinex) GetOrdersBySymbol(symbol string) []Order

func (*Bitfinex) InfoService

func (b *Bitfinex) InfoService()

func (*Bitfinex) ListKlines

func (b *Bitfinex) ListKlines(symbol, time string)

func (*Bitfinex) ListOpenOrders

func (b *Bitfinex) ListOpenOrders(symbol string) []Order

func (*Bitfinex) ListTickerPrices

func (b *Bitfinex) ListTickerPrices()

func (*Bitfinex) Name

func (b *Bitfinex) Name() string

func (*Bitfinex) NewHistoryTrades

func (b *Bitfinex) NewHistoryTrades(symbol string)

func (*Bitfinex) ShowDepth

func (b *Bitfinex) ShowDepth(symbol string)

func (*Bitfinex) TimeService

func (b *Bitfinex) TimeService()

type Candlestick

type Candlestick struct {
	OpenTime                 int64
	Open                     string
	High                     string
	Low                      string
	Close                    string
	Volume                   string
	CloseTime                int64
	QuoteAssetVolume         string
	TradeNum                 int64
	TakerBuyBaseAssetVolume  string
	TakerBuyQuoteAssetVolume string
}

Candlestick informations about events in some time interval

type Description

type Description struct {
	// contains filtered or unexported fields
}

Description is the main informations about the acccount

type Exchange

type Exchange interface {
	Account()
	Assets() []*Asset
	AddAsset(string)
	AssetsTable()
	Balances() []Balance
	AccountService()
	//todo: Account settings
	CancelOrder(symbol string, orderID int64)
	CreateOrder(symbol, price, qtd string)
	GetID() string
	GetOrder(symbol string, orderID int64) Order
	OrdersBySymbol(symbol string)
	InfoService()
	ListOpenOrders(symbol string) []Order
	UpdateTickerPrices()
	ListKlines(symbol, time string)
	NewHistoryTrades(symbol string)
	NewPriceChangeStatsService()
	Depth(symbol string)
	TimeService()
}

Exchange client

type Indication

type Indication struct {
	Action      int
	MarketOrder bool
	Price       float64
}

Indication the result of the analysis TODO: receive the indication and create the order, than send it to the exchange

func CalculatePercent

func CalculatePercent(ticker Ticker) Indication

CalculatePercent indications based in percent of prices

func NewIndication

func NewIndication(action int, atMarket bool, price float64) Indication

NewIndication creates a indication

type Indicator

type Indicator struct {
	Name           string
	Category       string
	Weight         int
	Enabled        bool
	TickerAnalisys func(Ticker) Indication
}

Indicator is the structure that will do the price analisys the weight indicates how much important is the indication to make a decision

func NewIndicator

func NewIndicator(weight int, enable bool, analysis func(Ticker) Indication) *Indicator

NewIndicator creates a new indicator

type Order

type Order struct {
	Symbol           string
	OrderID          int64
	ClientOrderID    string
	Price            string
	OrigQuantity     string
	ExecutedQuantity string
	Status           string
	TimeInForce      string
	Type             string
	Side             string
	StopPrice        string
	IcebergQuantity  string
	Time             int64
}

Order info

type Strategy

type Strategy struct {
	Indicators       []*Indicator
	Threshold        int
	Pairs            []string
	AvailableBalance float64
}

Strategy is the structure to configure the environment of the decisions the threshold is the sum of all indicatorweight to enable an action the field AvailableBalance is the limit which the strategies can get from total balance of an account

func NewStrategy

func NewStrategy(threshold int, balance float64, indicators []*Indicator, pairs []string) *Strategy

NewStrategy creates a new strategy

func (*Strategy) AddIndicator

func (stg *Strategy) AddIndicator(indicator *Indicator)

AddIndicator adds an indicator into the strategy

func (*Strategy) ConsultStrategy

func (stg *Strategy) ConsultStrategy(ticker Ticker) bool

ConsultStrategy runs the indicators in parallel the result is if the ticker is inside the strategy or not

func (Strategy) ThresholdReached

func (stg Strategy) ThresholdReached() bool

ThresholdReached sum all enabled indicators and checks the acceptation

type Ticker

type Ticker struct {
	LastPrice float64

	Timestamp time.Time
	Interval  string
	// contains filtered or unexported fields
}

Ticker has the informations about events in timeline this events ocours in scale of minutes, hours, days, weeks, months and years all interval are in pkg tools

Jump to

Keyboard shortcuts

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