Skip to content

Commit

Permalink
[REFACTOR] formatting code
Browse files Browse the repository at this point in the history
  • Loading branch information
VladKochetov007 committed Dec 4, 2023
1 parent 72680d9 commit ac2c628
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 28 deletions.
10 changes: 5 additions & 5 deletions backtest/backtester.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ package backtest
import (
"fmt"
"time"

"xoney/common/data"
"xoney/events"
"xoney/exchange"

st "xoney/strategy"
)

type Backtester struct {
equity data.Equity
simulator exchange.Simulator
equity data.Equity
simulator exchange.Simulator
}

func NewBacktester(simulator exchange.Simulator) *Backtester {
return &Backtester{
equity: data.Equity{},
simulator: simulator,
equity: data.Equity{},
simulator: simulator,
}
}

Expand Down
1 change: 1 addition & 0 deletions backtest/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package backtest

import (
"math"

"xoney/common/data"
"xoney/internal"
)
Expand Down
1 change: 0 additions & 1 deletion common/data/candlestick.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package data
import (
"sort"
"time"

"xoney/errors"
"xoney/internal"
)
Expand Down
18 changes: 9 additions & 9 deletions common/data/equity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ package data

import (
"time"

"xoney/internal"
)

type Equity struct {
startTime time.Time
startTime time.Time
portfolioHistory []map[Currency]float64
mainHistory []float64
Timestamp TimeStamp
timeframe TimeFrame
mainHistory []float64
Timestamp TimeStamp
timeframe TimeFrame
}

func (e *Equity) Timeframe() TimeFrame {
Expand Down Expand Up @@ -41,6 +40,7 @@ func (e *Equity) AddPortfolio(portfolio map[Currency]float64) {
element := internal.MapCopy(portfolio)
e.portfolioHistory = internal.Append(e.portfolioHistory, element)
}

func (e *Equity) AddValue(value float64) {
e.mainHistory = internal.Append(e.mainHistory, value)
if e.Timestamp.Len() == 0 {
Expand All @@ -64,10 +64,10 @@ func NewEquity(
timestamp := NewTimeStamp(timeframe, capacity)

return &Equity{
startTime: start,
startTime: start,
portfolioHistory: make([]map[Currency]float64, 0, internal.DefaultCapacity),
mainHistory: history,
Timestamp: timestamp,
timeframe: timeframe,
mainHistory: history,
Timestamp: timestamp,
timeframe: timeframe,
}
}
4 changes: 3 additions & 1 deletion common/data/instruments.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package data
import (
"strings"
"time"

"xoney/errors"
"xoney/internal"
)
Expand All @@ -23,9 +24,10 @@ func (c Currency) String() string {

return str.String()
}

func NewCurrency[E Exchange | string](asset string, exchange E) Currency {
return Currency{
Asset: asset,
Asset: asset,
Exchange: Exchange(exchange),
}
}
Expand Down
2 changes: 1 addition & 1 deletion exchange/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Order struct {
func (o Order) Symbol() data.Symbol { return o.symbol }
func (o Order) Type() OrderType { return o.orderType }
func (o Order) Side() OrderSide { return o.side }
func (o Order) ID() uint64 { return o.id }
func (o Order) ID() uint64 { return o.id }
func (o Order) Price() float64 { return o.price }
func (o Order) Amount() float64 { return o.amount }

Expand Down
1 change: 0 additions & 1 deletion internal/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package internal

import (
"math"

"xoney/errors"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/system.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package internal

// This constants can be modified to improve performance
// This constants can be modified to improve performance.
const (
DefaultCapacity = 100
CapacityMultiplier = 10
Expand Down
5 changes: 1 addition & 4 deletions realtime/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ import (
"context"
"fmt"
"sync"

"xoney/common/data"
"xoney/internal"

ev "xoney/events"
conn "xoney/exchange"

"xoney/internal"
st "xoney/strategy"
)

Expand Down
3 changes: 1 addition & 2 deletions strategy/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package strategy

import (
"time"

"xoney/common/data"
"xoney/events"
"xoney/exchange"
Expand Down Expand Up @@ -31,7 +30,7 @@ type VectorizedTradable interface {
Tradable
Backtest(
simulator exchange.Simulator,
charts data.ChartContainer,
charts data.ChartContainer,
) (data.Equity, error)
}

Expand Down
6 changes: 3 additions & 3 deletions test/backtesting/backtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"os"
"testing"
"time"

bt "xoney/backtest"
"xoney/common"
"xoney/common/data"
"xoney/exchange"

bt "xoney/backtest"

st "xoney/strategy"
testdata "xoney/testdata/backtesting"
dtr "xoney/testdata/dataread"
Expand Down Expand Up @@ -66,7 +67,6 @@ func TestBacktestReturnsEquity(t *testing.T) {
balanceHistory := equity.PortfolioHistory()
balanceHistory[data.NewCurrency("Total", "")] = history


err = dtr.WriteMap(balanceHistory, "../../testdata/BBEquity.csv")
if err != nil {
t.Error(err.Error())
Expand Down

0 comments on commit ac2c628

Please sign in to comment.