简体   繁体   English

如何在 php 中正确获取所有 coinbase pro 交易

[英]How to fetch all the coinbase pro transactions correctly in php

I have a question of coinbase pro,我有一个关于coinbase pro的问题,

How can I get all the orders/transactions from coinbase pro using php without any limit, or with any limit parameter.如何在没有任何限制或任何限制参数的情况下使用 php 从 coinbase pro 获取所有订单/交易。

I am using the following library to fetch all the coinbase pro orders, but it only gives me 100 orders from the below method.我正在使用以下库来获取所有 coinbase pro 订单,但它只给了我来自以下方法的 100 个订单。

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

This question was answered here:https://github.com/ccxt/ccxt/issues/6105#issuecomment-552405563这个问题在这里得到了回答: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";

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM