1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- 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(symbol string, interval time.Duration, from *time.Time) ([]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 s := strings.TrimSpace(criteria.Status); s != "" {
- values["status"] = s
- }
- 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.Nested {
- values["nested"] = "true"
- } else {
- values["nested"] = "false"
- }
- if criteria.Side != nil {
- values["side"] = *criteria.Side
- }
- values["limit"] = fmt.Sprintf("%d", criteria.Limit)
- values["after"] = criteria.After.In(time.UTC).Format(time.RFC3339)
- values["direction"] = "asc"
- return values
- }
|