@@ -33,7 +33,7 @@ |
||
33 | 33 | */ |
34 | 34 | public function make(array $args) |
35 | 35 | { |
36 | - if( class_exists($this->class)) { |
|
36 | + if (class_exists($this->class)) { |
|
37 | 37 | $instance = new $this->class(...$args); |
38 | 38 | |
39 | 39 | return $instance; |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | |
19 | 19 | public function __construct($config) |
20 | 20 | { |
21 | - self::$apiService = new BinanceApiService($config['api_key'],$config['api_secret']); |
|
21 | + self::$apiService = new BinanceApiService($config['api_key'], $config['api_secret']); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $params = [ |
62 | 62 | 'symbol' => $action->getSymbol(), |
63 | 63 | 'price' => $action->getActionPrice(), |
64 | - 'quantity' => round($action->getQuantity(),2), |
|
64 | + 'quantity' => round($action->getQuantity(), 2), |
|
65 | 65 | 'side' => 'BUY', |
66 | 66 | 'type' => 'LIMIT', |
67 | 67 | 'timeInForce' => 'GTC', |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $balance = null; |
124 | 124 | //catch BTC balance |
125 | 125 | foreach ($account['balances'] as $item) { |
126 | - if ($item['asset'] == 'BTC'){ |
|
126 | + if ($item['asset'] == 'BTC') { |
|
127 | 127 | $balance = $item['free']; |
128 | 128 | break; |
129 | 129 | } |
@@ -8,8 +8,12 @@ |
||
8 | 8 | public function buyQuantityCalculator($maxFund, $price, $balance) |
9 | 9 | { |
10 | 10 | //calculate max fund based balance |
11 | - if ($maxFund > 100) throw new \InvalidArgumentException('max_fund value can not be more than 100'); |
|
12 | - if ($maxFund < 1) throw new \InvalidArgumentException('max_fund value can not be less than 1'); |
|
11 | + if ($maxFund > 100) { |
|
12 | + throw new \InvalidArgumentException('max_fund value can not be more than 100'); |
|
13 | + } |
|
14 | + if ($maxFund < 1) { |
|
15 | + throw new \InvalidArgumentException('max_fund value can not be less than 1'); |
|
16 | + } |
|
13 | 17 | |
14 | 18 | $buyFund = ($balance * $maxFund) / 100; |
15 | 19 | return round($buyFund / $price, 8); |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | $lastAction = $logger |
61 | 61 | ->read() |
62 | 62 | ->where('market', '=', $this->getMarket()) |
63 | - ->where('symbol','=',$this->getSymbol()) |
|
63 | + ->where('symbol', '=', $this->getSymbol()) |
|
64 | 64 | ->sortDesc('lastUpdate') |
65 | 65 | ->limit(1) |
66 | 66 | ->first(); |
@@ -69,13 +69,13 @@ discard block |
||
69 | 69 | |
70 | 70 | //calculate in loop by interval |
71 | 71 | /** @var ActionInterface $actionType */ |
72 | - $actionType = self::$indicator->calculate($this->getSymbol(),$lastAction); |
|
72 | + $actionType = self::$indicator->calculate($this->getSymbol(), $lastAction); |
|
73 | 73 | |
74 | 74 | if ($actionType->getType() == ActionInterface::TYPE_BUY) { |
75 | 75 | $action = new BuyAction(); |
76 | - }elseif ( $actionType->getType() == ActionInterface::TYPE_SELL) { |
|
76 | + }elseif ($actionType->getType() == ActionInterface::TYPE_SELL) { |
|
77 | 77 | $action = new SellAction(); |
78 | - }elseif ( $actionType->getType() == ActionInterface::TYPE_IDLE) { |
|
78 | + }elseif ($actionType->getType() == ActionInterface::TYPE_IDLE) { |
|
79 | 79 | $action = new IdleAction(); |
80 | 80 | } |
81 | 81 |
@@ -73,9 +73,9 @@ |
||
73 | 73 | |
74 | 74 | if ($actionType->getType() == ActionInterface::TYPE_BUY) { |
75 | 75 | $action = new BuyAction(); |
76 | - }elseif ( $actionType->getType() == ActionInterface::TYPE_SELL) { |
|
76 | + } elseif ( $actionType->getType() == ActionInterface::TYPE_SELL) { |
|
77 | 77 | $action = new SellAction(); |
78 | - }elseif ( $actionType->getType() == ActionInterface::TYPE_IDLE) { |
|
78 | + } elseif ( $actionType->getType() == ActionInterface::TYPE_IDLE) { |
|
79 | 79 | $action = new IdleAction(); |
80 | 80 | } |
81 | 81 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @param $lastAction Action last trade action |
20 | 20 | * @return ActionInterface |
21 | 21 | */ |
22 | - public function calculate($symbol,Action $lastAction) : ActionInterface |
|
22 | + public function calculate($symbol, Action $lastAction) : ActionInterface |
|
23 | 23 | { |
24 | 24 | //current price of symbol |
25 | 25 | $currentPrice = $this->exchange->getPrice($symbol) * self::FIXER; |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | $lastActionPrice = $lastAction->getActionPrice() * self::FIXER; |
28 | 28 | |
29 | 29 | //logic is here |
30 | - $calculatedPercentOfPrice = ( $lastActionPrice * $this->options['default_percent']) / 100; |
|
30 | + $calculatedPercentOfPrice = ($lastActionPrice * $this->options['default_percent']) / 100; |
|
31 | 31 | |
32 | 32 | |
33 | 33 | //buy signal |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | $action->setType(ActionInterface::TYPE_IDLE); |
53 | 53 | } |
54 | 54 | |
55 | - $lastActionPrice = number_format($lastActionPrice / self::FIXER,8,'.',''); |
|
56 | - $currentPrice = number_format($currentPrice / self::FIXER,8,'.',''); |
|
55 | + $lastActionPrice = number_format($lastActionPrice / self::FIXER, 8, '.', ''); |
|
56 | + $currentPrice = number_format($currentPrice / self::FIXER, 8, '.', ''); |
|
57 | 57 | |
58 | 58 | $action->setPreviousPrice($lastActionPrice); |
59 | 59 | $action->setActionPrice($currentPrice); |
@@ -20,7 +20,7 @@ |
||
20 | 20 | |
21 | 21 | public function make($args) |
22 | 22 | { |
23 | - if( class_exists($this->class)) { |
|
23 | + if (class_exists($this->class)) { |
|
24 | 24 | $instance = new $this->class(...$args); |
25 | 25 | |
26 | 26 | return $instance; |
@@ -48,7 +48,7 @@ |
||
48 | 48 | */ |
49 | 49 | public function update() |
50 | 50 | { |
51 | - return $this->logger->update()->in($this->dbName); |
|
51 | + return $this->logger->update()->in($this->dbName); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -19,10 +19,10 @@ discard block |
||
19 | 19 | $this |
20 | 20 | ->setName('report') |
21 | 21 | ->setDescription('Generate mokka reports') |
22 | - ->addOption('market','m',InputOption::VALUE_OPTIONAL,'Choose market to run') |
|
23 | - ->addOption('symbol','s',InputOption::VALUE_OPTIONAL,'Specific symbol for the report') |
|
24 | - ->addOption('date','d',InputOption::VALUE_OPTIONAL,'Choose the date of repor. Format: YYYY-MM-DD') |
|
25 | - ->addOption('format','f',InputOption::VALUE_OPTIONAL,'File format for the reports. Default is console output. Available formats; CSV, XML, JSON',"console") |
|
22 | + ->addOption('market', 'm', InputOption::VALUE_OPTIONAL, 'Choose market to run') |
|
23 | + ->addOption('symbol', 's', InputOption::VALUE_OPTIONAL, 'Specific symbol for the report') |
|
24 | + ->addOption('date', 'd', InputOption::VALUE_OPTIONAL, 'Choose the date of repor. Format: YYYY-MM-DD') |
|
25 | + ->addOption('format', 'f', InputOption::VALUE_OPTIONAL, 'File format for the reports. Default is console output. Available formats; CSV, XML, JSON', "console") |
|
26 | 26 | ; |
27 | 27 | } |
28 | 28 | |
@@ -35,20 +35,20 @@ discard block |
||
35 | 35 | { |
36 | 36 | try { |
37 | 37 | $fs = new Filesystem(); |
38 | - if(!is_dir(__DIR__ . '/../../reports')) $fs->mkdir(__DIR__ . '/../../reports'); |
|
38 | + if (!is_dir(__DIR__.'/../../reports')) $fs->mkdir(__DIR__.'/../../reports'); |
|
39 | 39 | |
40 | 40 | $reportDate = $input->getOption("date") ? $input->getOption("date") : (new \DateTime())->format('Y-m-d'); |
41 | 41 | |
42 | 42 | //set logs (txt db) |
43 | - $logger = new Logger(__DIR__ . '/../../logs/', $reportDate); |
|
43 | + $logger = new Logger(__DIR__.'/../../logs/', $reportDate); |
|
44 | 44 | |
45 | 45 | $report = $logger->read(); |
46 | 46 | |
47 | - if($input->getOption("symbol")){ |
|
47 | + if ($input->getOption("symbol")) { |
|
48 | 48 | $report->where("symbol", "=", $input->getOption("symbol")); |
49 | 49 | } |
50 | 50 | |
51 | - if($input->getOption("market")){ |
|
51 | + if ($input->getOption("market")) { |
|
52 | 52 | $report->where("market", "=", $input->getOption("market")); |
53 | 53 | } |
54 | 54 | |
@@ -57,18 +57,18 @@ discard block |
||
57 | 57 | $formatData = []; |
58 | 58 | |
59 | 59 | array_map(function($row) use (&$formatData){ |
60 | - $row['lastUpdate'] = date('Y-m-d H:i:s',$row['lastUpdate']); |
|
60 | + $row['lastUpdate'] = date('Y-m-d H:i:s', $row['lastUpdate']); |
|
61 | 61 | $formatData[] = $row; |
62 | 62 | }, (array) $reportData->getIterator()); |
63 | 63 | |
64 | 64 | $format = $input->getOption("format"); |
65 | 65 | $method = "output".ucfirst($format); |
66 | 66 | |
67 | - if(method_exists($this,$method)){ |
|
68 | - $this->$method($input,$output,$formatData); |
|
67 | + if (method_exists($this, $method)) { |
|
68 | + $this->$method($input, $output, $formatData); |
|
69 | 69 | } |
70 | 70 | |
71 | - } catch (\Exception $exception){ |
|
71 | + } catch (\Exception $exception) { |
|
72 | 72 | $output->writeln("<error>{$exception->getMessage()}</error>"); |
73 | 73 | } |
74 | 74 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | protected function outputConsole(InputInterface $input, OutputInterface $output, $reportData) |
83 | 83 | { |
84 | 84 | $table = new Table($output); |
85 | - $table->setHeaders(array('Action Price', 'Previous Price', 'Action', 'Symbol','Market','Update Date')); |
|
85 | + $table->setHeaders(array('Action Price', 'Previous Price', 'Action', 'Symbol', 'Market', 'Update Date')); |
|
86 | 86 | |
87 | 87 | $table->setRows($reportData); |
88 | 88 | |
@@ -94,15 +94,15 @@ discard block |
||
94 | 94 | * @param OutputInterface $output |
95 | 95 | * @param $reportData |
96 | 96 | */ |
97 | - protected function outputJson(InputInterface $input, OutputInterface $output, $reportData){ |
|
97 | + protected function outputJson(InputInterface $input, OutputInterface $output, $reportData) { |
|
98 | 98 | $fs = new Filesystem(); |
99 | 99 | |
100 | 100 | $fileName = "report_".time().".json"; |
101 | - $filePath = __DIR__ ."/../../reports/" . $fileName; |
|
101 | + $filePath = __DIR__."/../../reports/".$fileName; |
|
102 | 102 | |
103 | - $fs->dumpFile($filePath,json_encode($reportData)); |
|
103 | + $fs->dumpFile($filePath, json_encode($reportData)); |
|
104 | 104 | |
105 | - $realPath = realpath(dirname($filePath)) . "/" . $fileName; |
|
105 | + $realPath = realpath(dirname($filePath))."/".$fileName; |
|
106 | 106 | $output->writeln("<question>Report Generated!</question>"); |
107 | 107 | $output->writeln("<question>{$realPath}</question>"); |
108 | 108 |
@@ -35,7 +35,9 @@ |
||
35 | 35 | { |
36 | 36 | try { |
37 | 37 | $fs = new Filesystem(); |
38 | - if(!is_dir(__DIR__ . '/../../reports')) $fs->mkdir(__DIR__ . '/../../reports'); |
|
38 | + if(!is_dir(__DIR__ . '/../../reports')) { |
|
39 | + $fs->mkdir(__DIR__ . '/../../reports'); |
|
40 | + } |
|
39 | 41 | |
40 | 42 | $reportDate = $input->getOption("date") ? $input->getOption("date") : (new \DateTime())->format('Y-m-d'); |
41 | 43 |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | // the name of the command (the part after "bin/console") |
33 | 33 | ->setName('run') |
34 | 34 | ->setDescription('Run Mokka! Run!') |
35 | - ->addOption('market','m',InputOption::VALUE_OPTIONAL,'Choose market to run','binance') |
|
36 | - ->addOption('interval','i',InputOption::VALUE_OPTIONAL,'Seconds for each requests. Default: 60',60) |
|
37 | - ->addOption('symbol','s',InputOption::VALUE_OPTIONAL,'Symbol for the bot to run','BTCUSDT') |
|
38 | - ->addOption('indicator','it',InputOption::VALUE_OPTIONAL,'Which indicator will be applied? (for future development)','percent') |
|
39 | - ->addOption('config','c',InputOption::VALUE_OPTIONAL,'default config file. you can use custom config for each command','default') |
|
40 | - ->addOption('test','t',InputOption::VALUE_OPTIONAL,'Test mode for botta. If set TRUE botta will not buy and sell any crypto currency',false) |
|
35 | + ->addOption('market', 'm', InputOption::VALUE_OPTIONAL, 'Choose market to run', 'binance') |
|
36 | + ->addOption('interval', 'i', InputOption::VALUE_OPTIONAL, 'Seconds for each requests. Default: 60', 60) |
|
37 | + ->addOption('symbol', 's', InputOption::VALUE_OPTIONAL, 'Symbol for the bot to run', 'BTCUSDT') |
|
38 | + ->addOption('indicator', 'it', InputOption::VALUE_OPTIONAL, 'Which indicator will be applied? (for future development)', 'percent') |
|
39 | + ->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'default config file. you can use custom config for each command', 'default') |
|
40 | + ->addOption('test', 't', InputOption::VALUE_OPTIONAL, 'Test mode for botta. If set TRUE botta will not buy and sell any crypto currency', false) |
|
41 | 41 | |
42 | 42 | ; |
43 | 43 | } |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | { |
53 | 53 | //get config first |
54 | 54 | try { |
55 | - $config = (new Configurator(__DIR__ . '/../../config/'.$input->getOption('config').'.yml'))->make(); |
|
55 | + $config = (new Configurator(__DIR__.'/../../config/'.$input->getOption('config').'.yml'))->make(); |
|
56 | 56 | |
57 | 57 | //check if Exchange Market provider is available |
58 | - $marketConfig = $config->get('markets.'. $input->getOption('market')); |
|
58 | + $marketConfig = $config->get('markets.'.$input->getOption('market')); |
|
59 | 59 | $market = (new ExchangeFactory($input->getOption('market')))->make([$marketConfig]); |
60 | 60 | |
61 | 61 | //set logs (txt db) |
@@ -64,15 +64,15 @@ discard block |
||
64 | 64 | ? (new \DateTime())->format('Y-m-d') |
65 | 65 | : $input->getOption('symbol'); |
66 | 66 | |
67 | - $logger = new Logger(__DIR__ . '/../../logs/', $logFileType); |
|
67 | + $logger = new Logger(__DIR__.'/../../logs/', $logFileType); |
|
68 | 68 | |
69 | 69 | //check the first row in logs |
70 | - $this->createActionFile($logger,$input,$output); |
|
70 | + $this->createActionFile($logger, $input, $output); |
|
71 | 71 | |
72 | 72 | //get indicator |
73 | - $indicatorConfig = $config->get('indicators.'. $input->getOption('indicator')); |
|
73 | + $indicatorConfig = $config->get('indicators.'.$input->getOption('indicator')); |
|
74 | 74 | $indicator = (new IndicatorFactory($input->getOption('indicator'))) |
75 | - ->make([$market,$logger,$indicatorConfig]); |
|
75 | + ->make([$market, $logger, $indicatorConfig]); |
|
76 | 76 | |
77 | 77 | |
78 | 78 | //run strategy calculator |
@@ -86,18 +86,18 @@ discard block |
||
86 | 86 | $table = new Table($output); |
87 | 87 | $table->setHeaders(array('Action', 'Previous Price', 'Action Price', 'Symbol', 'Amount', 'Trigger', 'Change', 'Date')); |
88 | 88 | |
89 | - while(1){ |
|
89 | + while (1) { |
|
90 | 90 | $quantity = new Quantity(); |
91 | 91 | $action = $strategy->run($logger); |
92 | 92 | |
93 | 93 | if ($input->getOption('test') === false) { |
94 | - if( $action->getType() == ActionInterface::TYPE_BUY) { |
|
94 | + if ($action->getType() == ActionInterface::TYPE_BUY) { |
|
95 | 95 | //calculate quantity |
96 | - $maxFund = $config->get('markets.'. $input->getOption('market') .'.max_fund'); |
|
96 | + $maxFund = $config->get('markets.'.$input->getOption('market').'.max_fund'); |
|
97 | 97 | |
98 | 98 | /** @var BuyAction $action */ |
99 | 99 | $action->setQuantity( |
100 | - $quantity->buyQuantityCalculator($maxFund,$action->getActionPrice(),$market->getBalance()) |
|
100 | + $quantity->buyQuantityCalculator($maxFund, $action->getActionPrice(), $market->getBalance()) |
|
101 | 101 | ); |
102 | 102 | |
103 | 103 | $market->buyOrder($action); |
@@ -106,10 +106,10 @@ discard block |
||
106 | 106 | |
107 | 107 | if ($action->getType() == ActionInterface::TYPE_SELL) { |
108 | 108 | //get quantity to sell |
109 | - $maxSell = $config->get('markets.'. $input->getOption('market') .'.max_sell'); |
|
109 | + $maxSell = $config->get('markets.'.$input->getOption('market').'.max_sell'); |
|
110 | 110 | |
111 | 111 | $action->setQuantity( |
112 | - $quantity->sellQuantityCalculator($maxSell,$action->getQuantity()) |
|
112 | + $quantity->sellQuantityCalculator($maxSell, $action->getQuantity()) |
|
113 | 113 | ); |
114 | 114 | |
115 | 115 | /** @var SellAction $action */ |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | |
143 | 143 | $output->writeln('<question>Mokka stopped!</question>'); |
144 | 144 | |
145 | - } catch (InvalidConfigurationException $exception){ |
|
145 | + } catch (InvalidConfigurationException $exception) { |
|
146 | 146 | $output->writeln("<error>Invalid Configuration</error>"); |
147 | - } catch (\Exception $exception){ |
|
147 | + } catch (\Exception $exception) { |
|
148 | 148 | $output->writeln("<error>{$exception->getMessage()}</error>"); |
149 | 149 | } |
150 | 150 | } |
@@ -162,12 +162,12 @@ discard block |
||
162 | 162 | $lastAction = $logger |
163 | 163 | ->read() |
164 | 164 | ->where('market', '=', $input->getOption('market')) |
165 | - ->where('symbol','=',$input->getOption('symbol')) |
|
165 | + ->where('symbol', '=', $input->getOption('symbol')) |
|
166 | 166 | ->sortDesc('lastUpdate') |
167 | 167 | ->limit(1) |
168 | 168 | ->first(); |
169 | 169 | |
170 | - if($lastAction){ |
|
170 | + if ($lastAction) { |
|
171 | 171 | return; |
172 | 172 | } |
173 | 173 | |
@@ -186,14 +186,14 @@ discard block |
||
186 | 186 | $question2 = new Question("What was the last price for {$input->getOption('symbol')}?"); |
187 | 187 | $price = $helper->ask($input, $output, $question2); |
188 | 188 | |
189 | - if (!$price){ |
|
189 | + if (!$price) { |
|
190 | 190 | $output->writeln("<comment>You need to tell me the last action price. Otherwise I can not move on.</comment>"); |
191 | 191 | die(); |
192 | 192 | } |
193 | 193 | |
194 | 194 | $actionContent = new Action(); |
195 | 195 | $actionContent->setType($chosenActionType); |
196 | - $actionContent->setSymbol( $input->getOption('symbol')); |
|
196 | + $actionContent->setSymbol($input->getOption('symbol')); |
|
197 | 197 | $actionContent->setLastUpdate(time()); |
198 | 198 | $actionContent->setMarket($input->getOption('market')); |
199 | 199 | $actionContent->setPreviousPrice($price); |