<commit_before><?php

date_default_timezone_set ('UTC');

include 'ccxt.php';
include 'Console/Table.php';

date_default_timezone_set ('UTC');

function style ($s, $style) { return $style . $s . "\033[0m"; }
function green     ($s) { return style ($s, "\033[92m"); }
function blue      ($s) { return style ($s, "\033[94m"); }
function yellow    ($s) { return style ($s, "\033[93m"); }
function red       ($s) { return style ($s, "\033[91m"); }
function pink      ($s) { return style ($s, "\033[95m"); }
function bold      ($s) { return style ($s, "\033[1m"); }
function underline ($s) { return style ($s, "\033[4m"); }
function dump ($s) { echo implode (' ', func_get_args ()) . "\n"; }

$markets = null;

if (file_exists ('config.php'))
    include 'config.php';
else
    $markets = array ();

//-----------------------------------------------------------------------------

foreach (\ccxt\Market::$markets as $id) {
    $market = '\\ccxt\\' . $id;
    $markets[$id] = new $market (array (
        'verbose' => false,
        // 'proxy' => 'https://crossorigin.me/',
        // 'proxy' => 'https://cors-anywhere.herokuapp.com/',
        // 'proxy' => 'http://cors-proxy.htmldriven.com/?url=',
    ));
}

