0

I have a question of coinbase pro,

How can I get all the orders/transactions from coinbase pro using php without any limit , or with any limit parameter.

I am using the following library to fetch all the coinbase pro orders , but it only gives me 100 orders from the below method.

fetch_orders

Here is the method,

$CoinbaseProtrans = $CoinbasePro->fetch_orders('ETH/USD',"",150,array('limit'=>100,'after'=>1));
echo "<pre>";print_r($CoinbaseProtrans);echo "</pre>";

Here is the error I am getting,

Fatal error: Uncaught ccxt\ExchangeError: coinbasepro after cursor value is not valid in coinbasepro.php:813 

Here is the link of the library:

https://github.com/ccxt/ccxt/blob/master/php/coinbasepro.php
gosuto
  • 5,422
  • 6
  • 36
  • 57
Kappa
  • 1,015
  • 1
  • 16
  • 31

1 Answers1

3

This question was answered here: https://github.com/ccxt/ccxt/issues/6105#issuecomment-552405563

<?php

include_once ('ccxt.php');

date_default_timezone_set ('UTC');

$exchange = new \ccxt\coinbasepro(array(
    'apiKey' => 'YOUR_API_KEY',
    'secret' => 'YOUR_SECRET',
    // 'verbose' => true, // uncomment for debugging
    // https://github.com/ccxt/ccxt/wiki/Manual#rate-limit
    'enableRateLimit' => true, // rate-limiting is required by the Manual
));

$exchange->load_markets ();

// $exchange->verbose = true; // uncomment for debugging

$all_results = array();

$symbol = 'ETH/USD';
$since = null;
$limit = 100;
$params = array();

do {
    // any of the following methods should work:
    // $results = $exchange->fetch_orders($symbol, $since, $limit, $params);
    // $results = $exchange->fetch_my_trades($symbol, $since, $limit, $params);
    $results = $exchange->fetch_trades($symbol, $since, $limit, $params);
    echo $exchange->iso8601($exchange->milliseconds());
    echo ' fetched ' . count($results) . " results\n";
    $all_results = array_merge ($all_results, $results);
    if (count($results) > 0) {
        $last = count($results) - 1;
        echo '     last result ' . $results[$last]['id'] . ' ' . $results[$last]['datetime'] . "\n";
        echo '    first result ' . $results[0]['id'] . ' ' . $results[0]['datetime'] . "\n";
    } else {
        break;
    }
    @$params['after'] = $exchange->last_response_headers['cb-after'][0];

// uncomment one of the following:
// } while (true); // fetch all results forever
} while (count($all_results) < 1000); // fetch up to 1000 results

echo "fetched " . count($all_results) . " results in total\n";

?>
Igor Kroitor
  • 1,548
  • 13
  • 16
  • Hello kroitor, Thank you for the detailed program. It worked for me to fetch the orders with pagination option :). Thank you so much. I would like to know how can we get the exact transaction as per cointracker if you know? For the 'ETH/USD' symbol , I am getting total 110 transactions from ccxt library , but when I fetch the 'ETH' transactions from cointracker , it gives total 355 transactions. so just confused about that one if you can help me on that. Again thank you for the help :) – Kappa Nov 12 '19 at 07:20