domain

package
v0.0.0-...-f351f3f Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorAgentStatus   = iota
	ActiveAgentStatus  = iota
	DisableAgentStatus = iota
)
View Source
const (
	BoolParameterType    = iota
	IntParameterType     = iota
	StringParameterType  = iota
	PercentParameterType = iota
	PairParameterType    = iota
	BalanceParameterType = iota
)

Variables

View Source
var Version string = "v0.3.0"

Functions

func SimpleStratedyToJson

func SimpleStratedyToJson(s *SimpleStrategy) ([]byte, error)

func StartAgents

func StartAgents(ctx context.Context, repos Repos) error

Types

type Agent

type Agent struct {
	Id           int64
	UserId       int64
	Status       AgentStatus
	StrategyId   StrategyId
	StrategyData []byte
}

type AgentRepo

type AgentRepo interface {
	//GetActiveAgents() []Agent
	FindAgents(active bool) ([]Agent, error)
}

type AgentStatus

type AgentStatus int

type AssetAllocationStorage

type AssetAllocationStorage interface {
}

type AssetAllocationStrategy

type AssetAllocationStrategy struct {
}

func (AssetAllocationStrategy) Name

func (AssetAllocationStrategy) Parameters

func (s AssetAllocationStrategy) Parameters() []StrategyParameter

func (*AssetAllocationStrategy) Run

func (s *AssetAllocationStrategy) Run(ctx context.Context, storage interface{}, exchanges []Exchange, logger Logger) error

func (AssetAllocationStrategy) ValidateParameter

func (s AssetAllocationStrategy) ValidateParameter(param StrategyParameter) bool

type Balance

type Balance struct {
	Asset  string          `json:"asset"`
	Amount decimal.Decimal `json:"amount"`
}

type Exchange

type Exchange interface {
	Name() string
	Balances(assets []string) ([]Balance, error)
	GetOpenOrders(filter *OrderFilter) ([]Order, error)
	GetHistoryOrders(pairs []Pair) ([]Order, error)
	LastPrice(pair Pair) (decimal.Decimal, error)
	Buy(pair Pair, amount decimal.Decimal) (*Order, error)
	Sell(pair Pair, amount decimal.Decimal, price decimal.Decimal) (*Order, error)
	CancelOrder(orderId string, pair Pair) error
	GetOrderFee(pair Pair, amount decimal.Decimal, price decimal.Decimal) (Balance, error)
	GetPairFee(pair Pair) (Balance, error)
}

type ExchangeRepo

type ExchangeRepo interface {
	GetAgentExchanges(agentId int64) ([]Exchange, error)
}

type Logger

type Logger interface {
	Info(message string)
	Warn(message string)
	Error(message string)
	Debug(message string)
}

type LoggerRepo

type LoggerRepo interface {
	New(agentId int64) Logger
}

type Order

type Order struct {
	Id         string
	Status     OrderStatus
	Price      decimal.Decimal
	Amount     decimal.Decimal
	Pair       Pair
	Commission Balance
}

type OrderFilter

type OrderFilter struct {
	Ids      []string
	Statuses []OrderStatus
	Pairs    []Pair
}

type OrderStatus

type OrderStatus = int
const (
	PendingOrderStatus  OrderStatus = iota
	FillOrderStatus     OrderStatus = iota
	CanceledOrderStatus OrderStatus = iota
)

type Pair

type Pair struct {
	BaseAsset  string `json:"base_asset"`
	QuoteAsset string `json:"quote_asset"`
}

type Repos

type Repos struct {
	Agent AgentRepo
	//Strategy StrategyRepo
	Storage  StorageRepo
	Exchange ExchangeRepo
	Logger   LoggerRepo
}

type SimpleStorage

type SimpleStorage interface {
	//Storage
	GetTrades(filter *SimpleTradeFilter) ([]SimpleTrade, error)
	SaveTrade(trade *SimpleTrade) error
}

type SimpleStrategy

type SimpleStrategy struct {
	Pair            Pair            `json:"pair"`
	BaseQuality     decimal.Decimal `json:"base_quality"`
	MaxTrades       int             `json:"max_trades"`
	ProfitPercent   decimal.Decimal `json:"profit_percent"`
	FarPricePercent decimal.Decimal `json:"far_price_percent"`
}

func NewSimpleStrategyFromJson

func NewSimpleStrategyFromJson(_json []byte) (*SimpleStrategy, error)

func (SimpleStrategy) Name

func (s SimpleStrategy) Name() string

func (SimpleStrategy) Parameters

func (s SimpleStrategy) Parameters() []StrategyParameter

func (*SimpleStrategy) Run

func (s *SimpleStrategy) Run(ctx context.Context, _storage interface{}, exchanges []Exchange, logger Logger) error

func (SimpleStrategy) ValidateParameter

func (s SimpleStrategy) ValidateParameter(param StrategyParameter) bool

type SimpleTrade

type SimpleTrade struct {
	Id     int
	Status SimpleTradeStatus
	Amount decimal.Decimal
	Buy    SimpleTradeOrder
	Sell   SimpleTradeOrder
}

type SimpleTradeFilter

type SimpleTradeFilter struct {
	Statuses []SimpleTradeStatus
}

type SimpleTradeOrder

type SimpleTradeOrder struct {
	Datetime string
	OrderId  string
	Price    decimal.Decimal
	//amount     decimal.Decimal
	Commission Balance
}

type SimpleTradeStatus

type SimpleTradeStatus = int
const (
	SimpleTradeStatusBuy    SimpleTradeStatus = iota
	SimpleTradeStatusSell   SimpleTradeStatus = iota
	SimpleTradeStatusFinish SimpleTradeStatus = iota
)

type Storage

type Storage interface{}

type StorageRepo

type StorageRepo interface {
	GetAgentStorage(agent Agent) interface{}
}

type Strategy

type Strategy interface {
	Name() string
	Parameters() []StrategyParameter
	ValidateParameter(StrategyParameter) bool
	Run(ctx context.Context, storage interface{}, exchanges []Exchange, logger Logger) error
}

func GetStrategyFromJson

func GetStrategyFromJson(id StrategyId, data []byte) Strategy

type StrategyId

type StrategyId int
const (
	SimpleStratedy StrategyId = iota
)

type StrategyParameter

type StrategyParameter struct {
	Type  StrategyParameterType
	Name  string
	Value interface{}
}

type StrategyParameterType

type StrategyParameterType = int

type StrategyRepo

type StrategyRepo interface {
	GetStrategyData(agentId string) []byte
}

type User

type User struct {
	Id   int64
	Name string
}

type UserFindFilter

type UserFindFilter struct {
	Ids   []string
	Links map[string]interface{}
}

type UserRepo

type UserRepo interface {
	Find(filter UserFindFilter) ([]User, error)
	Create(linkName string, linkValue interface{}) (*User, error)
	Update(userId string, newName string) (*User, error)
}

Directories

Path Synopsis
tests
mocks
Package mock_domain is a generated GoMock package.
Package mock_domain is a generated GoMock package.

Jump to

Keyboard shortcuts

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