This commit is contained in:
discountry
2025-10-03 15:28:16 +08:00
parent d5c4b04746
commit fcb83bd16b
925 changed files with 165721 additions and 4 deletions
@@ -0,0 +1,76 @@
<?php
error_reporting(E_ALL);
date_default_timezone_set('UTC');
$root = dirname(dirname(dirname(dirname(__FILE__))));
include $root . '/ccxt.php';
function create_exchange($exchange_id, $config) {
$keys = array(
'ids',
'markets',
'markets_by_id',
'currencies',
'currencies_by_id',
'base_currencies',
'quote_currencies',
'symbols',
);
$exchange_class = '\\ccxt\\pro\\' . $exchange_id;
$exchange = new $exchange_class($config);
$markets_on_disk = "./{$exchange_id}.markets.json";
$exchange->verbose = true; // this is a debug output to demonstrate which networking calls are being issued
if (file_exists($markets_on_disk)) {
$cache = json_decode(file_get_contents($markets_on_disk), true);
foreach ($keys as $key) {
$exchange->{$key} = $cache[$key];
}
} else {
$markets = yield $exchange->load_markets();
$cache = array();
foreach ($keys as $key) {
$cache[$key] = $exchange->{$key};
}
file_put_contents($markets_on_disk, json_encode($cache));
}
return $exchange;
}
$exchanges = array(
array('binance', array(
'id' => 'binance1',
'apiKey' => 'YOUR_API_KEY_HERE',
'secret' => 'YOUR_SECRET_HERE',
)),
array('binance', array(
'id' => 'binance2',
'apiKey' => 'YOUR_API_KEY_HERE',
'secret' => 'YOUR_SECRET_HERE',
)),
);
$loop = function($exchange_id, $config) {
$exchange = yield create_exchange($exchange_id, $config);
$exchange->verbose = true;
while (true) {
$response = yield $exchange->watch_balance();
print('--------------------------------------------------------------');
print($exchange->id);
print($response);
}
};
foreach ($exchanges as $exchange) {
\React\Async\coroutine($loop, $exchange[0], $exchange[1]);
}
@@ -0,0 +1,27 @@
<?php
$root = dirname(dirname(dirname(dirname(__FILE__))));
include $root . '/ccxt.php';
$config = array('enableRateLimit' => true);
$binance = new \ccxt\pro\binance($config);
$bittrex = new \ccxt\pro\bittrex($config);
$symbol = "BTC/USDT";
$loop = function($exchange, $symbol) {
echo 'got inside' . PHP_EOL;
for ($i = 0; $i < 5; $i++) {
$ticker = yield $exchange->watch_ticker($symbol);
print_ticker($ticker, $exchange->id, $symbol);
}
};
function print_ticker($ticker, $exchange_name, $symbol) {
$bid = $ticker['bid'];
$ask = $ticker['ask'];
echo "$exchange_name $symbol - bid: $bid <> ask: $ask" . PHP_EOL;
}
\React\Async\coroutine($loop, $bittrex, $symbol);
\React\Async\coroutine($loop, $binance, $symbol);
@@ -0,0 +1,30 @@
<?php
$root = dirname(dirname(dirname(dirname(__FILE__))));
include $root . '/ccxt.php';
$id = 'aax';
$exchange_class = '\\ccxt\\pro\\' . $id;
$exchange = new $exchange_class(array(
'enableRateLimit' => true,
));
$symbols = array('BTC/USDT', 'ETH/USDT', 'ETH/BTC');
function print_orderbook($orderbook, $symbol) {
$id = isset($orderbook['nonce']) ? $orderbook['nonce'] : $orderbook['datetime'];
echo $id, ' ', $symbol, ' ',
count($orderbook['asks']), ' asks ', json_encode($orderbook['asks'][0]), ' ',
count($orderbook['bids']), ' bids ', json_encode($orderbook['bids'][0]), "\n";
}
$loop = function($exchange, $symbol) {
while (true) {
$orderbook = yield $exchange->watch_order_book($symbol);
print_orderbook($orderbook, $symbol);
}
};
foreach ($symbols as $symbol) {
\React\Async\coroutine($loop, $exchange, $symbol);
}
@@ -0,0 +1,41 @@
<?php
error_reporting(E_ALL);
date_default_timezone_set('UTC');
include dirname(dirname(dirname(dirname(__FILE__)))). '/ccxt.php';
$binance_id = '\\ccxt\\pro\\binance';
$binance_exchange = new $binance_id( /*[ 'apiKey' => _YOUR_APIKEY_HERE_, 'secret' => _YOUR_SECRET_HERE_ ]*/ );
$ftx_id = '\\ccxt\\pro\\ftx';
$ftx_exchange = new $ftx_id( /*['apiKey' => _YOUR_APIKEY_HERE_, 'secret' => _YOUR_SECRET_HERE_]*/ );
$wrapper_func = function($exchange, $symbol, $method_name) {
if ($exchange->has[$method_name]) {
print ("Starting $method_name for $exchange->id -> $symbol\n");
while (true) {
try {
$orderbook = yield $exchange->$method_name($symbol);
print("$exchange->id -> $method_name -> $symbol : " . substr(json_encode($orderbook), 0 , 70) . "...\n");
} catch (\Exception $ex) {
print($ex->getMessage());
sleep(5);
}
}
} else {
print ($exchange->id . " API yet doesnt support $method_name");
}
};
function runAsync (...$args) {
\React\Async\coroutine(...$args);
}
// *** uncomment whichever methods you want to test ***
// runAsync($wrapper_func, ...[$exchange, 'ETH/USDT', 'watchOrderBook']);
// runAsync($wrapper_func, ...[$exchange, 'ETH/USDT', 'watchTicker']);
// runAsync($wrapper_func, ...[$exchange, 'ETH/USDT', 'watchOrders']);
// runAsync($wrapper_func, ...[$exchange, 'ETH/USDT', 'watchMyTrades']);
runAsync($wrapper_func, ...[$binance_exchange, 'SOL/USDT', 'watchTrades']);
runAsync($wrapper_func, ...[$ftx_exchange, 'ETH/USDT', 'watchTrades']);