Skip to content

Commit

Permalink
Merge branch '2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
kleninmaxim committed Jun 2, 2022
2 parents e864e59 + 316d828 commit b3d8495
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 38 deletions.
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"require": {
"ext-pdo": "*",
"ext-memcached": "*"
},

"require": {
"ext-pdo": "*",
"ext-memcached": "*",
"ext-curl": "*"
},
"autoload": {
"psr-4": {
"Src\\" : "src/",
"robotrade\\" : "libs/PHP-API"
"Src\\": "src/",
"robotrade\\": "libs/PHP-API"
}
}
}
6 changes: 6 additions & 0 deletions kernel/balancer_by_market_order.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@

$config = (SOURCE == 'file') ? $common_config['config'] : Configurator::getConfig($common_config['exchange'], $common_config['instance']);

$config_api = Configurator::getConfig($common_config['exchange'], $common_config['instance']);

$config['assets_labels'] = $config_api['assets_labels'];

$config['markets'] = $config_api['markets'];

// API для формирования сообщения для отправки по aeron
$robotrade_api = new Api($common_config['exchange'], $common_config['algorithm'], $common_config['node'], $common_config['instance']);

Expand Down
23 changes: 14 additions & 9 deletions kernel/cross_3t.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,21 @@

if ($best_result[$step]['exchange'] == $common_config['exchange']) {

$gate_publisher->offer(
$robotrade_api->createOrder(
$best_result[$step]['amountAsset'] . '/' . $best_result[$step]['priceAsset'],
'market',
$best_result[$step]['orderType'],
$best_result[$step]['amount'],
$best_result[$step]['price'],
'Create order ' . $step
)
$message = $robotrade_api->createOrder(
$best_result[$step]['amountAsset'] . '/' . $best_result[$step]['priceAsset'],
'market',
$best_result[$step]['orderType'],
$best_result[$step]['amount'],
$best_result[$step]['price'],
'Create order ' . $step
);

// отправить гейту на постановку ордера
$gate_publisher->offer($message);

// отправить в лог сервер, что ордер постановился
$log_publisher->offer($message);

echo '[' . date('Y-m-d H:i:s') . '] Send to gate create order. Pair: ' . $best_result[$step]['amountAsset'] . '/' . $best_result[$step]['priceAsset'] . ' Type: ' . $best_result[$step]['orderType'] . ' Amount: ' . $best_result[$step]['amount'] . ' Price: ' . $best_result[$step]['price'] . PHP_EOL;

}
Expand All @@ -98,6 +102,7 @@

}

// отправить на лог сервер теоретические расчеты
$log_publisher->offer($log->sendExpectedTriangle($best_result));

// Запрос на получение баланса
Expand Down
24 changes: 14 additions & 10 deletions kernel/multi_3t.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,21 @@
// для каждого шага, если результат выпал на текущую биржу, отправить сообщение на создание ордера
foreach (['step_one', 'step_two', 'step_three'] as $step) {

// отправить гейту на постановку ордера
$gate_publishers[$best_result[$step]['exchange']]->offer(
$robotrade_apis[$best_result[$step]['exchange']]->createOrder(
$best_result[$step]['amountAsset'] . '/' . $best_result[$step]['priceAsset'],
'market',
$best_result[$step]['orderType'],
$best_result[$step]['amount'],
$best_result[$step]['price'],
'Create order ' . $step
)
$message = $robotrade_apis[$best_result[$step]['exchange']]->createOrder(
$best_result[$step]['amountAsset'] . '/' . $best_result[$step]['priceAsset'],
'market',
$best_result[$step]['orderType'],
$best_result[$step]['amount'],
$best_result[$step]['price'],
'Create order ' . $step
);

// отправить гейту на постановку ордера
$gate_publishers[$best_result[$step]['exchange']]->offer($message);

// отправить в лог сервер, что ордер постановился
$log_publisher->offer($message);

echo '[' . date('Y-m-d H:i:s') . '] Send to gate create order. Pair: ' .
$best_result[$step]['amountAsset'] . '/' . $best_result[$step]['priceAsset'] .
' Type: ' . $best_result[$step]['orderType'] .
Expand All @@ -75,6 +78,7 @@

}

// отправить на лог сервер теоретические расчеты
$log_publisher->offer($log->sendExpectedTriangle($best_result));

}
Expand Down
28 changes: 18 additions & 10 deletions src/Cross3T.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,31 @@ public function run(array $balances, array $orderbooks, bool $multi = false): ar

}

