Skip to content

Commit b44702f

Browse files
committed
Fix linting errors
1 parent 6e10b55 commit b44702f

File tree

17 files changed

+102
-114
lines changed

17 files changed

+102
-114
lines changed

.golangci.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ linters = ["forbidigo"]
8080
path = "cmd/"
8181
linters = ["forbidigo"]
8282

83+
[[issues.exclude-rules]]
84+
path = "./"
85+
linters = ["nosnakecase","exhaustruct"]
86+
8387
[[issues.exclude-rules]]
8488
path = "flags.go"
8589
linters = ["forbidigo"]

account/service.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ func (a *Service) EnsureBalance(ctx context.Context, assetID string, targetAmoun
8080
return nil
8181
}
8282

83-
// TODO: DRY
8483
func (a *Service) EnsureStake(ctx context.Context, receiverName, receiverPubKey, assetID string, targetAmount *num.Uint, from string) error {
8584
if receiverPubKey == "" {
8685
return fmt.Errorf("receiver public key is empty")
@@ -147,7 +146,9 @@ func (a *Service) Balance() types.Balance {
147146
return store.Balance()
148147
}
149148

150-
func (a *Service) getStore(assetID string) (_ data.BalanceStore, err error) {
149+
func (a *Service) getStore(assetID string) (data.BalanceStore, error) {
150+
var err error
151+
151152
store, ok := a.stores[assetID]
152153
if !ok {
153154
store, err = a.accountStream.GetBalances(assetID)

bot/normal/helpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func discreteThreeLevelProbabilities(V []float64, muHat float64, sigmaHat float6
9999
// generatePriceUsingDiscreteThreeLevel is a method for calculating price levels
100100
// input is a float price (so divide uint64 price by 10^{num of decimals})
101101
// it returns a float price which you want to multiply by 10^{num of decimals} and then round.
102-
func generatePriceUsingDiscreteThreeLevel(m0, delta, sigma, tgtTimeHorizonYrFrac, n float64) (price float64, err error) {
102+
func generatePriceUsingDiscreteThreeLevel(m0, delta, sigma, tgtTimeHorizonYrFrac, n float64) (float64, error) {
103103
muHat := -0.5 * sigma * sigma * tgtTimeHorizonYrFrac
104104
sigmaHat := math.Sqrt(n*tgtTimeHorizonYrFrac) * sigma
105105
v := make([]float64, 3)
@@ -117,7 +117,7 @@ func generatePriceUsingDiscreteThreeLevel(m0, delta, sigma, tgtTimeHorizonYrFrac
117117
shockX := v[randomChoice(probabilities)]
118118
y := math.Exp(shockX / n)
119119

120-
price = m0 * y
120+
price := m0 * y
121121

122122
return price, nil
123123
}

bot/normal/normal.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,8 @@ func (b *bot) Start() error {
140140
func (b *bot) pauseChannel() chan types.PauseSignal {
141141
in := make(chan types.PauseSignal)
142142
go func() {
143-
for {
144-
select {
145-
case p := <-in:
146-
b.Pause(p)
147-
}
143+
for p := range in {
144+
b.Pause(p)
148145
}
149146
}()
150147
return in

bot/normal/position_management.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,6 @@ func (b *bot) calculateOrderSizes(obligation *num.Uint, liquidityOrders []*vega.
459459
}
460460

461461
order := vega.Order{
462-
//MarketId: b.marketID,
463-
//PartyId: b.walletPubKey,
464462
Side: vega.Side_SIDE_BUY,
465463
Remaining: size.Uint64(),
466464
Size: size.Uint64(),

cmd/liqbot/doc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
// provide liquidity. Each bot connects to one Vega node and submits orders to
33
// one market.
44
//
5-
// $ make install
6-
// $ $GOPATH/bin/liqbot -config=config.yml
5+
// $ make install
6+
// $ $GOPATH/bin/liqbot -config=config.yml
77
package main

data/streamingaccount.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ type account struct {
2626
busEvProc busEventer
2727

2828
mu sync.Mutex
29-
once sync.Once
3029
waitingDeposits map[string]*num.Uint
3130
}
3231

@@ -293,7 +292,6 @@ func (a *account) WaitForStakeLinking(pubKey string) error {
293292
} else {
294293
return true, fmt.Errorf("stake linking failed: %s", stake.Status.String())
295294
}
296-
297295
}
298296
a.log.WithFields(log.Fields{
299297
"name": a.name,

market/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type PricingEngine interface {
1919
GetPrice(pricecfg ppconfig.PriceConfig) (ppservice.PriceResponse, error)
2020
}
2121

22-
// TODO: this could be improved: pubKey could be specified in config,
22+
// TODO: this could be improved: pubKey could be specified in config.
2323
type marketStream interface {
2424
Init(pubKey string, pauseCh chan types.PauseSignal) (data.MarketStore, error)
2525
Subscribe(marketID string) error

market/service.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ func (m *Service) FindMarket() (*vega.Market, error) {
153153
continue
154154
}
155155

156-
//m.settlementAssetID = market.TradableInstrument.Instrument.GetFuture().SettlementAsset
157156
m.log = m.log.WithFields(log.Fields{"marketID": mkt.Id})
158157
m.decimalPlaces = mkt.DecimalPlaces
159158

node/datanode.go

Lines changed: 52 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ func (n *DataNode) dialNode(ctx context.Context, host string) {
8383
n.mu.Lock()
8484
n.conn = conn
8585
n.mu.Unlock()
86-
return
8786
}
8887

8988
func (n *DataNode) Target() string {
@@ -93,27 +92,26 @@ func (n *DataNode) Target() string {
9392
// === CoreService ===
9493

9594
// SubmitTransaction submits a signed v2 transaction.
96-
func (n *DataNode) SubmitTransaction(req *vegaapipb.SubmitTransactionRequest) (response *vegaapipb.SubmitTransactionResponse, err error) {
95+
func (n *DataNode) SubmitTransaction(req *vegaapipb.SubmitTransactionRequest) (*vegaapipb.SubmitTransactionResponse, error) {
9796
msg := "gRPC call failed: SubmitTransaction: %w"
9897
if n == nil {
99-
err = fmt.Errorf(msg, e.ErrNil)
100-
return
98+
return nil, fmt.Errorf(msg, e.ErrNil)
10199
}
102100

103101
if n.conn.GetState() != connectivity.Ready {
104-
err = fmt.Errorf(msg, e.ErrConnectionNotReady)
105-
return
102+
return nil, fmt.Errorf(msg, e.ErrConnectionNotReady)
106103
}
107104

108105
c := vegaapipb.NewCoreServiceClient(n.conn)
109106
ctx, cancel := context.WithTimeout(context.Background(), n.callTimeout)
110107
defer cancel()
111108

112-
response, err = c.SubmitTransaction(ctx, req)
109+
response, err := c.SubmitTransaction(ctx, req)
113110
if err != nil {
114-
err = fmt.Errorf(msg, e.ErrorDetail(err))
111+
return nil, fmt.Errorf(msg, e.ErrorDetail(err))
115112
}
116-
return
113+
114+
return response, nil
117115
}
118116

119117
// LastBlockData gets the latest blockchain data, height, hash and pow parameters.
@@ -130,157 +128,153 @@ func (n *DataNode) LastBlockData() (*vegaapipb.LastBlockHeightResponse, error) {
130128
c := vegaapipb.NewCoreServiceClient(n.conn)
131129
ctx, cancel := context.WithTimeout(context.Background(), n.callTimeout)
132130
defer cancel()
131+
133132
var response *vegaapipb.LastBlockHeightResponse
133+
134134
response, err := c.LastBlockHeight(ctx, &vegaapipb.LastBlockHeightRequest{})
135135
if err != nil {
136136
err = fmt.Errorf(msg, e.ErrorDetail(err))
137137
}
138+
138139
return response, err
139140
}
140141

141142
// ObserveEventBus opens a stream.
142-
func (n *DataNode) ObserveEventBus(ctx context.Context) (client vegaapipb.CoreService_ObserveEventBusClient, err error) {
143+
func (n *DataNode) ObserveEventBus(ctx context.Context) (vegaapipb.CoreService_ObserveEventBusClient, error) {
143144
msg := "gRPC call failed: ObserveEventBus: %w"
144145
if n == nil {
145-
err = fmt.Errorf(msg, e.ErrNil)
146-
return
146+
return nil, fmt.Errorf(msg, e.ErrNil)
147147
}
148148

149149
if n.conn == nil || n.conn.GetState() != connectivity.Ready {
150-
err = fmt.Errorf(msg, e.ErrConnectionNotReady)
151-
return
150+
return nil, fmt.Errorf(msg, e.ErrConnectionNotReady)
152151
}
153152

154153
c := vegaapipb.NewCoreServiceClient(n.conn)
155154
// no timeout on streams
156-
client, err = c.ObserveEventBus(ctx)
155+
client, err := c.ObserveEventBus(ctx)
157156
if err != nil {
158-
err = fmt.Errorf(msg, e.ErrorDetail(err))
159-
return
157+
return nil, fmt.Errorf(msg, e.ErrorDetail(err))
160158
}
161-
return
159+
160+
return client, nil
162161
}
163162

164163
// === TradingDataService ===
165164

166165
// PartyAccounts returns accounts for the given party.
167-
func (n *DataNode) PartyAccounts(req *dataapipb.PartyAccountsRequest) (response *dataapipb.PartyAccountsResponse, err error) {
166+
func (n *DataNode) PartyAccounts(req *dataapipb.PartyAccountsRequest) (*dataapipb.PartyAccountsResponse, error) {
168167
msg := "gRPC call failed (data-node): PartyAccounts: %w"
169168
if n == nil {
170-
err = fmt.Errorf(msg, e.ErrNil)
171-
return
169+
return nil, fmt.Errorf(msg, e.ErrNil)
172170
}
173171

174172
if n.conn.GetState() != connectivity.Ready {
175-
err = fmt.Errorf(msg, e.ErrConnectionNotReady)
176-
return
173+
return nil, fmt.Errorf(msg, e.ErrConnectionNotReady)
177174
}
178175

179176
c := dataapipb.NewTradingDataServiceClient(n.conn)
180177
ctx, cancel := context.WithTimeout(context.Background(), n.callTimeout)
181178
defer cancel()
182179

183-
response, err = c.PartyAccounts(ctx, req)
180+
response, err := c.PartyAccounts(ctx, req)
184181
if err != nil {
185-
err = fmt.Errorf(msg, e.ErrorDetail(err))
182+
return nil, fmt.Errorf(msg, e.ErrorDetail(err))
186183
}
187-
return
184+
185+
return response, nil
188186
}
189187

190188
// MarketDataByID returns market data for the specified market.
191-
func (n *DataNode) MarketDataByID(req *dataapipb.MarketDataByIDRequest) (response *dataapipb.MarketDataByIDResponse, err error) {
189+
func (n *DataNode) MarketDataByID(req *dataapipb.MarketDataByIDRequest) (*dataapipb.MarketDataByIDResponse, error) {
192190
msg := "gRPC call failed (data-node): MarketDataByID: %w"
193191
if n == nil {
194-
err = fmt.Errorf(msg, e.ErrNil)
195-
return
192+
return nil, fmt.Errorf(msg, e.ErrNil)
196193
}
197194

198195
if n.conn.GetState() != connectivity.Ready {
199-
err = fmt.Errorf(msg, e.ErrConnectionNotReady)
200-
return
196+
return nil, fmt.Errorf(msg, e.ErrConnectionNotReady)
201197
}
202198

203199
c := dataapipb.NewTradingDataServiceClient(n.conn)
204200
ctx, cancel := context.WithTimeout(context.Background(), n.callTimeout)
205201
defer cancel()
206202

207-
response, err = c.MarketDataByID(ctx, req)
203+
response, err := c.MarketDataByID(ctx, req)
208204
if err != nil {
209-
err = fmt.Errorf(msg, e.ErrorDetail(err))
205+
return nil, fmt.Errorf(msg, e.ErrorDetail(err))
210206
}
211-
return
207+
208+
return response, nil
212209
}
213210

214211
// Markets returns all markets.
215-
func (n *DataNode) Markets(req *dataapipb.MarketsRequest) (response *dataapipb.MarketsResponse, err error) {
212+
func (n *DataNode) Markets(req *dataapipb.MarketsRequest) (*dataapipb.MarketsResponse, error) {
216213
msg := "gRPC call failed (data-node): Markets: %w"
217214
if n == nil {
218-
err = fmt.Errorf(msg, e.ErrNil)
219-
return
215+
return nil, fmt.Errorf(msg, e.ErrNil)
220216
}
221217

222218
if n.conn.GetState() != connectivity.Ready {
223-
err = fmt.Errorf(msg, e.ErrConnectionNotReady)
224-
return
219+
return nil, fmt.Errorf(msg, e.ErrConnectionNotReady)
225220
}
226221

227222
c := dataapipb.NewTradingDataServiceClient(n.conn)
228223
ctx, cancel := context.WithTimeout(context.Background(), n.callTimeout)
229224
defer cancel()
230225

231-
response, err = c.Markets(ctx, req)
226+
response, err := c.Markets(ctx, req)
232227
if err != nil {
233-
err = fmt.Errorf(msg, e.ErrorDetail(err))
228+
return nil, fmt.Errorf(msg, e.ErrorDetail(err))
234229
}
235-
return
230+
231+
return response, nil
236232
}
237233

238234
// PositionsByParty returns positions for the given party.
239-
func (n *DataNode) PositionsByParty(req *dataapipb.PositionsByPartyRequest) (response *dataapipb.PositionsByPartyResponse, err error) {
235+
func (n *DataNode) PositionsByParty(req *dataapipb.PositionsByPartyRequest) (*dataapipb.PositionsByPartyResponse, error) {
240236
msg := "gRPC call failed (data-node): PositionsByParty: %w"
241237
if n == nil {
242-
err = fmt.Errorf(msg, e.ErrNil)
243-
return
238+
return nil, fmt.Errorf(msg, e.ErrNil)
244239
}
245240

246241
if n.conn.GetState() != connectivity.Ready {
247-
err = fmt.Errorf(msg, e.ErrConnectionNotReady)
248-
return
242+
return nil, fmt.Errorf(msg, e.ErrConnectionNotReady)
249243
}
250244

251245
c := dataapipb.NewTradingDataServiceClient(n.conn)
252246
ctx, cancel := context.WithTimeout(context.Background(), n.callTimeout)
253247
defer cancel()
254248

255-
response, err = c.PositionsByParty(ctx, req)
249+
response, err := c.PositionsByParty(ctx, req)
256250
if err != nil {
257-
err = fmt.Errorf(msg, e.ErrorDetail(err))
251+
return nil, fmt.Errorf(msg, e.ErrorDetail(err))
258252
}
259-
return
253+
254+
return response, nil
260255
}
261256

262257
// AssetByID returns the specified asset.
263-
func (n *DataNode) AssetByID(req *dataapipb.AssetByIDRequest) (response *dataapipb.AssetByIDResponse, err error) {
258+
func (n *DataNode) AssetByID(req *dataapipb.AssetByIDRequest) (*dataapipb.AssetByIDResponse, error) {
264259
msg := "gRPC call failed (data-node): AssetByID: %w"
265260
if n == nil {
266-
err = fmt.Errorf(msg, e.ErrNil)
267-
return
261+
return nil, fmt.Errorf(msg, e.ErrNil)
268262
}
269263

270264
if n.conn.GetState() != connectivity.Ready {
271-
err = fmt.Errorf(msg, e.ErrConnectionNotReady)
272-
return
265+
return nil, fmt.Errorf(msg, e.ErrConnectionNotReady)
273266
}
274267

275268
c := dataapipb.NewTradingDataServiceClient(n.conn)
276269
ctx, cancel := context.WithTimeout(context.Background(), n.callTimeout)
277270
defer cancel()
278271

279-
response, err = c.AssetByID(ctx, req)
272+
response, err := c.AssetByID(ctx, req)
280273
if err != nil {
281-
err = fmt.Errorf(msg, e.ErrorDetail(err))
274+
return nil, fmt.Errorf(msg, e.ErrorDetail(err))
282275
}
283-
return
276+
277+
return response, nil
284278
}
285279

286280
func (n *DataNode) WaitForStateChange(ctx context.Context, state connectivity.State) bool {

0 commit comments

Comments
 (0)