Documentation ¶
Index ¶
- type Account
- type AccountService
- type AccountServiceReader
- type AccountsRepository
- type Application
- type ApplicationExecutionState
- type ApplicationExecutionStateRepository
- type ApplicationOptions
- type ApplicationRepository
- type ApplicationService
- type ApplicationState
- type Asset
- type AssetPrice
- type AssetPriceAggregatedByDate
- type AssetPriceGroupByDate
- type AssetPriceRepository
- type AssetsPricesService
- type AssetsRepository
- type AssetsRepositoryReader
- type Benchmark
- type BenchmarkInput
- type BenchmarkOutput
- type BenchmarkResult
- type BenchmarkService
- type BenchmarksRepository
- type Broker
- type CoindeskHTTPResponse
- type CoindeskResponse
- type Collector
- type CollectorOptions
- type DCAAsset
- type DCAAssetsRepository
- type DCAJob
- type DCAJobOptions
- type DCAJobsRepository
- type DecisionMaker
- type DecisionMakerOptions
- type DecisionMakerState
- type Env
- type EventLog
- type EventsLog
- type Indicator
- type Notification
- type NotificationOptions
- type NotificationsRepository
- type NotificationsService
- type OHLC
- type OnNewAssetPrice
- type Repository
- type SendMail
- type Statistics
- type StatisticsOptions
- type Strategy
- type Trader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct { ID primitive.ObjectID `bson:"_id" json:"_id"` Amount float32 `bson:"amount,truncate" json:"amount"` Broker string `json:"broker"` }
Account has details about an exchange account
type AccountService ¶
type AccountService interface { AccountServiceReader Withdraw(amount float32) error Deposit(amount float32) error CreateAsset(amount, price float32, time time.Time) (*Asset, error) SellAsset(assetID string, price float32, time time.Time) error }
AccountService interacts with one account
type AccountServiceReader ¶
type AccountServiceReader interface { GetAmount() (float32, error) FindPendingAssets() (*[]Asset, error) FindAllAssets() (*[]Asset, error) GetBalance(startDate, endDate time.Time) (float32, error) CheckAssetWithCloserPriceExists(price, limit float32) (bool, error) }
AccountServiceReader reads information about one account
type AccountsRepository ¶
type AccountsRepository interface { FindById(id string) (*Account, error) FindByBroker(broker string) (*Account, error) Create(broker string, amount float32) (*Account, error) Withdraw(id string, amount float32) error Deposit(id string, amount float32) error }
AccountsRepository stores and fetches accounts
type Application ¶
type Application struct { ID primitive.ObjectID `bson:"_id" json:"_id"` Asset string `json:"asset"` AccountID primitive.ObjectID `bson:"accountID" json:"accountID"` Options ApplicationOptions `bson:"options" json:"options"` CreatedAt time.Time `json:"createdAt" bson:"createdAt"` }
Application stores all options and required relations ids for a running application
type ApplicationExecutionState ¶
type ApplicationExecutionState struct { ID primitive.ObjectID `bson:"_id" json:"_id"` ExecutionID primitive.ObjectID `bson:"executionId" json:"executionId"` Date time.Time `json:"date"` State interface{} `json:"state" bson:"state"` }
ApplicationExecutionState is used to store a snapshot of an application execution state in each price change
type ApplicationExecutionStateRepository ¶
type ApplicationExecutionStateRepository interface { Create(date time.Time, executionID primitive.ObjectID, state interface{}) error Aggregate(pipeline mongo.Pipeline) (*[]bson.M, error) BulkCreate(documents *[]bson.M) error BulkDeleteByExecutionID(id string) error FindLast(filter interface{}) (*ApplicationExecutionState, error) }
ApplicationExecutionStateRepository stores and gets application executions states
type ApplicationOptions ¶
type ApplicationOptions struct { NotificationOptions `bson:"notificationOptions" json:"notificationOptions"` StatisticsOptions `bson:"statisticsOptions" json:"statisticsOptions"` DecisionMakerOptions `bson:"decisionMakerOptions" json:"decisionMakerOptions"` CollectorOptions `bson:"collectorOptions" json:"collectorOptions"` }
ApplicationOptions aggregates options of every service options needed to run an application
type ApplicationRepository ¶
type ApplicationRepository interface { FindByID(id string) (*Application, error) Create(asset string, options ApplicationOptions, acountID primitive.ObjectID) (*Application, error) FindAll() (*[]Application, error) DeleteByID(id string) error }
ApplicationRepository stores and gets applications from db
type ApplicationService ¶
type ApplicationService interface { FindAll() (*[]Application, error) GetLastState(appID primitive.ObjectID) (*ApplicationExecutionState, error) DeleteByID(id string) error GetLogEvents(appID primitive.ObjectID) (*[]EventLog, error) GetStateAggregated(appID string, startDate, endDate time.Time) (*[]bson.M, error) }
ApplicationService interacts with objects related with an application
type ApplicationState ¶
type ApplicationState struct { Average float32 `json:"average"` StandardDeviation float32 `json:"standardDeviation"` LowerBollingerBand float32 `json:"lowerBollingerBand"` HigherBollingerBand float32 `json:"higherBollingerBand"` CurrentPrice float32 `json:"currentPrice"` CurrentChange float32 `json:"currentChange"` }
ApplicationState is the state hold by application execution state object
type Asset ¶
type Asset struct { ID primitive.ObjectID `bson:"_id" json:"_id"` Amount float32 `bson:"amount,truncate" json:"amount"` BuyTime time.Time `json:"buyTime"` SellTime time.Time `json:"sellTime"` BuyPrice float32 `bson:"buyPrice,truncate" json:"buyPrice"` SellPrice float32 `bson:"sellPrice,truncate" json:"sellPrice"` Sold bool `json:"sold"` AccountID primitive.ObjectID `bson:"accountID" json:"accountID"` }
Asset is a financial instrument
type AssetPrice ¶
type AssetPrice struct { ID primitive.ObjectID `bson:"_id" json:"_id"` Date time.Time `bson:"date" json:"date"` EndDate time.Time `bson:"endDate" json:"endDate"` Open float32 `bson:"o" json:"o"` Close float32 `bson:"c" json:"c"` High float32 `bson:"h" json:"h"` Low float32 `bson:"l" json:"l"` Volume float32 `bson:"v" json:"v"` Asset string `bson:"asset" json:"asset"` }
AssetPrice represents the price of an asset on a moment
type AssetPriceAggregatedByDate ¶
type AssetPriceAggregatedByDate struct { ID AssetPriceGroupByDate `json:"_id"` Price float32 `json:"price"` }
AssetPriceAggregatedByDate is the output of the aggregate query that groups prices per date
type AssetPriceGroupByDate ¶
type AssetPriceGroupByDate struct { Year int `json:"year"` Month int `json:"month"` Day int `json:"day"` }
AssetPriceGroupByDate is a group id struct
type AssetPriceRepository ¶
type AssetPriceRepository interface { Create(ohlc *OHLC, asset string) error FindAll(filter interface{}) (*[]AssetPrice, error) Aggregate(pipeline mongo.Pipeline) (*[]bson.M, error) GetLastAssetsPrices(asset string, limit int) (*[]AssetPrice, error) BulkCreate(documents *[]bson.M) error }
AssetPriceRepository stores and gets assets prices
type AssetsPricesService ¶
type AssetsPricesService interface { GetLastAssetsPrices(asset string, limit int) (*[]AssetPrice, error) Create(ohlc *OHLC, asset string) error FetchAndStoreAssetPrices(asset string, endDate time.Time) error }
AssetsPricesService provides assets prices related methods
type AssetsRepository ¶
type AssetsRepository interface { AssetsRepositoryReader Sell(id string, price float32, sellTime time.Time) error Create(asset *Asset) error }
AssetsRepository stores and fetches assets
type AssetsRepositoryReader ¶
type AssetsRepositoryReader interface { FindAll(accountID string) (*[]Asset, error) FindPendingAssets(accountID string) (*[]Asset, error) FindCheaperAssetPrice(accountID string) (float32, error) CheckAssetWithCloserPriceExists(accountID string, price float32, limit float32) (bool, error) GetBalance(accountID string, startDate, endDate time.Time) (float32, error) }
AssetsRepositoryReader fetches assets data
type Benchmark ¶
type Benchmark struct { ID primitive.ObjectID `bson:"_id" json:"_id"` Input BenchmarkInput `json:"input"` Output BenchmarkOutput `json:"output"` Status string `json:"status"` CreatedAt time.Time `json:"createdAt"` CompletedAt time.Time `json:"completedAt"` }
Benchmark stores inputs and outputs of a benchmark
type BenchmarkInput ¶
type BenchmarkInput struct { DecisionMakerOptions DecisionMakerOptions `json:"decisionMakerOptions"` StatisticsOptions StatisticsOptions `json:"statisticsOptions"` CollectorOptions CollectorOptions `json:"collectorOptions"` AccountInitialAmount float64 `json:"accountInitialAmount"` DataSourceFilePath string `json:"dataSourceFilePath"` Asset string `json:"asset"` }
BenchmarkInput needed to run benchmark
type BenchmarkOutput ¶
type BenchmarkOutput struct { Buys [][]float32 `json:"buys"` Sells [][]float32 `json:"sells"` SellsPending int `json:"sellsPending"` FinalAmount float32 `json:"finalAmount"` Assets *[]Asset `json:"assets"` AssetsAmountPending float32 `json:"assetsAmountPending"` AssetsValuePending float32 `json:"assetsValuePending"` LastPrice float32 `json:"lastPrice"` }
BenchmarkOutput is the output of the benchmark
func (*BenchmarkOutput) String ¶
func (o *BenchmarkOutput) String()
String displays Output formatted
type BenchmarkResult ¶
type BenchmarkResult struct { Input *BenchmarkInput Output *BenchmarkOutput Err error }
BenchmarkResult stores benchmark returned value and possible error
type BenchmarkService ¶
type BenchmarkService interface { Create(input BenchmarkInput) (*Benchmark, error) DeleteByID(id string) error FindAll() (*[]Benchmark, error) BulkRun(inputs []BenchmarkInput, c chan BenchmarkResult) Run(input BenchmarkInput, benchmarkID *primitive.ObjectID) (*BenchmarkOutput, error) HandleBenchmark(benchmark *Benchmark) error GetDataSources() map[string]map[string]string AggregateApplicationState(pipeline mongo.Pipeline) (*[]bson.M, error) }
type BenchmarksRepository ¶
type BenchmarksRepository interface { FindAll() (*[]Benchmark, error) InsertOne(benchmark *Benchmark) error DeleteByID(id string) error UpdateBenchmarkCompleted(id string, output *BenchmarkOutput) error }
BenchmarksRepository stores and fetches benchmarks
type Broker ¶
type Broker interface { AddBuyOrder(amount, price float32) error AddSellOrder(amount, price float32) error SetTicker(ticker string) }
Broker add order to buy and sell assets in real brokers
type CoindeskHTTPResponse ¶
type CoindeskHTTPResponse struct { StatusCode int `json:"statusCode"` Message string `json:"message"` Data CoindeskResponse `json:"data"` }
CoindeskHTTPResponse is the response of Coindesk HTTP
type CoindeskResponse ¶
type CoindeskResponse struct { Iso string `json:"iso"` Name string `json:"name"` Slug string `json:"slug"` Interval string `json:"interval"` Entries [][]float64 `json:"entries"` }
CoindeskResponse is the body of Coindesk HTTP Response
type Collector ¶
type Collector interface { Start() Stop() Regist(observable OnNewAssetPrice) SetIndicators(indicators *[]Indicator) GetTicker(tickerSymbol string) (float32, error) }
Collector notifies when price asset changes
type CollectorOptions ¶
type CollectorOptions struct { PriceVariationDetection float32 `bson:"priceVariationDetection,truncate" json:"priceVariationDetection"` DataSource *csv.Reader NewPriceTimeRate int `bson:"newPriceTimeRate,truncate" json:"newPriceTimeRate"` }
CollectorOptions are used to change collectors behaviour
type DCAAsset ¶
type DCAAsset struct { Coin string Amount float32 Price float32 FiatAmount float32 CreatedAt time.Time `bson:"createdAt" json:"createdAt"` }
DCAAsset represents an asset bought on a dca operation
type DCAAssetsRepository ¶
DCAAssetsRepository stores and gets dca assets
type DCAJob ¶
type DCAJob struct { ID primitive.ObjectID `bson:"_id" json:"_id"` Period int64 NextExecution int64 Options DCAJobOptions }
DCAJob stores details about a dca job like the time it has to be executed and strategy options
func (*DCAJob) GetFiatCoinsAmount ¶
GetFiatCoinsAmount use coins values proportion and total FIAT amount that must be invested and returns amounts to invest in each coin
func (*DCAJob) SetNextExecution ¶
func (d *DCAJob) SetNextExecution()
SetNextExecution updates dca job with the next timestamp to execute the job
type DCAJobOptions ¶
DCAJobOptions stores dca jobs strategy options
type DCAJobsRepository ¶
DCAJobsRepository stores and gets dca jobs
type DecisionMaker ¶
type DecisionMaker interface { ShouldBuy() (bool, float32, error) ShouldSell() (bool, float32, error) }
DecisionMaker makes decisions to buy or sell assets
type DecisionMakerOptions ¶
type DecisionMakerOptions struct { MaximumBuyAmount float32 `bson:"maximumBuyAmount,truncate" json:"maximumBuyAmount"` MaximumFIATBuyAmount float32 `bson:"maximumFIATBuyAmount,truncate" json:"maximumFIATBuyAmount"` MinimumProfitPerSold float32 `bson:"minimumProfitPerSold,truncate" json:"minimumProfitPerSold"` MinimumPriceDropToBuy float32 `bson:"minimumPriceDropToBuy,truncate" json:"minimumPriceDropToBuy"` GrowthDecreaseLimit float32 `bson:"growthDecreaseLimit,truncate" json:"growthDecreaseLimit"` GrowthIncreaseLimit float32 `bson:"growthIncreaseLimit,truncate" json:"growthIncreaseLimit"` }
DecisionMakerOptions are used to change DecisionMaker behaviour
type DecisionMakerState ¶
type DecisionMakerState struct { Price float32 `bson:"price,truncate" json:"price"` PriceAverage float64 `bson:"priceAverage,truncate" json:"priceAverage"` PriceStandardDeviation float64 `bson:"priceStandardDeviation,truncate" json:"priceStandardDeviation"` PriceUpperLimit float64 `bson:"priceUpperLimit,truncate" json:"priceUpperLimit"` PriceLowerLimit float64 `bson:"priceLowerLimit,truncate" json:"priceLowerLimit"` Change float32 `bson:"change,truncate" json:"change"` ChangeAverage float64 `bson:"changeAverage,truncate" json:"changeAverage"` ChangeStandardDeviation float64 `bson:"changeStandardDeviation,truncate" json:"changeStandardDeviation"` ChangeUpperLimit float64 `bson:"changeUpperLimit,truncate" json:"changeUpperLimit"` ChangeLowerLimit float64 `bson:"changeLowerLimit,truncate" json:"changeLowerLimit"` Acceleration float32 `bson:"acceleration,truncate" json:"acceleration"` AccelerationAverage float64 `bson:"accelerationAverage,truncate" json:"accelerationAverage"` AccelerationStandardDeviation float64 `bson:"accelerationStandardDeviation,truncate" json:"accelerationStandardDeviation"` AccelerationUpperLimit float64 `bson:"accelerationUpperLimit,truncate" json:"accelerationUpperLimit"` AccelerationLowerLimit float64 `bson:"accelerationLowerLimit,truncate" json:"accelerationLowerLimit"` Volume float32 `bson:"volume" json:"volume"` VolumeAverage float64 `bson:"volumeAverage" json:"volumeAverage"` VolumeUpperLimit float64 `bson:"volumeUpperLimit" json:"volumeUpperLimit"` VolumeLowerLimit float64 `bson:"volumeLowerLimit" json:"volumeLowerLimit"` Open float32 `bson:"open" json:"open"` Close float32 `bson:"close" json:"close"` High float32 `bson:"high" json:"high"` Low float32 `bson:"low" json:"low"` AccountAmount float64 `bson:"accountAmount,truncate" json:"accountAmount"` }
DecisionMakerState represents the decision maker state
type EventLog ¶
type EventLog struct { ID primitive.ObjectID `bson:"_id" json:"_id"` EventName string `json:"eventName"` Message string `json:"message"` Notified bool `json:"notified"` CreatedAt time.Time `json:"createdAt"` ApplicationID primitive.ObjectID `bson:"applicationID" json:"applicationID"` }
EventLog is a regist of an application event
type EventsLog ¶
type EventsLog interface { FindAllToNotify() (*[]EventLog, error) Create(logType, message string) error MarkNotified(ids []primitive.ObjectID) error FindAll(filter interface{}) (*[]EventLog, error) BulkDeleteByApplicationID(id string) error }
EventsLog interacts with events
type Indicator ¶
type Indicator interface { AddValue(ohlc *OHLC) GetState() interface{} }
Indicator collects metric values and produces outputs to help decision maker deciding
type Notification ¶
type Notification struct { ID primitive.ObjectID `bson:"_id" json:"_id"` Title string `json:"title"` Message string `json:"message"` To string `json:"to"` NotificationType string `bson:"notificationType" json:"notificationType"` NotificationChannel string `bson:"notificationChannel" json:"notificationChannel"` Sent bool `json:"sent"` CreatedAt time.Time `bson:"createdAt" json:"createdAt"` ApplicationID primitive.ObjectID `bson:"applicationID" json:"applicationID"` }
Notification is a message sent to a specific user
type NotificationOptions ¶
NotificationOptions has notifications service options
type NotificationsRepository ¶
type NotificationsRepository interface { Create(notification *Notification) error FindLastEventLogsNotificationDate() (time.Time, error) Sent(id primitive.ObjectID) error BulkDelete(filter bson.M) error BulkDeleteByApplicationID(id string) error }
NotificationsRepository stores and gets notifications
type NotificationsService ¶
type NotificationsService interface { FindLastEventLogsNotificationDate() (time.Time, error) CreateEmailNotification(subject, message, notificationType string) error ShouldSendNotification() bool BulkDeleteByApplicationID(id string) error SendEmail(subject, body string) error }
NotificationsService interacts with notifications
type OHLC ¶
type OHLC struct { Time time.Time `json:"time"` EndTime time.Time `json:"etime"` Open float32 `json:"open"` Close float32 `json:"close"` High float32 `json:"high"` Low float32 `json:"low"` Volume float32 `json:"volume"` }
OHLC is a type with interval asset prices
type Repository ¶
type Repository interface { FindAll(documents interface{}, query interface{}, opts *options.FindOptions) error Aggregate(documents interface{}, pipelineOptions mongo.Pipeline) error FindOne(document interface{}, query interface{}, opts *options.FindOneOptions) error InsertOne(document interface{}) error UpdateOne(query interface{}, update interface{}) error DeleteByID(id string) error BulkUpsert(documents []bson.M) error BulkCreate(documents *[]bson.M) error BulkDelete(filter bson.M) error BulkUpdate(filter bson.M, update bson.M) error }
Repository is a generic interface to be used by other repositories
type Statistics ¶
type Statistics interface { AddPoint(p float64) GetStandardDeviation() float64 GetVariance() float64 GetAverage() float64 HasRequiredNumberOfPoints() bool }
Statistics receives points and do statitics calculations
type StatisticsOptions ¶
type StatisticsOptions struct {
NumberOfPointsHold int `json:"numberOfPointsHold"`
}
StatisticsOptions used in Statistics