$config = {
    '_1broker':    { 'apiKey': '<KEY>' },
    '_1btcxe':     { 'apiKey': '<KEY>', 'secret': '<KEY>' },
    'bit2c':       { 'apiKey': '5296814c-b1dc-4201-a62a-9b2364e890da', 'secret': '<KEY>' },
    'bitbay':      { 'apiKey': '3faec3e5458d24809a68fbaf0e97245b', 'secret': '2ffb20992e10dd54fd4fd4133cc09b00' },
    'bitcoincoid': { 'apiKey': '<KEY>', 'secret': '<KEY>' },
    'bitfinex':    { 'apiKey': '<KEY>', 'secret': '<KEY>' },
    'bitlish':     { 'apiKey': '<KEY>', 'login': '<EMAIL>', 'password': '<PASSWORD>!' },
    'bitmarket':   { 'apiKey': '<KEY>', 'secret': '892b34c7d8e6669550aa9d12aed0ad34' },
    'bitmex':      { 'apiKey': '<KEY>', 'secret': '<KEY>' },
    'bitso':       { 'apiKey': '<KEY>', 'secret': '<KEY>' },
    'bittrex':     { 'apiKey': '<KEY>', 'secret': '9d294ddb5b944403b58e5298653720c1' },
    'btcx':        { 'apiKey': '<KEY>', 'secret': '<KEY>' },
    'bxinth':      { 'apiKey': '<KEY>', 'secret': '03031e588e69' },
    # 'ccex':        { 'apiKey': '301D5954466D87CEAA9BA713A7951F5A', 'secret': '<KEY>' },
    'cex':         { 'apiKey': '<KEY>', 'secret': '<KEY>', 'uid': 'up105393824' },
    'coincheck':   { 'apiKey': '1YBiSTpyEIkchWdE', 'secret': '<KEY>' },
    'coinsecure':  { 'apiKey': '<KEY>' },
    'coinspot':    { 'apiKey': '36b5803f892fe97ccd0b22da79ce6b21', 'secret': '<KEY>', },
    'fybse':       { 'apiKey': '<KEY>', 'secret': '<KEY>' },
    'fybsg':       { 'apiKey': '', 'secret': '' },
    'gdax':        { 'apiKey': '<KEY>', 'secret': '<KEY>', 'password': '<PASSWORD>', },
    'hitbtc':      { 'apiKey': '<KEY>', 'secret': '8340a60fb4e9fc73a169c26c7a7926f5' },
    'huobi':       { 'apiKey': '09bdde40-cc179779-1941272a-433a7', 'secret': 'ce6487f4-f078c39f-018ea6ce-01922' },
    'jubi':        { 'apiKey': '<KEY>', 'secret': '<KEY>' },
    'livecoin':    { 'apiKey': '<KEY>', 'secret': '<KEY>', },
    'luno':        { 'apiKey': '<KEY>', 'secret': '<KEY>' },
    'okcoinusd':   { 'apiKey': '<KEY>', 'secret': '614D2E6D3428C2C5E54C81139A500BE0' },
    'okcoincny':   { 'apiKey': '', 'secret' : '' },
    'poloniex':    { 'apiKey': '<KEY>', 'secret': '70cc628f95e4e536bd2de702c058ff482fff52f176ac884d6aa605040c29e31caca93430755d1c56a09d0c6a9fe90077754da54b194523f21591e63015bf81fd' },
    'quadrigacx':  { 'apiKey': '<KEY>', 'secret': '<KEY>', 'uid': '395037' },
    'quoine':      { 'apiKey': '80953', 'secret': '<KEY> },
    'therock':     { 'apiKey': '2b2a54cc6258b2a971318000d60e6b61ba4af05e', 'secret': 'b424a76088bda492852dbd5cadbb60ebcf144427' },
    'vaultoro':    { 'apiKey': '<KEY>', 'secret': '<KEY> },
    'virwox':      { 'apiKey': '<KEY>', 'login': 'IgorKroitor', 'password': '<PASSWORD>' },
    'xbtce':       { 'apiKey': '<KEY>', 'secret': '<KEY>', 'uid': '68ef0552-3c37-4896-ba56-76173d9cd573', },
    'yobit':       { 'apiKey': '5DB6C7C6034E667D77F85B245772A7FD', 'secret': '<KEY>' },
    'zaif':        { 'apiKey': '<KEY>', 'secret': '<KEY>' },
}

$markets['_1broker']->apiKey = '<KEY>';

$markets['xbtce']->uid    = '68ef0552-3c37-4896-ba56-76173d9cd573';
$markets['xbtce']->apiKey = '<KEY>';
$markets['xbtce']->secret = '<KEY>';

$markets['coinspot']->apiKey = '36b5803f892fe97ccd0b22da79ce6b21';
$markets['coinspot']->secret = '<KEY>';

function test_market_symbol_ticker ($market, $symbol) { 
    $ticker = $market->fetch_ticker ($symbol);
    echo implode (' ', array ($market->id, $symbol, 'ticker',
        $ticker['datetime'],
        'high: '    . $ticker['high'],
        'low: '     . $ticker['low'],
        'bid: '     . $ticker['bid'],
        'ask: '     . $ticker['ask'],
        'volume: '  . $ticker['quoteVolume'])) . "\n";
}

function test_market_symbol_orderbook ($market, $symbol) {
    $orderbook = $market->fetch_order_book ($symbol);
    echo implode (' ', array ($market->id, $symbol, 'order book',
        $orderbook['datetime'],
        'bid: '       . @$orderbook['bids'][0][0],
        'bidVolume: ' . @$orderbook['bids'][0][1],
        'ask: '       . @$orderbook['asks'][0][0],
        'askVolume: ' . @$orderbook['asks'][0][1])) . "\n";
}

function test_market_symbol ($market, $symbol) {
    $delay = $market->rateLimit * 1000;
    usleep ($delay);
    test_market_symbol_ticker ($market, $symbol);
    usleep ($delay);
    if ($market->id == 'coinmarketcap')
        dump (var_export ($market->fetchGlobal ()));
    else
        test_market_symbol_orderbook ($market, $symbol);
}

function load_market ($market) {

    $products = $market->load_products ();
    $symbols = array_keys ($products);    
    echo $market->id . ' ' . count ($symbols) . " symbols: " . implode (", ", $symbols) . "\n";
}

function test_market ($market) {

    $keys = array_keys ($market->products);
    $delay = $market->rateLimit * 1000;

    $symbol = $keys[0];
    $symbols = array (
        'BTC/USD',
        'BTC/CNY',
        'BTC/ETH',
        'ETH/BTC',
        'BTC/JPY',
        'LTC/BTC',
    );

    foreach ($symbols as $s) {
        if (in_array ($s, $keys))
            $symbol = $s;
    }
<commit_msg>fixes #34 gdax private api<commit_after><?php

date_default_timezone_set ('UTC');

include 'ccxt.php';
include 'Console/Table.php';

date_default_timezone_set ('UTC');

function style ($s, $style) { return $style . $s . "\033[0m"; }
function green     ($s) { return style ($s, "\033[92m"); }
function blue      ($s) { return style ($s, "\033[94m"); }
function yellow    ($s) { return style ($s, "\033[93m"); }
function red       ($s) { return style ($s, "\033[91m"); }
function pink      ($s) { return style ($s, "\033[95m"); }
function bold      ($s) { return style ($s, "\033[1m"); }
function underline ($s) { return style ($s, "\033[4m"); }
function dump ($s) { echo implode (' ', func_get_args ()) . "\n"; }

$markets = null;

if (file_exists ('config.php'))
    include 'config.php';
else
    $markets = array ();

//-----------------------------------------------------------------------------

foreach (\ccxt\Market::$markets as $id) {
    $market = '\\ccxt\\' . $id;
    $markets[$id] = new $market (array (
        'verbose' => true,
        // 'proxy' => 'https://crossorigin.me/',
        // 'proxy' => 'https://cors-anywhere.herokuapp.com/',
        // 'proxy' => 'http://cors-proxy.htmldriven.com/?url=',
    ));
}

$config = array (
    '_1broker'    => array ('apiKey' => '<KEY>'),
    '_1btcxe'     => array ('apiKey' => '<KEY>', 'secret' => '<KEY>'),
    'bit2c'       => array ('apiKey' => '5296814c-b1dc-4201-a62a-9b2364e890da', 'secret' => '<KEY>'),
    'bitbay'      => array ('apiKey' => '3faec3e5458d24809a68fbaf0e97245b', 'secret' => '2ffb20992e10dd54fd4fd4133cc09b00'),
    'bitcoincoid' => array ('apiKey' => '<KEY>', 'secret' => '<KEY>'),
    'bitfinex'    => array ('apiKey' => '<KEY>', 'secret' => '<KEY>'),
    'bitlish'     => array ('apiKey' => '<KEY>', 'login' => '<EMAIL>', 'password' => '<PASSWORD>!'),
    'bitmarket'   => array ('apiKey' => '<KEY>', 'secret' => '892b34c7d8e6669550aa9d12aed0ad34'),
    'bitmex'      => array ('apiKey' => '<KEY>', 'secret' => '<KEY>'),
    'bitso'       => array ('apiKey' => '<KEY>', 'secret' => '<KEY>'),
    'bittrex'     => array ('apiKey' => '<KEY>', 'secret' => '9d294ddb5b944403b58e5298653720c1'),
    'btcx'        => array ('apiKey' => '<KEY>', 'secret' => '<KEY>'),
    'bxinth'      => array ('apiKey' => '<KEY>', 'secret' => '03031e588e69'),
    # 'ccex'       => array ('apiKey' => '301D5954466D87CEAA9BA713A7951F5A', 'secret' => '<KEY>'),
    'cex'         => array ('apiKey' => '<KEY>', 'secret' => '<KEY>', 'uid' => 'up105393824'),
    'coincheck'   => array ('apiKey' => '1YBiSTpyEIkchWdE', 'secret' => '<KEY>'),
    'coinsecure'  => array ('apiKey' => '<KEY>'),
    'coinspot'    => array ('apiKey' => '36b5803f892fe97ccd0b22da79ce6b21', 'secret' => '<KEY>'),
    'fybse'       => array ('apiKey' => '<KEY>', 'secret' => '<KEY>'),
    'fybsg'       => array ('apiKey' => '', 'secret' => ''),
    'gdax'        => array ('apiKey' => '<KEY>', 'secret' => '<KEY>', 'password' => '<PASSWORD>'),
    'hitbtc'      => array ('apiKey' => '<KEY>', 'secret' => '8340a60fb4e9fc73a169c26c7a7926f5'),
    'huobi'       => array ('apiKey' => '09bdde40-cc179779-1941272a-433a7', 'secret' => 'ce6487f4-f078c39f-018ea6ce-01922'),
    'jubi'        => array ('apiKey' => '<KEY>', 'secret' => '<KEY>'),
    'livecoin'    => array ('apiKey' => '<KEY>', 'secret' => '<KEY>'),
    'luno'        => array ('apiKey' => '<KEY>', 'secret' => '<KEY>'),
    'okcoinusd'   => array ('apiKey' => '<KEY>', 'secret' => '614D2E6D3428C2C5E54C81139A500BE0'),
    'okcoincny'   => array ('apiKey' => '', 'secret' => ''),
    'poloniex'    => array ('apiKey' => '<KEY>', 'secret' => '70cc628f95e4e536bd2de702c058ff482fff52f176ac884d6aa605040c29e31caca93430755d1c56a09d0c6a9fe90077754da54b194523f21591e63015bf81fd'),
    'quadrigacx'  => array ('apiKey' => '<KEY>', 'secret' => '<KEY>', 'uid' => '395037'),
    'quoine'      => array ('apiKey' => '80953', 'secret' => '<KEY>'),
    'therock'     => array ('apiKey' => '2b2a54cc6258b2a971318000d60e6b61ba4af05e', 'secret' => 'b424a76088bda492852dbd5cadbb60ebcf144427'),
    'vaultoro'    => array ('apiKey' => '<KEY>', 'secret' => '<KEY>),
    'virwox'      => array ('apiKey' => '<KEY>', 'login' => 'IgorKroitor', 'password' => '<PASSWORD>'),
    'xbtce'       => array ('apiKey' => '<KEY>', 'secret' => '<KEY>', 'uid' => '68ef0552-3c37-4896-ba56-76173d9cd573'),
    'yobit'       => array ('apiKey' => '5DB6C7C6034E667D77F85B245772A7FD', 'secret' => '<KEY>'),
    'zaif'        => array ('apiKey' => '<KEY>', 'secret' => '4c529fd6-fb28-4879-b20d-2a8f02c5db47'),
);

foreach ($config as $id => $params)
    foreach ($params as $key => $value)
        $markets[$id]->$key = $value;

$markets['gdax']->urls['api'] = 'https://api-public.sandbox.gdax.com';
$markets['anxpro']->proxy = 'https://crossorigin.me/';

function test_market_symbol_ticker ($market, $symbol) { 
    $ticker = $market->fetch_ticker ($symbol);
    echo implode (' ', array ($market->id, $symbol, 'ticker',
        $ticker['datetime'],
        'high: '    . $ticker['high'],
        'low: '     . $ticker['low'],
        'bid: '     . $ticker['bid'],
        'ask: '     . $ticker['ask'],
        'volume: '  . $ticker['quoteVolume'])) . "\n";
}

function test_market_symbol_orderbook ($market, $symbol) {
    $orderbook = $market->fetch_order_book ($symbol);
    echo implode (' ', array ($market->id, $symbol, 'order book',
        $orderbook['datetime'],
        'bid: '       . @$orderbook['bids'][0][0],
        'bidVolume: ' . @$orderbook['bids'][0][1],
        'ask: '       . @$orderbook['asks'][0][0],
        'askVolume: ' . @$orderbook['asks'][0][1])) . "\n";
}

function test_market_symbol ($market, $symbol) {
    $delay = $market->rateLimit * 1000;
    usleep ($delay);
    test_market_symbol_ticker ($market, $symbol);
    usleep ($delay);
    if ($market->id == 'coinmarketcap')
        dump (var_export ($market->fetchGlobal ()));
    else
        test_market_symbol_orderbook ($market, $symbol);
}

function load_market ($market) {

    $products = $market->load_products ();
    $symbols = array_keys ($products);    
    echo $market->id . ' ' . count ($symbols) . " symbols: " . implode (", ", $symbols) . "\n";
}

function test_market ($market) {

    $keys = array_keys ($market->products);
    $delay = $market->rateLimit * 1000;

    $symbol = $keys[0];
    $symbols = array (
        'BTC/USD',
        'BTC/CNY',
        'BTC/ETH',
        'ETH/BTC',
        'BTC/JPY',
        'LTC/BTC',
    );

    foreach ($symbols as $s) {
        if (in_array ($s, $keys)) {
            $symbol = $s;
            break;
        }
    }

{'fraction_non_alphanumeric': 0.25085669781931463, 'fraction_numerical': 0.08193146417445483, 'mean_word_length': 3.1012456084318107, 'pattern_counts': {'":': 0, '<': 112, '<?xml version=': 0, '>': 266, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2688193', 'n_tokens_mistral': 5453, 'n_tokens_neox': 4960, 'n_words': 891}