$best_result = $this->getBestResult($results, $this->config['min_profit']);
if ($results) {

if (isset($this->common_config['debug']) && $this->common_config['debug']) {
$best_result = $this->getBestResult($results, $this->config['min_profit']);

$var = str_split(time());
if (isset($this->common_config['debug']) && $this->common_config['debug']) {

$var = end($var);
$var = str_split(time());

if (!isset($this->previous) || (in_array($var, [1, 3, 5, 7, 9]) && $this->previous != $var) || $best_result) {
$var = end($var);

$this->madeHtmlVision($results, $best_result, $orderbooks, $balances, $this->common_config['made_html_vision_file']);
if (!isset($this->previous) || (in_array($var, [1, 3, 5, 7, 9]) && $this->previous != $var) || $best_result) {

$this->previous = $var;
$this->madeHtmlVision($results, $best_result, $orderbooks, $balances, $this->common_config['made_html_vision_file']);

$this->previous = $var;

}

}

return $best_result;

}

return $best_result;
return [];

}

Expand Down Expand Up @@ -119,6 +125,8 @@ public function getBestResult(array $results, array $min_profit): array
public function findBestOrderbooks(array $route, array $balances, array $orderbooks): array
{

$best_orderbooks = [];

foreach ($route as $source) {

$deal_amount_potential = $this->config['max_deal_amounts'][$source['source_asset']];
Expand Down Expand Up @@ -202,7 +210,7 @@ public function findBestOrderbooks(array $route, array $balances, array $orderbo

}

return $best_orderbooks ?? [];
return (count($best_orderbooks) == 3) ? $best_orderbooks : [];

}

Expand Down Expand Up @@ -326,7 +334,7 @@ public function getOrderbook(array $combinations, array $best_orderbooks, bool $
'amountAsset' => $market_config['base_asset'] ?? '',
'priceAsset' => $market_config['quote_asset'] ?? '',
'exchange' => $best_orderbooks[$combinations[$step_symbol]]['exchange'] ?? '',
'fee' => $config['fees'][$best_orderbooks[$combinations[$step_symbol]]['exchange']] ?? 0,
'fee' => $this->config['fees'][$best_orderbooks[$combinations[$step_symbol]]['exchange']],
];

}
Expand Down
28 changes: 27 additions & 1 deletion src/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,33 @@ public function madeHtmlVision(array $results, array $best_result, array $orderb

$html .= '</table>';

$html .= '<br /><br /> Balances: <pre>' . json_encode($balances, JSON_PRETTY_PRINT) . '</pre> <br /><br /> Orderbooks: <pre>' . json_encode($orderbooks, JSON_PRETTY_PRINT) . '</pre> <br /><br /> Best results: <pre>' . json_encode($best_result, JSON_PRETTY_PRINT) . '</pre> <br /><br /> Results: <pre>' . json_encode($results, JSON_PRETTY_PRINT) . '</pre>';
$sum_balances = [];

foreach ($balances as $balance) {

foreach ($balance as $asset => $b) {

$sum_balances[$asset]['free'] = 0;
$sum_balances[$asset]['used'] = 0;
$sum_balances[$asset]['total'] = 0;

}

}

foreach ($balances as $balance) {

foreach ($balance as $asset => $b) {

$sum_balances[$asset]['free'] += $b['free'];
$sum_balances[$asset]['used'] += $b['used'];
$sum_balances[$asset]['total'] += $b['total'];

}

}

$html .= '<br /><br /> All Balances: <pre>' . json_encode($sum_balances, JSON_PRETTY_PRINT) . '</pre> <br /><br /> Balances: <pre>' . json_encode($balances, JSON_PRETTY_PRINT) . '</pre> <br /><br /> Orderbooks: <pre>' . json_encode($orderbooks, JSON_PRETTY_PRINT) . '</pre> <br /><br /> Best results: <pre>' . json_encode($best_result, JSON_PRETTY_PRINT) . '</pre> <br /><br /> Results: <pre>' . json_encode($results, JSON_PRETTY_PRINT) . '</pre>';

$index = fopen($file_path, 'w');

Expand Down
36 changes: 35 additions & 1 deletion src/Multi/MultiConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function getConfig(string $multi_config_path): array
foreach ($config['exchanges'] as $exchange) {

$config_from_configurator = json_decode(
file_get_contents('https://configurator.robotrade.io/' . $exchange . '/' . $config['instances'][$exchange] . '?only_new=false'),
self::file_get_contents_ssl('https://configurator.robotrade.io/' . $exchange . '/' . $config['instances'][$exchange] . '?only_new=false'),
true
)['data'];

Expand Down Expand Up @@ -53,4 +53,38 @@ public static function getConfig(string $multi_config_path): array

}

/**
* Делает curl запрос
* @param string $url Url адрес
* @return bool|string возвращает контент
*/
private static function file_get_contents_ssl(string $url): bool|string
{

$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt($ch, CURLOPT_HEADER, false);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_REFERER, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3000); // 3 sec.

curl_setopt($ch, CURLOPT_TIMEOUT, 10000); // 10 sec.

$result = curl_exec($ch);

curl_close($ch);

return $result;

}

}

0 comments on commit b3d8495

Please sign in to comment.