Browse Source

Refactoring

- pure impl
Alexey Kim 1 month ago
parent
commit
1b6b0b20d7
5 changed files with 13 additions and 86 deletions
  1. 0 4
      go.mod
  2. 0 4
      go.sum
  3. 13 8
      portfolio.go
  4. 0 15
      strategy/clock_test.go
  5. 0 55
      strategy/portfolio_test.go

+ 0 - 4
go.mod

@@ -1,7 +1,3 @@
 module git.beejay.kim/Gshopper/sentio
 
 go 1.22.2
-
-require github.com/samber/lo v1.47.0
-
-require golang.org/x/text v0.16.0 // indirect

+ 0 - 4
go.sum

@@ -1,4 +0,0 @@
-github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
-github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
-golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
-golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=

+ 13 - 8
portfolio.go

@@ -1,7 +1,5 @@
 package sentio
 
-import "github.com/samber/lo"
-
 type Portfolio interface {
 	// Get returns Position of the symbol if exists in Portfolio
 	Get(symbol string) (Position, bool)
@@ -13,15 +11,22 @@ type Portfolio interface {
 type PortfolioStub []PositionStub
 
 func (p PortfolioStub) Get(symbol string) (Position, bool) {
-	return lo.Find(p, func(item PositionStub) bool {
-		return item.Symbol == symbol
-	})
+	for _, stub := range p {
+		if symbol == stub.Symbol {
+			return stub, true
+		}
+	}
+
+	return nil, false
 }
 
 func (p PortfolioStub) Positions() []Position {
-	return lo.Map(p, func(item PositionStub, _ int) Position {
-		return item
-	})
+	var positions []Position
+	for _, stub := range p {
+		positions = append(positions, stub)
+	}
+
+	return positions
 }
 
 func NewPortfolioStub(elem ...PositionStub) Portfolio {

+ 0 - 15
strategy/clock_test.go

@@ -1,15 +0,0 @@
-package main
-
-import "time"
-
-type ClockFixed struct {
-	fix time.Time
-}
-
-func (t ClockFixed) Now() time.Time {
-	return t.fix.In(time.UTC)
-}
-
-func (t ClockFixed) After(d time.Duration) <-chan time.Time {
-	return time.After(d)
-}

+ 0 - 55
strategy/portfolio_test.go

@@ -1,55 +0,0 @@
-package main
-
-import (
-	"git.beejay.kim/Gshopper/sentio"
-	"github.com/samber/lo"
-)
-
-type PortfolioStub []PositionStub
-
-func newStubPortfolio(elem ...PositionStub) sentio.Portfolio {
-	var p PortfolioStub
-	p = append(p, elem...)
-
-	return p
-}
-
-func (p PortfolioStub) Get(symbol string) (sentio.Position, bool) {
-	return lo.Find(p, func(item PositionStub) bool {
-		return item.symbol == symbol
-	})
-}
-
-func (p PortfolioStub) Positions() []sentio.Position {
-	return lo.Map(p, func(item PositionStub, _ int) sentio.Position {
-		return item
-	})
-}
-
-type PositionStub struct {
-	symbol       string
-	size         float64
-	price        float64
-	pnl          float64
-	currentPrice float64
-}
-
-func (p PositionStub) GetSize() float64 {
-	return p.size
-}
-
-func (p PositionStub) GetAvgPrice() float64 {
-	return p.price
-}
-
-func (p PositionStub) GetSymbol() string {
-	return p.symbol
-}
-
-func (p PositionStub) GetPnL() float64 {
-	return p.pnl
-}
-
-func (p PositionStub) GetCurrentPrice() float64 {
-	return p.currentPrice
-}