Skip to content

Commit

Permalink
Add necessary changes before start cross_3t
Browse files Browse the repository at this point in the history
  • Loading branch information
kleninmaxim committed Apr 28, 2022
1 parent 5460efe commit 6501610
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 150 deletions.
110 changes: 61 additions & 49 deletions config/aeron_config.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

// Конфиг, который должен получать от конфигуратора
const CONFIG = [
'exchange' => 'kuna',
'exchanges' => ['kuna', 'huobi'],
'exchange' => 'ftx',
'exchanges' => ['ftx'],
'min_profit' => [
'BTC' => 0,
'ETH' => 0,
'USDT' => 0
],
'min_deal_amounts' => [
'BTC' => 0.001,
'ETH' => 0.01,
'USDT' => 20
'BTC' => 0,
'ETH' => 0,
'USDT' => 0
],
'rates' => [
'BTC' => 46139,
'ETH' => 3471,
'BTC' => 39000,
'ETH' => 2900,
'USDT' => 1
],
'max_deal_amounts' => [
Expand All @@ -26,22 +26,22 @@
],
'markets' => [
[
'exchange_symbol' => 'ETH-BTC',
'exchange_symbol' => 'ETH/BTC',
'common_symbol' => 'ETH/BTC',
'price_increment' => 0.000001,
'amount_increment' => 0.0000001,
'price_increment' => 0.0000025,
'amount_increment' => 0.001,
'limits' => [
'amount' => [
'min' => 0.0005,
'max' => 5000.0,
'min' => 0.001,
'max' => null,
],
'price' => [
'min' => 1.0E-8,
'max' => 10.0,
'min' => null,
'max' => null,
],
'cost' => [
'min' => 0.0002,
'max' => 100.0,
'min' => null,
'max' => null,
]
],
'assets' => [
Expand All @@ -50,22 +50,22 @@
]
],
[
'exchange_symbol' => 'BTC-USDT',
'exchange_symbol' => 'BTC/USDT',
'common_symbol' => 'BTC/USDT',
'price_increment' => 0.1,
'amount_increment' => 0.00000001,
'price_increment' => 1,
'amount_increment' => 0.0001,
'limits' => [
'amount' => [
'min' => 2.0E-5,
'max' => 1000.0,
'min' => 0.0001,
'max' => null,
],
'price' => [
'min' => 0.01,
'max' => 150000.0,
'min' => null,
'max' => null,
],
'cost' => [
'min' => 1.0,
'max' => 500000.0,
'min' => null,
'max' => null,
],
],
'assets' => [
Expand All @@ -74,22 +74,22 @@
]
],
[
'exchange_symbol' => 'ETH-USDT',
'exchange_symbol' => 'ETH/USDT',
'common_symbol' => 'ETH/USDT',
'price_increment' => 0.01,
'amount_increment' => 0.0000001,
'price_increment' => 0.1,
'amount_increment' => 0.001,
'limits' => [
'amount' => [
'min' => 0.0005,
'max' => 5000.0,
'min' => 0.001,
'max' => null,
],
'price' => [
'min' => 0.01,
'max' => 100000.0,
'min' => null,
'max' => null,
],
'cost' => [
'min' => 1.0,
'max' => 500000.0
'min' => null,
'max' => null
],
],
'assets' => [
Expand All @@ -100,15 +100,39 @@
],
'routes' => [
[
['source_asset' => 'USDT', 'common_symbol' => 'BTC/USDT', 'operation' => 'buy'],
['source_asset' => 'BTC', 'common_symbol' => 'ETH/BTC', 'operation' => 'buy'],
['source_asset' => 'ETH', 'common_symbol' => 'ETH/USDT', 'operation' => 'sell'],
],
[
['source_asset' => 'BTC', 'common_symbol' => 'BTC/USDT', 'operation' => 'sell'],
['source_asset' => 'USDT', 'common_symbol' => 'ETH/USDT', 'operation' => 'buy'],
['source_asset' => 'ETH', 'common_symbol' => 'ETH/BTC', 'operation' => 'sell'],
],
[
['source_asset' => 'ETH', 'common_symbol' => 'ETH/BTC', 'operation' => 'sell'],
['source_asset' => 'BTC', 'common_symbol' => 'BTC/USDT', 'operation' => 'sell'],
['source_asset' => 'USDT', 'common_symbol' => 'ETH/USDT', 'operation' => 'buy'],
],
[
['source_asset' => 'BTC', 'common_symbol' => 'ETH/BTC', 'operation' => 'buy'],
['source_asset' => 'ETH', 'common_symbol' => 'ETH/USDT', 'operation' => 'sell'],
['source_asset' => 'USDT', 'common_symbol' => 'BTC/USDT', 'operation' => 'buy'],
],
[
['source_asset' => 'ETH', 'common_symbol' => 'ETH/USDT', 'operation' => 'sell'],
['source_asset' => 'USDT', 'common_symbol' => 'BTC/USDT', 'operation' => 'buy'],
['source_asset' => 'BTC', 'common_symbol' => 'ETH/BTC', 'operation' => 'buy'],
],
[
['source_asset' => 'USDT', 'common_symbol' => 'ETH/USDT', 'operation' => 'buy'],
['source_asset' => 'ETH', 'common_symbol' => 'ETH/BTC', 'operation' => 'sell'],
['source_asset' => 'BTC', 'common_symbol' => 'BTC/USDT', 'operation' => 'sell'],
],
],
'max_depth' => 10,
'fees' => [
'kuna' => 0.1,
'huobi' => 0.1
'ftx' => 0.1
],
];

Expand All @@ -124,22 +148,10 @@
// Instance
const INSTANCE = '1';

// publisher, который подключается к subscriber в агенте, для посылания команды на получения конфига
const AGENT_PUBLISHER = [
'channel' => 'aeron:ipc',
'stream_id' => 1001
];

// subscriber, который подключается к publisher в агенте, для принятия конфига
const AGENT_SUBSCRIBERS_BALANCES = [
'channel' => 'aeron:ipc',
'stream_id' => 1001
];

// publisher, который подключается к subscriber в гейте, для посылания команд
const GATE_PUBLISHER = [
'channel' => 'aeron:ipc',
'stream_id' => 1001
'stream_id' => 1005
];

// subscriber, который подключается к publisher в гейте, для принятия данных
Expand Down
30 changes: 0 additions & 30 deletions kernel/cross_3t.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,11 @@
// нужен publisher, отправлять команды по aeron в гейт
$publisher = new AeronPublisher(GATE_PUBLISHER['channel'], GATE_PUBLISHER['stream_id']);

// получить конфиг из memcached. Пока не получит конфиг, алгоритм выполняться не будет
while (!isset($config)) {

sleep(1);

// берет конфиг из memcached
$memcached_data = $memcached->get('config');

// если нашел запись в memcached
if ($memcached_data) {

// присвоить конфиг
$config = $memcached_data;

// удалить из memcached
$memcached->delete('config');

echo '[Ok] Config is set' . PHP_EOL;

} else
echo '[WARNING] Config is not set' . PHP_EOL;

}

// создаем класс cross 3t
$cross_3t = new Cross3T($config);

while (true) {

sleep(1);

// берем все данные из memcached
$all_keys = $cross_3t->getAllMemcachedKeys();

Expand All @@ -58,10 +32,6 @@

print_r($all_keys);

// проверяем конфиг на обновление, если появился новый конфиг, обновить его, удалить данные конфига из memcached
if ($cross_3t->proofConfigOnUpdate($config, $memcached_data))
$memcached->delete('config');

// отформировать и отделить все данные, полученные из memcached
$all_data = $cross_3t->reformatAndSeparateData($memcached_data);

Expand Down
71 changes: 0 additions & 71 deletions kernel/receive_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,77 +9,6 @@
$memcached = new Memcached();
$memcached->addServer('localhost', 11211);

// публишер для агента, чтобы получить конфиг
$publisher = new AeronPublisher(AGENT_PUBLISHER['channel'], AGENT_PUBLISHER['stream_id']);

function handler_get_config(string $message): void
{

global $memcached, $core_config;

if ($data = Aeron::messageDecode($message)) {

if ($data['event'] == 'config' && $data['node'] == 'configurator') {

$core_config = $data['data']['core_config'];

$memcached->set(
'config',
$data['data']
);

} else {

echo '[ERROR] data broken. Node: ' . ($data['node'] ?? 'null') . PHP_EOL;

}

}

}

$subscriber = new AeronSubscriber('handler_get_config', AGENT_SUBSCRIBERS_BALANCES['channel'], AGENT_SUBSCRIBERS_BALANCES['stream_id']);

while (true) {

usleep(100000);

$subscriber->poll();

if (!isset($core_config)) {

do {

usleep(1000000);

$code = $publisher->offer(
Aeron::messageEncode([
'event' => 'config',
'exchange' => EXCHANGE,
'instance' => NODE,
'action' => 'get_full_config',
'algo' => ALGORITHM,
'data' => [],
'timestamp' => intval(microtime(true) * 1000000)
])
);

echo 'Try to send command get_full_config to Agent. Code: ' . $code . PHP_EOL;

} while($code > 0);

} else {

echo '[OK] Can config get' . PHP_EOL;

unset($subscriber);

break;

}

}

function handler_orderbooks(string $message): void
{

Expand Down

0 comments on commit 6501610

Please sign in to comment.