Conditions | 9 |
Paths | 358 |
Total Lines | 98 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
51 | protected function execute(InputInterface $input, OutputInterface $output) |
||
52 | { |
||
53 | //get config first |
||
54 | try { |
||
55 | $config = (new Configurator(__DIR__.'/../../config/'.$input->getOption('config').'.yml'))->make(); |
||
56 | |||
57 | //check if Exchange Market provider is available |
||
58 | $marketConfig = $config->get('markets.'.$input->getOption('market')); |
||
59 | $market = (new ExchangeFactory($input->getOption('market')))->make([$marketConfig]); |
||
60 | |||
61 | //set logs (txt db) |
||
62 | $logFileType = |
||
63 | $config->get('mokka.default_log_type') == 'date' |
||
64 | ? (new \DateTime())->format('Y-m-d') |
||
65 | : $input->getOption('symbol'); |
||
66 | |||
67 | $logger = new Logger(__DIR__.'/../../logs/', $logFileType); |
||
68 | |||
69 | //check the first row in logs |
||
70 | $this->createActionFile($logger, $input, $output); |
||
71 | |||
72 | //get indicator |
||
73 | $indicatorConfig = $config->get('indicators.'.$input->getOption('indicator')); |
||
74 | $indicator = (new IndicatorFactory($input->getOption('indicator'))) |
||
75 | ->make([$market, $logger, $indicatorConfig]); |
||
76 | |||
77 | |||
78 | //run strategy calculator |
||
79 | $strategy = new StrategyCalculator($market, $indicator); |
||
80 | |||
81 | $strategy->setInterval($input->getOption('interval')); |
||
82 | $strategy->setSymbol($input->getOption('symbol')); |
||
83 | $strategy->setMarket($input->getOption('market')); |
||
84 | |||
85 | $output->writeln('<info>Mokka Started!</info>'); |
||
86 | $table = new Table($output); |
||
87 | $table->setHeaders(array('Action', 'Previous Price', 'Action Price', 'Symbol', 'Amount', 'Trigger', 'Change', 'Date')); |
||
88 | |||
89 | while (1) { |
||
90 | $quantity = new Quantity(); |
||
91 | $action = $strategy->run($logger); |
||
92 | |||
93 | if ($input->getOption('test') === false) { |
||
94 | if ($action->getType() == ActionInterface::TYPE_BUY) { |
||
95 | //calculate quantity |
||
96 | $maxFund = $config->get('markets.'.$input->getOption('market').'.max_fund'); |
||
97 | |||
98 | /** @var BuyAction $action */ |
||
99 | $action->setQuantity( |
||
100 | $quantity->buyQuantityCalculator($maxFund, $action->getActionPrice(), $market->getBalance()) |
||
101 | ); |
||
102 | |||
103 | $market->buyOrder($action); |
||
104 | } |
||
105 | |||
106 | |||
107 | if ($action->getType() == ActionInterface::TYPE_SELL) { |
||
108 | //get quantity to sell |
||
109 | $maxSell = $config->get('markets.'.$input->getOption('market').'.max_sell'); |
||
110 | |||
111 | $action->setQuantity( |
||
112 | $quantity->sellQuantityCalculator($maxSell, $action->getQuantity()) |
||
113 | ); |
||
114 | |||
115 | /** @var SellAction $action */ |
||
116 | $market->sellOrder($action); |
||
117 | } |
||
118 | } |
||
119 | |||
120 | //log the action |
||
121 | if ($action->getType() != ActionInterface::TYPE_IDLE) { |
||
122 | $logger->insert()->set($action->toArray())->execute(); |
||
123 | } |
||
124 | |||
125 | $table->setRows(array( |
||
126 | array( |
||
127 | $action->getType(), |
||
128 | $action->getPreviousPrice(), |
||
129 | $action->getActionPrice(), |
||
130 | $action->getSymbol(), |
||
131 | $action->getQuantity(), |
||
132 | $config->get('indicators.percent.default_percent'), |
||
133 | round($action->getActionPrice() / $action->getPreviousPrice(), 5), |
||
134 | date('Y-m-d H:i:s') |
||
135 | ), |
||
136 | )); |
||
137 | |||
138 | $table->render(); |
||
139 | |||
140 | sleep($input->getOption('interval')); |
||
141 | } |
||
142 | |||
143 | $output->writeln('<question>Mokka stopped!</question>'); |
||
144 | |||
145 | } catch (InvalidConfigurationException $exception) { |
||
146 | $output->writeln("<error>Invalid Configuration</error>"); |
||
147 | } catch (\Exception $exception) { |
||
148 | $output->writeln("<error>{$exception->getMessage()}</error>"); |
||
149 | } |
||
209 | } |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.