123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package sentio
- import (
- "errors"
- "fmt"
- "strings"
- "time"
- )
- var (
- ErrMarketClosed = errors.New("market is closed")
- ErrTooSmallOrder = errors.New("too small order size")
- )
- type Market interface {
- Clock() Clock
- IsOpen() bool
- Cooldown() uint8
- Connect(done chan struct{}) (chan MarketConnection, error)
- Subscribe(symbols ...string) error
- Account() (MarketAccount, error)
- CreateOrder(symbol string, quantity uint, sl float64) (Order, error)
- UpdateOrder(orderID string, sl float64) error
- CloseOrder(orderID string) (Order, error)
- Order(orderID string, nested bool) (Order, error)
- Orders(criteria OrderListCriteria) ([]Order, error)
- Portfolio() (Portfolio, error)
- PortfolioHistory() ([]PortfolioRecord, error)
- Quotes(symbols ...string) (map[string]Quote, error)
- HistoricalBars(symbols []string, interval time.Duration, from *time.Time) (map[string][]Bar, error)
- }
- type OrderListCriteria struct {
- Status string
- Limit uint
- Symbols []string
- After *time.Time
- Until *time.Time
- Nested bool
- Side *string
- }
- func (criteria OrderListCriteria) Values() map[string]string {
- var values = make(map[string]string)
- if criteria.Limit < 1 {
- criteria.Limit = 500
- }
- if criteria.Symbols != nil && len(criteria.Symbols) > 0 {
- values["symbols"] = strings.Join(criteria.Symbols, ",")
- }
- if criteria.After == nil {
- t := time.Now().Add(-time.Hour * 24).Round(time.Hour * 24)
- criteria.After = &t
- }
- if criteria.Until != nil && !criteria.Until.IsZero() {
- values["until"] = criteria.Until.In(time.UTC).Format(time.RFC3339)
- }
- if criteria.Side != nil {
- values["side"] = *criteria.Side
- }
- values["status"] = "all"
- values["nested"] = "true"
- values["limit"] = fmt.Sprintf("%d", criteria.Limit)
- values["after"] = criteria.After.In(time.UTC).Format(time.RFC3339)
- values["direction"] = "asc"
- return values
- }
|