Skip to content

Commit 3069d75

Browse files
[REFACTOR] code style
1 parent 3008af0 commit 3069d75

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

Makefile

+1-10
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@ setup :
55
export PATH=$$PATH:/home/vlad/go/bin
66

77
lint :
8-
golangci-lint run --enable-all -D \
9-
depguard,\
10-
gci,\
11-
varnamelen,\
12-
gomnd,\
13-
gofumpt,\
14-
ifshort,\
15-
wrapcheck,\
16-
paralleltest,\
17-
ireturn
8+
golangci-lint run --enable-all -D depguard,gci,varnamelen,gomnd,gofumpt,ifshort,wrapcheck,paralleltest,ireturn --skip-files '.*_test\.go' --skip-dirs 'test'
189

1910
fmt :
2011
go fmt ./... && \

backtest/backtester.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/quick-trade/xoney/common/data"
88
"github.com/quick-trade/xoney/exchange"
99
"github.com/quick-trade/xoney/internal"
10-
1110
exec "github.com/quick-trade/xoney/internal/executing"
1211
st "github.com/quick-trade/xoney/strategy"
1312
)
@@ -20,6 +19,7 @@ type StepByStepBacktester struct {
2019

2120
func NewStepByStepBacktester(simulator exchange.Simulator) *StepByStepBacktester {
2221
return &StepByStepBacktester{
22+
system: nil,
2323
equity: data.Equity{},
2424
simulator: simulator,
2525
}

common/account.go

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (p Portfolio) Total(prices map[data.Currency]float64) (float64, error) {
5454
func (p Portfolio) Balance(currency data.Currency) float64 {
5555
return p.assets[currency]
5656
}
57+
5758
// Assets returns a reference to the current assets held in the portfolio.
5859
// Be cautious when using this reference directly as it can alter the portfolio's state.
5960
// Consider using .Copy() method for a safe, mutable copy if needed.

common/data/candlestick.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func NewTimeStamp(timeframe TimeFrame, capacity int) TimeStamp {
4545
func (t *TimeStamp) Timeframe() TimeFrame {
4646
return t.timeframe
4747
}
48+
4849
// At returns the time at the specified index within the TimeStamp.
4950
func (t TimeStamp) At(index int) time.Time {
5051
return t.Timestamp[index]
@@ -109,6 +110,7 @@ func NewCandle(open, high, low, c, volume float64, timeClose time.Time) *Candle
109110
TimeClose: timeClose,
110111
}
111112
}
113+
112114
// InstrumentCandle represents a candlestick data point with an associated financial instrument.
113115
// It combines the detailed candlestick information such as OHLCV with the specific instrument
114116
// for which this data is relevant. This data structure is commonly used in trading strategies
@@ -187,6 +189,7 @@ func (c *Chart) Slice(period Period) Chart {
187189
Timestamp: c.Timestamp.Slice(start, stop),
188190
}
189191
}
192+
190193
// Len returns the number of timestamps (and hence the number of candles) in the Chart.
191194
func (c *Chart) Len() int {
192195
return len(c.Timestamp.Timestamp)
@@ -195,10 +198,13 @@ func (c *Chart) Len() int {
195198
// CandleByIndex retrieves the candle at the specified index from the Chart.
196199
// If the index is out of range, an error is returned.
197200
// Parameters:
198-
// index - The index of the candle to retrieve.
201+
//
202+
// index - The index of the candle to retrieve.
203+
//
199204
// Returns:
200-
// pointer to a Candle and nil error if successful, or
201-
// nil pointer and an OutOfIndexError if the index is invalid.
205+
//
206+
// pointer to a Candle and nil error if successful, or
207+
// nil pointer and an OutOfIndexError if the index is invalid.
202208
func (c *Chart) CandleByIndex(index int) (*Candle, error) {
203209
if index >= c.Len() {
204210
return nil, errors.NewOutOfIndexError(index)
@@ -213,6 +219,7 @@ func (c *Chart) CandleByIndex(index int) (*Candle, error) {
213219
c.Timestamp.At(index),
214220
), nil
215221
}
222+
216223
// ChartContainer represents a collection of instruments and their corresponding charts.
217224
// It can be used to inform your trading system about your investment universe during testing and training.
218225
type ChartContainer map[Instrument]Chart

common/data/instrument.go

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func NewTimeFrame(duration time.Duration, name string) (*TimeFrame, error) {
106106
Name: name,
107107
}, nil
108108
}
109+
109110
// Instrument represents the full description of a trading instrument in financial markets.
110111
// It encapsulates all concrete details required for trading with no further abstractions for tradable currencies.
111112
// The 'symbol' uniquely identifies the financial asset, and the 'timeframe' defines the trading interval.

events/events.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func (p *Parallel) Occur(connector exchange.Connector) error {
133133

134134
for _, action := range p.actions {
135135
wg.Add(1)
136+
136137
go func(act Event) {
137138
defer wg.Done()
138139
if err := act.Occur(connector); err != nil {
@@ -144,7 +145,7 @@ func (p *Parallel) Occur(connector exchange.Connector) error {
144145
wg.Wait()
145146
close(errorsChan)
146147

147-
var errorsList []string
148+
errorsList := make([]string, 0, len(p.actions))
148149
for err := range errorsChan {
149150
errorsList = append(errorsList, err)
150151
}

test/toolkit/rebalancer_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ func (m *MockConnector) GetPrices(symbols []data.Symbol) (<-chan exchange.Symbol
159159
go func() {
160160
defer close(priceChan)
161161
defer close(errChan)
162+
162163
for _, symbol := range symbols {
163164
price, ok := m.prices[symbol]
164165
if !ok {
165166
errChan <- errors.NewNoPriceError(symbol.String())
167+
166168
return
167169
}
168170
priceChan <- *exchange.NewSymbolPrice(symbol, price)
@@ -188,13 +190,15 @@ func NewMockConnector(portfolio common.Portfolio) *MockConnector {
188190
// mapSubtract takes two maps of data.Symbol to float64 and returns a new map with the subtraction result.
189191
func mapSubtract[T comparable](a, b map[T]float64) map[T]float64 {
190192
result := make(map[T]float64)
193+
191194
for k, v := range a {
192195
if bv, ok := b[k]; ok {
193196
result[k] = v - bv
194197
} else {
195198
result[k] = v
196199
}
197200
}
201+
198202
for k, bv := range b {
199203
if _, ok := a[k]; !ok {
200204
result[k] = -bv

0 commit comments

Comments
 (0)