Skip to content

Commit

Permalink
Optimisation: large structs/huge param fixes (part 2) (thrasher-corp#262
Browse files Browse the repository at this point in the history
)

* updated golangci config to enable hugeparam linter

* ModifyOrder struct usage converted to a pointer

* OrderBook conversion to struct

* More conversion of large structs to pointers

* updated golangci config to enable hugeparam linter

* ModifyOrder struct usage converted to a pointer

* OrderBook conversion to struct

* More conversion of large structs to pointers

* disabled hugeParam check for golang again

* changed based on suggested feedback and fix for no default provider

* fixed typing
  • Loading branch information
xtda authored and thrasher- committed Mar 26, 2019
1 parent 5683fdd commit dc236c2
Show file tree
Hide file tree
Showing 87 changed files with 234 additions and 232 deletions.
6 changes: 3 additions & 3 deletions currency/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (b *BaseCodes) RegisterFiat(c string) (Code, error) {
}

// LoadItem sets item data
func (b *BaseCodes) LoadItem(item Item) error {
func (b *BaseCodes) LoadItem(item *Item) error {
b.mtx.Lock()
defer b.mtx.Unlock()
for i := range b.Items {
Expand Down Expand Up @@ -386,7 +386,7 @@ func (b *BaseCodes) LoadItem(item Item) error {
}
}

b.Items = append(b.Items, &item)
b.Items = append(b.Items, item)
return nil
}

Expand Down Expand Up @@ -414,7 +414,7 @@ type Item struct {
}

// String conforms to the stringer interface
func (i Item) String() string {
func (i *Item) String() string {
return i.FullName
}

Expand Down
4 changes: 2 additions & 2 deletions currency/code_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func TestBaseCode(t *testing.T) {
true)
}

err = main.LoadItem(Item{
err = main.LoadItem(&Item{
ID: 0,
FullName: "Cardano",
Role: Cryptocurrency,
Expand Down Expand Up @@ -421,6 +421,6 @@ func TestItemString(t *testing.T) {
if newItem.String() != expected {
t.Errorf("Test Failed - Item String() error expected %s but recieved %s",
expected,
newItem)
&newItem)
}
}
2 changes: 1 addition & 1 deletion currency/forexprovider/forexprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func StartFXService(fxProviders []base.Settings) (*ForexProviders, error) {
}

if handler.Primary.Provider == nil {
return nil, errors.New("no foreign exchange providers enabled")
return nil, errors.New("no primary forex provider enabled")
}

return handler, nil
Expand Down
25 changes: 13 additions & 12 deletions currency/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func (s *Storage) SeedCurrencyAnalysisData() error {
return err
}

err = s.LoadFileCurrencyData(fromFile)
err = s.LoadFileCurrencyData(&fromFile)
if err != nil {
return err
}
Expand Down Expand Up @@ -369,37 +369,38 @@ func (s *Storage) WriteCurrencyDataToFile(path string, mainUpdate bool) error {
}

// LoadFileCurrencyData loads currencies into the currency codes
func (s *Storage) LoadFileCurrencyData(f File) error {
for _, contract := range f.Contracts {
err := s.currencyCodes.LoadItem(contract)
func (s *Storage) LoadFileCurrencyData(f *File) error {

for i := range f.Contracts {
err := s.currencyCodes.LoadItem(&f.Contracts[i])
if err != nil {
return err
}
}

for _, crypto := range f.Cryptocurrency {
err := s.currencyCodes.LoadItem(crypto)
for i := range f.Cryptocurrency {
err := s.currencyCodes.LoadItem(&f.Cryptocurrency[i])
if err != nil {
return err
}
}

for _, fiat := range f.FiatCurrency {
err := s.currencyCodes.LoadItem(fiat)
for i := range f.Token {
err := s.currencyCodes.LoadItem(&f.Token[i])
if err != nil {
return err
}
}

for _, token := range f.Token {
err := s.currencyCodes.LoadItem(token)
for i := range f.FiatCurrency {
err := s.currencyCodes.LoadItem(&f.FiatCurrency[i])
if err != nil {
return err
}
}

for _, unset := range f.UnsetCurrency {
err := s.currencyCodes.LoadItem(unset)
for i := range f.UnsetCurrency {
err := s.currencyCodes.LoadItem(&f.UnsetCurrency[i])
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion exchanges/alphapoint/alphapoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ func TestModifyOrder(t *testing.T) {
a := &Alphapoint{}
a.SetDefaults()

_, err := a.ModifyOrder(exchange.ModifyOrder{})
_, err := a.ModifyOrder(&exchange.ModifyOrder{})
if err == nil {
t.Error("Test failed - ModifyOrder() error")
}
Expand Down
2 changes: 1 addition & 1 deletion exchanges/alphapoint/alphapoint_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (a *Alphapoint) SubmitOrder(p currency.Pair, side exchange.OrderSide, order

// ModifyOrder will allow of changing orderbook placement and limit to
// market conversion
func (a *Alphapoint) ModifyOrder(_ exchange.ModifyOrder) (string, error) {
func (a *Alphapoint) ModifyOrder(_ *exchange.ModifyOrder) (string, error) {
return "", common.ErrNotYetImplemented
}

Expand Down
2 changes: 1 addition & 1 deletion exchanges/anx/anx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func TestGetAccountInfo(t *testing.T) {
}

func TestModifyOrder(t *testing.T) {
_, err := a.ModifyOrder(exchange.ModifyOrder{})
_, err := a.ModifyOrder(&exchange.ModifyOrder{})
if err == nil {
t.Error("Test failed - ModifyOrder() error")
}
Expand Down
2 changes: 1 addition & 1 deletion exchanges/anx/anx_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (a *ANX) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderType ex

// ModifyOrder will allow of changing orderbook placement and limit to
// market conversion
func (a *ANX) ModifyOrder(action exchange.ModifyOrder) (string, error) {
func (a *ANX) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
return "", common.ErrFunctionNotSupported
}

Expand Down
2 changes: 1 addition & 1 deletion exchanges/binance/binance.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func (b *Binance) GetBestPrice(symbol string) (BestPrice, error) {
}

// NewOrder sends a new order to Binance
func (b *Binance) NewOrder(o NewOrderRequest) (NewOrderResponse, error) {
func (b *Binance) NewOrder(o *NewOrderRequest) (NewOrderResponse, error) {
var resp NewOrderResponse

path := fmt.Sprintf("%s%s", b.APIUrl, newOrder)
Expand Down
4 changes: 2 additions & 2 deletions exchanges/binance/binance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestNewOrder(t *testing.T) {
if testAPIKey == "" || testAPISecret == "" {
t.Skip()
}
_, err := b.NewOrder(NewOrderRequest{
_, err := b.NewOrder(&NewOrderRequest{
Symbol: "BTCUSDT",
Side: BinanceRequestParamsSideSell,
TradeType: BinanceRequestParamsOrderLimit,
Expand Down Expand Up @@ -466,7 +466,7 @@ func TestGetAccountInfo(t *testing.T) {
}

func TestModifyOrder(t *testing.T) {
_, err := b.ModifyOrder(exchange.ModifyOrder{})
_, err := b.ModifyOrder(&exchange.ModifyOrder{})
if err == nil {
t.Error("Test failed - ModifyOrder() error")
}
Expand Down
6 changes: 3 additions & 3 deletions exchanges/binance/binance_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ func (b *Binance) SeedLocalCache(p currency.Pair) error {
newOrderBook.Pair = currency.NewPairFromString(formattedPair.String())
newOrderBook.AssetType = ticker.Spot

return b.Websocket.Orderbook.LoadSnapshot(newOrderBook, b.GetName(), false)
return b.Websocket.Orderbook.LoadSnapshot(&newOrderBook, b.GetName(), false)
}

// UpdateLocalCache updates and returns the most recent iteration of the orderbook
func (b *Binance) UpdateLocalCache(ob WebsocketDepthStream) error {
func (b *Binance) UpdateLocalCache(ob *WebsocketDepthStream) error {
m.Lock()
ID, ok := lastUpdateID[ob.Pair]
if !ok {
Expand Down Expand Up @@ -323,7 +323,7 @@ func (b *Binance) WsHandleData() {
continue
}

err = b.UpdateLocalCache(depth)
err = b.UpdateLocalCache(&depth)
if err != nil {
b.Websocket.DataHandler <- fmt.Errorf("binance_websocket.go - UpdateLocalCache error: %s",
err)
Expand Down
4 changes: 2 additions & 2 deletions exchanges/binance/binance_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (b *Binance) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderTyp
TimeInForce: BinanceRequestParamsTimeGTC,
}

response, err := b.NewOrder(orderRequest)
response, err := b.NewOrder(&orderRequest)

if response.OrderID > 0 {
submitOrderResponse.OrderID = fmt.Sprintf("%v", response.OrderID)
Expand All @@ -247,7 +247,7 @@ func (b *Binance) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderTyp

// ModifyOrder will allow of changing orderbook placement and limit to
// market conversion
func (b *Binance) ModifyOrder(action exchange.ModifyOrder) (string, error) {
func (b *Binance) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
return "", common.ErrFunctionNotSupported
}

Expand Down
2 changes: 1 addition & 1 deletion exchanges/bitfinex/bitfinex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ func TestCancelAllExchangeOrdera(t *testing.T) {
}

func TestModifyOrder(t *testing.T) {
_, err := b.ModifyOrder(exchange.ModifyOrder{})
_, err := b.ModifyOrder(&exchange.ModifyOrder{})
if err == nil {
t.Error("Test failed - ModifyOrder() error")
}
Expand Down
12 changes: 6 additions & 6 deletions exchanges/bitfinex/bitfinex_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,13 @@ func (b *Bitfinex) WsInsertSnapshot(p currency.Pair, assetType string, books []W
return errors.New("bitfinex.go error - no orderbooks in item lists")
}

var newOrderbook orderbook.Base
newOrderbook.Asks = ask
newOrderbook.AssetType = assetType
newOrderbook.Bids = bid
newOrderbook.Pair = p
var newOrderBook orderbook.Base
newOrderBook.Asks = ask
newOrderBook.AssetType = assetType
newOrderBook.Bids = bid
newOrderBook.Pair = p

err := b.Websocket.Orderbook.LoadSnapshot(newOrderbook, b.GetName(), false)
err := b.Websocket.Orderbook.LoadSnapshot(&newOrderBook, b.GetName(), false)
if err != nil {
return fmt.Errorf("bitfinex.go error - %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion exchanges/bitfinex/bitfinex_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (b *Bitfinex) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderTy

// ModifyOrder will allow of changing orderbook placement and limit to
// market conversion
func (b *Bitfinex) ModifyOrder(action exchange.ModifyOrder) (string, error) {
func (b *Bitfinex) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
return "", common.ErrFunctionNotSupported
}

Expand Down
2 changes: 1 addition & 1 deletion exchanges/bitflyer/bitflyer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func TestWithdraw(t *testing.T) {
}

func TestModifyOrder(t *testing.T) {
_, err := b.ModifyOrder(exchange.ModifyOrder{})
_, err := b.ModifyOrder(&exchange.ModifyOrder{})
if err == nil {
t.Error("Test failed - ModifyOrder() error")
}
Expand Down
2 changes: 1 addition & 1 deletion exchanges/bitflyer/bitflyer_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (b *Bitflyer) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderTy

// ModifyOrder will allow of changing orderbook placement and limit to
// market conversion
func (b *Bitflyer) ModifyOrder(action exchange.ModifyOrder) (string, error) {
func (b *Bitflyer) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
return "", common.ErrFunctionNotSupported
}

Expand Down
2 changes: 1 addition & 1 deletion exchanges/bithumb/bithumb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func TestGetAccountInfo(t *testing.T) {

func TestModifyOrder(t *testing.T) {
curr := currency.NewPairFromString("BTCUSD")
_, err := b.ModifyOrder(exchange.ModifyOrder{OrderID: "1337",
_, err := b.ModifyOrder(&exchange.ModifyOrder{OrderID: "1337",
Price: 100,
Amount: 1000,
OrderSide: exchange.SellOrderSide,
Expand Down
2 changes: 1 addition & 1 deletion exchanges/bithumb/bithumb_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (b *Bithumb) SubmitOrder(p currency.Pair, side exchange.OrderSide, _ exchan

// ModifyOrder will allow of changing orderbook placement and limit to
// market conversion
func (b *Bithumb) ModifyOrder(action exchange.ModifyOrder) (string, error) {
func (b *Bithumb) ModifyOrder(action *exchange.ModifyOrder) (string, error) {
order, err := b.ModifyTrade(action.OrderID,
action.CurrencyPair.Base.String(),
common.StringToLower(action.OrderSide.ToString()),
Expand Down
Loading

0 comments on commit dc236c2

Please sign in to comment.