Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zale144 committed Oct 10, 2022
1 parent 6e10b55 commit b44702f
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 114 deletions.
4 changes: 4 additions & 0 deletions .golangci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ linters = ["forbidigo"]
path = "cmd/"
linters = ["forbidigo"]

[[issues.exclude-rules]]
path = "./"
linters = ["nosnakecase","exhaustruct"]

[[issues.exclude-rules]]
path = "flags.go"
linters = ["forbidigo"]
Expand Down
5 changes: 3 additions & 2 deletions account/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func (a *Service) EnsureBalance(ctx context.Context, assetID string, targetAmoun
return nil
}

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

func (a *Service) getStore(assetID string) (_ data.BalanceStore, err error) {
func (a *Service) getStore(assetID string) (data.BalanceStore, error) {
var err error

store, ok := a.stores[assetID]
if !ok {
store, err = a.accountStream.GetBalances(assetID)
Expand Down
4 changes: 2 additions & 2 deletions bot/normal/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func discreteThreeLevelProbabilities(V []float64, muHat float64, sigmaHat float6
// generatePriceUsingDiscreteThreeLevel is a method for calculating price levels
// input is a float price (so divide uint64 price by 10^{num of decimals})
// it returns a float price which you want to multiply by 10^{num of decimals} and then round.
func generatePriceUsingDiscreteThreeLevel(m0, delta, sigma, tgtTimeHorizonYrFrac, n float64) (price float64, err error) {
func generatePriceUsingDiscreteThreeLevel(m0, delta, sigma, tgtTimeHorizonYrFrac, n float64) (float64, error) {
muHat := -0.5 * sigma * sigma * tgtTimeHorizonYrFrac
sigmaHat := math.Sqrt(n*tgtTimeHorizonYrFrac) * sigma
v := make([]float64, 3)
Expand All @@ -117,7 +117,7 @@ func generatePriceUsingDiscreteThreeLevel(m0, delta, sigma, tgtTimeHorizonYrFrac
shockX := v[randomChoice(probabilities)]
y := math.Exp(shockX / n)

price = m0 * y
price := m0 * y

return price, nil
}
Expand Down
7 changes: 2 additions & 5 deletions bot/normal/normal.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,8 @@ func (b *bot) Start() error {
func (b *bot) pauseChannel() chan types.PauseSignal {
in := make(chan types.PauseSignal)
go func() {
for {
select {
case p := <-in:
b.Pause(p)
}
for p := range in {
b.Pause(p)
}
}()
return in
Expand Down
2 changes: 0 additions & 2 deletions bot/normal/position_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,6 @@ func (b *bot) calculateOrderSizes(obligation *num.Uint, liquidityOrders []*vega.
}

order := vega.Order{
//MarketId: b.marketID,
//PartyId: b.walletPubKey,
Side: vega.Side_SIDE_BUY,
Remaining: size.Uint64(),
Size: size.Uint64(),
Expand Down
4 changes: 2 additions & 2 deletions cmd/liqbot/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
// provide liquidity. Each bot connects to one Vega node and submits orders to
// one market.
//
// $ make install
// $ $GOPATH/bin/liqbot -config=config.yml
// $ make install
// $ $GOPATH/bin/liqbot -config=config.yml
package main
2 changes: 0 additions & 2 deletions data/streamingaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type account struct {
busEvProc busEventer

mu sync.Mutex
once sync.Once
waitingDeposits map[string]*num.Uint
}

Expand Down Expand Up @@ -293,7 +292,6 @@ func (a *account) WaitForStakeLinking(pubKey string) error {
} else {
return true, fmt.Errorf("stake linking failed: %s", stake.Status.String())
}

}
a.log.WithFields(log.Fields{
"name": a.name,
Expand Down
2 changes: 1 addition & 1 deletion market/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type PricingEngine interface {
GetPrice(pricecfg ppconfig.PriceConfig) (ppservice.PriceResponse, error)
}

// TODO: this could be improved: pubKey could be specified in config,
// TODO: this could be improved: pubKey could be specified in config.
type marketStream interface {
Init(pubKey string, pauseCh chan types.PauseSignal) (data.MarketStore, error)
Subscribe(marketID string) error
Expand Down
1 change: 0 additions & 1 deletion market/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ func (m *Service) FindMarket() (*vega.Market, error) {
continue
}

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

Expand Down
110 changes: 52 additions & 58 deletions node/datanode.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func (n *DataNode) dialNode(ctx context.Context, host string) {
n.mu.Lock()
n.conn = conn
n.mu.Unlock()
return
}

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

// SubmitTransaction submits a signed v2 transaction.
func (n *DataNode) SubmitTransaction(req *vegaapipb.SubmitTransactionRequest) (response *vegaapipb.SubmitTransactionResponse, err error) {
func (n *DataNode) SubmitTransaction(req *vegaapipb.SubmitTransactionRequest) (*vegaapipb.SubmitTransactionResponse, error) {
msg := "gRPC call failed: SubmitTransaction: %w"
if n == nil {
err = fmt.Errorf(msg, e.ErrNil)
return
return nil, fmt.Errorf(msg, e.ErrNil)
}

if n.conn.GetState() != connectivity.Ready {
err = fmt.Errorf(msg, e.ErrConnectionNotReady)
return
return nil, fmt.Errorf(msg, e.ErrConnectionNotReady)
}

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

response, err = c.SubmitTransaction(ctx, req)
response, err := c.SubmitTransaction(ctx, req)
if err != nil {
err = fmt.Errorf(msg, e.ErrorDetail(err))
return nil, fmt.Errorf(msg, e.ErrorDetail(err))
}
return

return response, nil
}

// LastBlockData gets the latest blockchain data, height, hash and pow parameters.
Expand All @@ -130,157 +128,153 @@ func (n *DataNode) LastBlockData() (*vegaapipb.LastBlockHeightResponse, error) {
c := vegaapipb.NewCoreServiceClient(n.conn)
ctx, cancel := context.WithTimeout(context.Background(), n.callTimeout)
defer cancel()

var response *vegaapipb.LastBlockHeightResponse

response, err := c.LastBlockHeight(ctx, &vegaapipb.LastBlockHeightRequest{})
if err != nil {
err = fmt.Errorf(msg, e.ErrorDetail(err))
}

return response, err
}

// ObserveEventBus opens a stream.
func (n *DataNode) ObserveEventBus(ctx context.Context) (client vegaapipb.CoreService_ObserveEventBusClient, err error) {
func (n *DataNode) ObserveEventBus(ctx context.Context) (vegaapipb.CoreService_ObserveEventBusClient, error) {
msg := "gRPC call failed: ObserveEventBus: %w"
if n == nil {
err = fmt.Errorf(msg, e.ErrNil)
return
return nil, fmt.Errorf(msg, e.ErrNil)
}

if n.conn == nil || n.conn.GetState() != connectivity.Ready {
err = fmt.Errorf(msg, e.ErrConnectionNotReady)
return
return nil, fmt.Errorf(msg, e.ErrConnectionNotReady)
}

c := vegaapipb.NewCoreServiceClient(n.conn)
// no timeout on streams
client, err = c.ObserveEventBus(ctx)
client, err := c.ObserveEventBus(ctx)
if err != nil {
err = fmt.Errorf(msg, e.ErrorDetail(err))
return
return nil, fmt.Errorf(msg, e.ErrorDetail(err))
}
return

return client, nil
}

// === TradingDataService ===

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

if n.conn.GetState() != connectivity.Ready {
err = fmt.Errorf(msg, e.ErrConnectionNotReady)
return
return nil, fmt.Errorf(msg, e.ErrConnectionNotReady)
}

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

response, err = c.PartyAccounts(ctx, req)
response, err := c.PartyAccounts(ctx, req)
if err != nil {
err = fmt.Errorf(msg, e.ErrorDetail(err))
return nil, fmt.Errorf(msg, e.ErrorDetail(err))
}
return

return response, nil
}

// MarketDataByID returns market data for the specified market.
func (n *DataNode) MarketDataByID(req *dataapipb.MarketDataByIDRequest) (response *dataapipb.MarketDataByIDResponse, err error) {
func (n *DataNode) MarketDataByID(req *dataapipb.MarketDataByIDRequest) (*dataapipb.MarketDataByIDResponse, error) {
msg := "gRPC call failed (data-node): MarketDataByID: %w"
if n == nil {
err = fmt.Errorf(msg, e.ErrNil)
return
return nil, fmt.Errorf(msg, e.ErrNil)
}

if n.conn.GetState() != connectivity.Ready {
err = fmt.Errorf(msg, e.ErrConnectionNotReady)
return
return nil, fmt.Errorf(msg, e.ErrConnectionNotReady)
}

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

response, err = c.MarketDataByID(ctx, req)
response, err := c.MarketDataByID(ctx, req)
if err != nil {
err = fmt.Errorf(msg, e.ErrorDetail(err))
return nil, fmt.Errorf(msg, e.ErrorDetail(err))
}
return

return response, nil
}

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

if n.conn.GetState() != connectivity.Ready {
err = fmt.Errorf(msg, e.ErrConnectionNotReady)
return
return nil, fmt.Errorf(msg, e.ErrConnectionNotReady)
}

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

response, err = c.Markets(ctx, req)
response, err := c.Markets(ctx, req)
if err != nil {
err = fmt.Errorf(msg, e.ErrorDetail(err))
return nil, fmt.Errorf(msg, e.ErrorDetail(err))
}
return

return response, nil
}

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

if n.conn.GetState() != connectivity.Ready {
err = fmt.Errorf(msg, e.ErrConnectionNotReady)
return
return nil, fmt.Errorf(msg, e.ErrConnectionNotReady)
}

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

response, err = c.PositionsByParty(ctx, req)
response, err := c.PositionsByParty(ctx, req)
if err != nil {
err = fmt.Errorf(msg, e.ErrorDetail(err))
return nil, fmt.Errorf(msg, e.ErrorDetail(err))
}
return

return response, nil
}

// AssetByID returns the specified asset.
func (n *DataNode) AssetByID(req *dataapipb.AssetByIDRequest) (response *dataapipb.AssetByIDResponse, err error) {
func (n *DataNode) AssetByID(req *dataapipb.AssetByIDRequest) (*dataapipb.AssetByIDResponse, error) {
msg := "gRPC call failed (data-node): AssetByID: %w"
if n == nil {
err = fmt.Errorf(msg, e.ErrNil)
return
return nil, fmt.Errorf(msg, e.ErrNil)
}

if n.conn.GetState() != connectivity.Ready {
err = fmt.Errorf(msg, e.ErrConnectionNotReady)
return
return nil, fmt.Errorf(msg, e.ErrConnectionNotReady)
}

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

response, err = c.AssetByID(ctx, req)
response, err := c.AssetByID(ctx, req)
if err != nil {
err = fmt.Errorf(msg, e.ErrorDetail(err))
return nil, fmt.Errorf(msg, e.ErrorDetail(err))
}
return

return response, nil
}

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

0 comments on commit b44702f

Please sign in to comment.