2
0

portfolio.go 705 B

123456789101112131415161718192021222324252627282930313233343536
  1. package sentio
  2. type Portfolio interface {
  3. // Get returns Position of the symbol if exists in Portfolio
  4. Get(symbol string) (Position, bool)
  5. // Positions returns each Position we have in Portfolio
  6. Positions() []Position
  7. }
  8. type PortfolioStub []PositionStub
  9. func (p PortfolioStub) Get(symbol string) (Position, bool) {
  10. for _, stub := range p {
  11. if symbol == stub.Symbol {
  12. return stub, true
  13. }
  14. }
  15. return nil, false
  16. }
  17. func (p PortfolioStub) Positions() []Position {
  18. var positions []Position
  19. for _, stub := range p {
  20. positions = append(positions, stub)
  21. }
  22. return positions
  23. }
  24. func NewPortfolioStub(elem ...PositionStub) Portfolio {
  25. var p PortfolioStub
  26. p = append(p, elem...)
  27. return p
  28. }