question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fetchTrades does not handle since parameter

See original GitHub issue
  • OS: win10
  • Programming Language version: nodeJS, latest
  • CCXT version: 1.18.685
  • Exchange: kraken
  • Method: fetchTrades

If I supply a since microtimestamp of 2018-01-01 and limit of 1,to get only 1 trade, I get the latest value as follows and not 2018 one. When I use a browser to try the kraken API, it works ok (https://api.kraken.com/0/public/Trades?pair=xbtusd&since=0)

{
  "since": 1560415023540,
  "value": [
    [
      {
        "info": [
          "229.89000",
          "1.03544657",
          1560415023.5403,
          "b",
          "l",
          ""
        ],
        "timestamp": 1560415023540,
        "datetime": "2019-06-13T08:37:03.540Z",
        "symbol": "ETH/EUR",
        "type": "limit",
        "side": "buy",
        "price": 229.89,
        "amount": 1.03544657,
        "cost": 238.0388119773
      }
    ]
  ]
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kyjakcommented, Jun 13, 2019

If I supply a since microtimestamp of 2018-01-01 and limit of 1,to get only 1 trade, I get the latest value as follows and not 2018 one.

Kraken does not support date-based pagination, and the since should contain a trade id, not a timestamp. This is how Kraken API works, not an issue in CCXT.

https://www.kraken.com/en-us/features/api#get-recent-trades

In order to pass that parameter to the exchange with overrided params: https://github.com/ccxt/ccxt/wiki/Manual#overriding-unified-api-params

So the correct usage is:

'use strict';
const ccxt = require ('ccxt')
const exchange = new ccxt.kraken ({
   'enableRateLimit': true, // required by the Manual https://github.com/ccxt/ccxt/wiki/Manual#rate-limit
})
;(async () => {
    const symbol = 'ETH/EUR'
    const since = 1560430233878703138 // ←--------------------- this goes here ↓
    const trades = await exchange.fetchTrades (symbol, undefined, undefined, { since })
}) ()

However, it won’t help you get the trades history since year 2018, because that entire endpoint is specialized for recent trades, so it will allow queries within a very limited range of since ids, and which id corresponds to which date – you don’t know. Most exchanges will limit historical data and it’s documented in the Manual.

Let us know if that does not answer the question.

not entirely true, the response of that endpoint is structured as “{“error”:[],“result”:{“XETHZEUR”:[[“20.00000”,“4.50000000”,1438945790.9098,“b”,“l”,”“],[“20.00000”,“0.48000000”,1438945791.2365,“b”,“l”,”“],[“20.00000”,“3.37215150”,1438945954.1212,“s”,“l”,”"], where there is no tradaId as you say. This is the public endpoint, not private. When you try this in the browser, with since = 0, it goes well beyond year 2018. Will try to use your approach and reply.

0reactions
kroitorcommented, Jun 13, 2019

@kyjak

node examples/js/cli kraken fetchTrades ETH/EUR undefined undefined '{"since":0}' --verbose

Starts like this:

Screen Shot 2019-06-13 at 18 06 13

Then outputs lots of verbose data…

Then it gets to the actual fetchTrades call:

Screen Shot 2019-06-13 at 18 06 46

And in the end it outputs the set of trades in a table, which looks like so:

Screen Shot 2019-06-13 at 18 08 31

If you look at the last trade – you’ll see that it has an id, that’s the last trade id, reported by Kraken.

Screen Shot 2019-06-13 at 18 06 54

Here’s the id:

                    |       | 1439314147187 | 2015-08-11T17:29:07.187Z | ETH/EUR |  limit |  buy |    0.79 |      155.9148 |    123.17269200000001 |
                    |       | 1439314148147 | 2015-08-11T17:29:08.147Z | ETH/EUR |  limit |  buy |    0.79 |  798.62480473 |        630.9135957367 |
                    |       | 1439314606890 | 2015-08-11T17:36:46.890Z | ETH/EUR |  limit | sell |     0.8 |         68.65 |     54.92000000000001 |
                    |       | 1439314732350 | 2015-08-11T17:38:52.350Z | ETH/EUR |  limit | sell |   0.789 |         83.85 |              66.15765 |
                    |       | 1439314732700 | 2015-08-11T17:38:52.700Z | ETH/EUR |  limit | sell |   0.789 |   84.23584283 |        66.46207999287 |
                    |       | 1439314860839 | 2015-08-11T17:41:00.839Z | ETH/EUR |  limit | sell |    0.78 |       0.00077 |             0.0006006 |
                    |       | 1439314860848 | 2015-08-11T17:41:00.848Z | ETH/EUR |  limit | sell |    0.78 |   14.33305128 |    11.179779998399999 |
                    |       | 1439314860875 | 2015-08-11T17:41:00.875Z | ETH/EUR |  limit | sell |    0.78 |    0.00021794 |          0.0001699932 |
                    |       | 1439314892486 | 2015-08-11T17:41:32.486Z | ETH/EUR |  limit | sell |    0.78 |   56.19273078 |         43.8303300084 |
                    |       | 1439315085629 | 2015-08-11T17:44:45.629Z | ETH/EUR |  limit |  buy | 0.81973 |            10 |                8.1973 |
                    |       | 1439315345816 | 2015-08-11T17:49:05.816Z | ETH/EUR |  limit | sell |    0.75 |        33.565 |              25.17375 |
1439315345846191902 |       | 1439315345846 | 2015-08-11T17:49:05.846Z | ETH/EUR |  limit | sell | 0.73684 |      21.93726 |         16.1642506584 |
↑ here it is, and only the last trade in the result set has it

You can use cli to check your results.

In code that would look like so:

'use strict';
const ccxt = require ('ccxt')
const exchange = new ccxt.kraken ({
   'enableRateLimit': true, // required by the Manual https://github.com/ccxt/ccxt/wiki/Manual#rate-limit
})
;(async () => {
    const symbol = 'ETH/EUR'
    const since = 0 // ←----------------------------------------- this goes here ↓
    const trades = await exchange.fetchTrades (symbol, undefined, undefined, { since })
    const numTrades = trades.length
    if (trades.length > 0) {
        const lastId = trades[trades.length - 1]['id']
        console.log ('Last trade id for iteration purposes: ' + lastId)
    }
}) ()
Read more comments on GitHub >

github_iconTop Results From Across the Web

Exchanges — ccxt 2.4.71 documentation
Some exchanges require this parameter for trading, but most of them don't. uid : A unique id of your account. This can be...
Read more >
CCXT for WX.Network - Waves.Exchange
Fetch exchange transactions for the account by trading pair. Parameters and output are the same as the fetchTrades. For now, you can only...
Read more >
How to Easily Fetch Binance Historical Trades Using Python
In low liquidity pairs, this parameter can be changed because there is no guarantee that a trade occurred in the first minute of...
Read more >
Change Log – Binance API Documentation - GitHub Pages
{ "code": -1106, "msg": "Parameter X was sent when not required." } New behavior: If the combinations of optional parameters to the endpoint...
Read more >
Overview — ccxt 1.13.142 文档
id name ver doc countries _1broker 1Broker 2 API US _1btcxe 1BTCXE * API Panama acx ACX 2 API Australia
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found