unageanu/jiji2

View on GitHub
src/jiji/model/trading/internal/position_builder.rb

Summary

Maintainability
B
5 hrs
Test Coverage

Class has too many lines. [110/100]
Open

  class PositionBuilder

    include Jiji::Model::Trading
    include Jiji::Model::Trading::Utils

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for build_from_order is too high. [17.29/15]
Open

    def build_from_order(order, tick, account_currency, agent = nil)
      position = Position.new do |p|
        initialize_trading_information(p, @backtest, order.internal_id,
          order.pair_name, order.units, order.sell_or_buy)
        price = order.type == :market ? PricingUtils.calculate_entry_price(

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [11/10]
Open

    def build_from_order(order, tick, account_currency, agent = nil)
      position = Position.new do |p|
        initialize_trading_information(p, @backtest, order.internal_id,
          order.pair_name, order.units, order.sell_or_buy)
        price = order.type == :market ? PricingUtils.calculate_entry_price(

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method build_from_tick has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def build_from_tick(internal_id, pair_name,
      units, sell_or_buy, tick, account_currency, options = {})
Severity: Major
Found in src/jiji/model/trading/internal/position_builder.rb - About 50 mins to fix

    Method initialize_trading_information has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def initialize_trading_information(position,
          backtest, internal_id, pair_name, units, sell_or_buy)
    Severity: Minor
    Found in src/jiji/model/trading/internal/position_builder.rb - About 45 mins to fix

      Method initialize_price_and_time_from_tick has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

            position, tick, pair_name, sell_or_buy, account_currency)
      Severity: Minor
      Found in src/jiji/model/trading/internal/position_builder.rb - About 35 mins to fix

        Method create_splited_position has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def create_splited_position(position,
              units, price, time, agent)
        Severity: Minor
        Found in src/jiji/model/trading/internal/position_builder.rb - About 35 mins to fix

          Method split_and_close has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def split_and_close(position, units,
                price, time, agent = nil)
          Severity: Minor
          Found in src/jiji/model/trading/internal/position_builder.rb - About 35 mins to fix

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                def initialize_trading_information_from_trade_opend_of_order_result(position, trade)
                  pair_name = Jiji::Model::Securities::Internal::Utils::Converter\
                    .convert_instrument_to_pair_name(trade['instrument'])
                  initialize_trading_information(position, @backtest,
                    trade['tradeID'], pair_name, trade['units'].to_i.abs,
            Severity: Minor
            Found in src/jiji/model/trading/internal/position_builder.rb and 1 other location - About 25 mins to fix
            src/jiji/model/trading/internal/position_builder.rb on lines 118..123

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 30.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                def initialize_trading_information_from_trade(position, trade)
                  pair_name = Jiji::Model::Securities::Internal::Utils::Converter\
                    .convert_instrument_to_pair_name(trade['instrument'])
                  initialize_trading_information(position, @backtest,
                    trade['id'], pair_name, trade['currentUnits'].to_i.abs,
            Severity: Minor
            Found in src/jiji/model/trading/internal/position_builder.rb and 1 other location - About 25 mins to fix
            src/jiji/model/trading/internal/position_builder.rb on lines 110..115

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 30.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                def build_from_trade(trade)
                  Position.new do |p|
                    initialize_trading_information_from_trade(p, trade)
                    initialize_price_and_time(p, trade['price'].to_f, Time.parse(trade['openTime']), nil)
                    p.closing_policy = ClosingPolicy.create_from_trade(trade)
            Severity: Minor
            Found in src/jiji/model/trading/internal/position_builder.rb and 1 other location - About 20 mins to fix
            src/jiji/model/trading/internal/position_builder.rb on lines 52..56

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 27.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                def build_from_trade_opend_of_order_result(trade)
                  Position.new do |p|
                    initialize_trading_information_from_trade_opend_of_order_result(p, trade)
                    initialize_price_and_time(p, trade['price'].to_f, Time.parse(trade['time']), nil)
                    p.closing_policy = ClosingPolicy.create_from_trade(trade)
            Severity: Minor
            Found in src/jiji/model/trading/internal/position_builder.rb and 1 other location - About 20 mins to fix
            src/jiji/model/trading/internal/position_builder.rb on lines 44..48

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 27.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Line is too long. [93/80]
            Open

                    initialize_price_and_time(p, trade['price'].to_f, Time.parse(trade['openTime']), nil)

            Line is too long. [81/80]
            Open

                    initialize_trading_information_from_trade_opend_of_order_result(p, trade)

            Line is too long. [88/80]
            Open

                def initialize_trading_information_from_trade_opend_of_order_result(position, trade)

            Line is too long. [89/80]
            Open

                    initialize_price_and_time(p, trade['price'].to_f, Time.parse(trade['time']), nil)

            There are no issues that match your filters.

            Category
            Status