ccxt / ccxt

A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading API with support for more than 100 bitcoin/altcoin exchanges
https://docs.ccxt.com
MIT License
32.32k stars 7.45k forks source link

[bitstamp] spot trade price is undefined #11116

Open npomfret opened 2 years ago

npomfret commented 2 years ago
{
    id: '68086689',
    info: {
      fee: '0.25000',
      order_id: 1660243896,
      datetime: '2018-06-10 18:59:51.000000',
      usd: 0,
      btc: 0,
      eth: '0.21208000',
      eth_eur: 453.05, <-- this?
      type: '2',
      id: 68086689,
      eur: '-96.08'
    },
    timestamp: 1528657191000,
    datetime: '2018-06-10T18:59:51.000Z',
    symbol: 'ETH/EUR',
    order: '1660243896',
    type: undefined,
    side: 'buy',
    takerOrMaker: undefined,
    price: undefined,
    amount: 0.21208,
    cost: 96.08,
    fee: { cost: 0.25, currency: 'EUR' },
    fees: [ [Object] ],
    _source: 'rest api'
  }
frosty00 commented 2 years ago
 {
    id: '215949779',
    info: {
      fee: '0.12351',
      order_id: 1443751124246528,
      datetime: '2022-01-04 16:21:16.475000',
      usd: 0,
      btc: 0,
      eth: '0.00724502',
      eth_eur: 3409.54,
      type: '2',
      id: 215949779,
      eur: '-24.70'
    },
    timestamp: 1641313276475,
    datetime: '2022-01-04T16:21:16.475Z',
    symbol: 'ETH/EUR',
    order: '1443751124246528',
    type: undefined,
    side: 'buy',
    takerOrMaker: undefined,
    price: 3409.54,
    amount: 0.00724502,
    cost: 24.7,
    fee: { cost: 0.12351, currency: 'EUR' },
    fees: [ { currency: 'EUR', cost: 0.12351 } ]
  }

@npomfret it's working for me, what version of ccxt are you using, can you provide a request + response?

npomfret commented 2 years ago

sorry for slow reply - just upgraded to "version": "1.66.52", and get the same problem.

I think this is the issue: https://github.com/ccxt/ccxt/blob/master/js/bitstamp.js#L663

The price field is not the market id, in my example it's in a field called eth_eur, I think the market ids don't have the underscore.

It has actually used the price field to correctly pick the market here: https://github.com/ccxt/ccxt/blob/master/js/bitstamp.js#L650

I think at this point we can assign the price as well.

fetch Request: bitstamp POST https://www.bitstamp.net/api/v2/user_transactions/ RequestHeaders: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36', 'X-Auth': 'BITSTAMP 9MhEfI2pfbPcUuaWkOzdNI2MFz4VFVUs', 'X-Auth-Nonce': '8b41fb46-107c-43ce-8d93-486fe466b44e', 'X-Auth-Timestamp': '1641667224408', 'X-Auth-Version': 'v2', 'Content-Type': 'application/x-www-form-urlencoded', 'X-Auth-Signature': '2f32c3433ebfc9fa537e5ad025c236ffd123df450d0874c622567ccdb0ec1b9d' }

ResponseBody: [{"fee": "0.00000000", "btc_usd": "0.00", "datetime": "2021-12-08 10:17:08.877639", "usd": 0.0, "btc": 0.0, "sgb": "0.00000005", "type": "0", "id": 212608071, "eur": 0.0}, {"fee": "0.00000000", "btc_usd": "0.00", "datetime": "2019-03-04 20:28:59.000000", "usd": 0.0, "btc": "-0.39511777", "type": "1", "id": 83531383, "eur": 0.0}, {"fee": "0.00000000", "btc_usd": "0.00", "id": 83531019, "usd": 0.0, "btc": 0.0, "datetime": "2019-03-04 20:14:35.000000", "type": "1", "xrp": "-2099.84999900", "eur": 0.0}, {"fee": "0.00000000", "btc_usd": "0.00", "datetime": "2019-03-04 20:08:51.000000", "usd": 0.0, "btc": 0.0, "eth": "-2.00000000", "type": "1", "id": 83530844, "eur": 0.0}, {"fee": "0.00006400", "bch": "-0.76380550", "order_id": 2959161577, "datetime": "2019-03-04 20:01:15.000000", "usd": 0.0, "btc": "0.02525182", "bch_btc": 0.03306054, "type": "2", "id": 83530714, "eur": 0.0}, {"fee": "0.00000300", "bch": "0.01131550", "order_id": 1826070832, "datetime": "2018-08-13 16:34:15.000000", "usd": 0.0, "btc": "-0.00100000", "bch_btc": 0.08837442, "type": "2", "id": 72149445, "eur": 0.0}, {"fee": "0.90", "btc_usd": "0.00", "datetime": "2018-07-27 08:56:46.000000", "usd": 0.0, "btc": 0.0, "type": "1", "id": 70988957, "eur": "-1993.69"}, {"usd": "-245.27", "btc_usd": 8273.10000000, "order_id": 1904325293, "datetime": "2018-07-26 08:44:55.000000", "fee": "0.62000", "btc": "0.02964668", "type": "2", "id": 70929774, "eur": 0.0}, {"fee": "0.00018400", "order_id": 1739084557, "eth_btc": 0.07342958, "datetime": "2018-06-25 04:57:22.000000", "usd": 0.0, "btc": "-0.07342958", "eth": "1.00000000", "type": "2", "id": 69032893, "eur": 0.0}, {"fee": "0.79000", "order_id": 1735957430, "datetime": "2018-06-24 15:51:35.000000", "usd": 0.0, "btc": 0.0, "eth": "0.86000000", "eth_eur": 363.80000000, "type": "2", "id": 68993378, "eur": "-312.87"}, {"fee": "0.13000", "order_id": 1735957430, "datetime": "2018-06-24 15:51:35.000000", "usd": 0.0, "btc": 0.0, "eth": "0.14000000", "eth_eur": 363.79000000, "type": "2", "id": 68993377, "eur": "-50.93"}, {"usd": "-1761.24", "btc_usd": 5870.79000000, "order_id": 1734421912, "datetime": "2018-06-24 08:46:06.000000", "fee": "4.41000", "btc": "0.30000000", "type": "2", "id": 68969164, "eur": 0.0}, {"fee": "1.25000", "order_id": 1733870503, "datetime": "2018-06-24 06:36:19.000000", "usd": 0.0, "btc": "0.10000000", "btc_eur": 4993.74000000, "type": "2", "id": 68961144, "eur": "-499.37"}, {"usd": "97.29", "order_id": 1718110096, "datetime": "2018-06-21 09:31:04.000000", "ltc": "-1.00000000", "ltc_usd": 97.29000000, "fee": "0.25000", "btc": 0.0, "type": "2", "id": 68763369, "eur": 0.0}, {"fee": "0.00000000", "btc_usd": "0.00", "datetime": "2018-06-21 07:27:07.000000", "usd": 0.0, "btc": 0.0, "eth": "-16.53281574", "type": "1", "id": 68759185, "eur": 0.0}, {"fee": "0.00000000", "btc_usd": "0.00", "datetime": "2018-06-19 14:23:23.000000", "usd": 0.0, "btc": 0.0, "eth": "-0.10000000", "type": "1", "id": 68690901, "eur": 0.0}, {"usd": "-93.25", "order_id": 1694727197, "datetime": "2018-06-16 15:42:53.000000", "ltc": "1.00000000", "ltc_usd": 93.25000000, "fee": "0.24000", "btc": 0.0, "type": "2", "id": 68563028, "eur": 0.0}, {"usd": "-553.96", "bch": "0.65249000", "order_id": 1693922728, "datetime": "2018-06-16 11:40:33.000000", "fee": "1.39000", "bch_usd": 849.00000000, "btc": 0.0, "type": "2", "id": 68555800, "eur": 0.0}, {"fee": "0.00008500", "order_id": 1672498519, "id": 68283423, "usd": 0.0, "xrp_btc": 0.00008475, "btc": "-0.03390000", "datetime": "2018-06-12 22:36:14.000000", "type": "2", "xrp": "400.00000000", "eur": 0.0}, {"fee": "0.00008500", "order_id": 1672462921, "id": 68283021, "usd": 0.0, "xrp_btc": 0.00008494, "btc": "-0.03397600", "datetime": "2018-06-12 22:29:03.000000", "type": "2", "xrp": "400.00000000", "eur": 0.0}, {"fee": "0.00001300", "order_id": 1663545532, "id": 68153861, "usd": 0.0, "xrp_btc": 0.00008535, "btc": "-0.00512100", "datetime": "2018-06-11 07:48:33.000000", "type": "2", "xrp": "60.00000000", "eur": 0.0}, {"fee": "0.00007300", "order_id": 1663545532, "id": 68153855, "usd": 0.0, "xrp_btc": 0.00008535, "btc": "-0.02901900", "datetime": "2018-06-11 07:48:29.000000", "type": "2", "xrp": "340.00000000", "eur": 0.0}, {"fee": "0.01000", "order_id": 1660243896, "datetime": "2018-06-10 19:07:19.000000", "usd": 0.0, "btc": 0.0, "eth": "0.00002000", "eth_eur": 453.07000000, "type": "2", "id": 68087959, "eur": "-0.01"}, {"fee": "0.33000", "order_id": 1660243896, "datetime": "2018-06-10 18:59:53.000000", "usd": 0.0, "btc": 0.0, "eth": "0.28790000", "eth_eur": 453.07000000, "type": "2", "id": 68086700, "eur": "-130.44"}, {"fee": "0.25000", "order_id": 1660243896, "datetime": "2018-06-10 18:59:51.000000", "usd": 0.0, "btc": 0.0, "eth": "0.21208000", "eth_eur": 453.05000000, "type": "2", "id": 68086689, "eur": "-96.08"}]

npomfret commented 2 years ago

@kroitor does this ^ make sense?

ttodua commented 2 years ago

@npomfret I'm checking this issue and will submit fix shortly.

ttodua commented 2 years ago

I was unable to reproduce the issue. I've tested:

npomfret commented 2 years ago

I'm not using any modifications and I think I'm using a very recent build. The issue is with fetchMyTrades. The parseTrade method doesn't work for data that looks like this:

{
      fee: '0.00008500',
      order_id: 1672462921,
      id: 68283021,
      usd: 0,
      xrp_btc: 0.00008494,   <-- this is the price
      btc: '-0.03397600',
      datetime: '2018-06-12 22:29:03',
      type: '2',
      xrp: '400.00000000',
      eur: 0
    }

The issue is that the following returns an undefined priceString:

priceString = this.safeString (trade, market['marketId'], priceString);

I think this would work:

priceString = this.safeString (trade, market['symbolId'], priceString);

You can see here the code used to use symbolId. I think revision 6462e823849d45b666009d985a78904df061c534 caused the problem.

Also, I'm not sure how you're got it to work in your testing, it seems to fail for 100% of the trades in my trade history.

fetch Request:
 bitstamp POST https://www.bitstamp.net/api/v2/user_transactions/ 
RequestHeaders:
 {
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36',
  'X-Auth': 'BITSTAMP gg',
  'X-Auth-Nonce': 'gg
  'X-Auth-Timestamp': '1643537229605',
  'X-Auth-Version': 'v2',
  'Content-Type': 'application/x-www-form-urlencoded',
  'X-Auth-Signature': 'gg'
} 
RequestBody:
 limit=20&offset=0 

handleRestResponse:
 bitstamp POST https://www.bitstamp.net/api/v2/user_transactions/ 200 OK 
ResponseHeaders:
 {
  'Access-Control-Allow-Headers': 'x-requested-with, Content-Type, origin, accept, cache-control',
  'Access-Control-Allow-Methods': 'POST, GET',
  'Access-Control-Allow-Origin': '*',
  'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
  Connection: 'keep-alive',
  'Content-Encoding': 'gzip',
  'Content-Language': 'en',
  'Content-Security-Policy': "default-src 'self' 'report-sample'; base-uri 'self' ; connect-src 'self' wss://ws.bitstamp.net *.bitstamp.net *.trackjs.com *.google-analytics.com stats.g.doubleclick.net *.mixpanel.com *.branch.io hcaptcha.com *.hcaptcha.com ; font-src 'self' data: assets.bitstamp.net fonts.gstatic.com fonts.gstatic.cn www.google.com ; frame-ancestors 'self'; frame-src 'self' pixel-a.basis.net *.youtube-nocookie.com 8720977.fls.doubleclick.net *.ledgerwallet.com *.google.com www.recaptcha.net www.googletagmanager.com pixel.sitescout.com ctpe.net hcaptcha.com *.hcaptcha.com player.twitch.tv ; img-src * data: blob:; media-src 'self' assets.bitstamp.net ; object-src 'self' blob:; report-uri /api/report-csp/; script-src 'self' 'report-sample' 'unsafe-eval' assets.bitstamp.net js-agent.newrelic.com *.google-analytics.com d3dy5gmtp8yhk7.cloudfront.net www.googleadservices.com www.googletagmanager.com www.gstatic.com www.gstatic.cn www.recaptcha.net code.highcharts.com/stock/highstock.js bam.nr-data.net cdn.mxpnl.com app.link hcaptcha.com *.hcaptcha.com 'nonce-MTA2NzYyNDA2MTMwNDQ3NDcyMDI0MzYwNjg0MjMwNjIzNTE4MTk='; style-src 'self' 'unsafe-inline' assets.bitstamp.net fonts.googleapis.com hcaptcha.com *.hcaptcha.com",
  'Content-Type': 'application/json',
  Date: 'Sun, 30 Jan 2022 10:07:09 GMT',
  Expires: 'Sun, 30 Jan 2022 10:07:09 GMT',
  'Last-Modified': 'Sun, 30 Jan 2022 10:07:09 GMT',
  Server: 'Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips mod_wsgi/4.7.1 Python/2.7',
  'Set-Cookie': 'stmpdid=oDR_cdobYd1zJ8Ym41XQuxgyNxMpGEqqb42zLSCB99MaB6BOSsFO8tE2C81Yx6wwsHfH6sWcBW_8js8CJXrUBGk; expires=Sun, 28-Jan-2029 10:07:09 GMT; httponly; Max-Age=220752000; Path=/; secure, visid_incap_99025=ZuvEuiSnSFOUFZ+/Nf9PI01j9mEAAAAAQUIPAAAAAADyCZ9RK+0I8Lr7Ne++syEF; expires=Sun, 29 Jan 2023 14:30:27 GMT; HttpOnly; path=/; Domain=.bitstamp.net, nlbi_99025=4clGLGqfTGTIiwNS5Q12eAAAAADU/0FCAJ5aH8G2GnOHjSkm; path=/; Domain=.bitstamp.net, incap_ses_393_99025=YIMfAeHfq308F6yx7zd0BU1j9mEAAAAASqpt1F0kvDJvGl+6eNyn7Q==; path=/; Domain=.bitstamp.net',
  'Strict-Transport-Security': 'max-age=63072000; includeSubDomains',
  'Transfer-Encoding': 'chunked',
  Vary: 'Authorization,Accept-Language,Cookie,Accept-Encoding',
  'X-Bts-Request-Trace-Id': 'Root=1-61f6634d-64af08323adec9ae0f45073a',
  'X-Cdn': 'Imperva',
  'X-Frame-Options': 'SAMEORIGIN',
  'X-Iinfo': '0-2735720-2735721 NNNN CT(9 10 0) RT(1643537229450 19) q(0 0 0 -1) r(1 1) U6',
  'X-Server-Auth-Signature': 'ea3e679bd210004a6f0dc255b383d910902200cbbee63434785924d0fbdcd2c2',
  'X-Xss-Protection': '1; mode=block'
} 
ResponseBody:
 [{"fee": "0.00000000", "btc_usd": "0.00", "datetime": "2021-12-08 10:17:08.877639", "usd": 0.0, "btc": 0.0, "sgb": "0.00000005", "type": "0", "id": 212608071, "eur": 0.0}, {"fee": "0.00000000", "btc_usd": "0.00", "datetime": "2019-03-04 20:28:59", "usd": 0.0, "btc": "-0.39511777", "type": "1", "id": 83531383, "eur": 0.0}, {"fee": "0.00000000", "btc_usd": "0.00", "id": 83531019, "usd": 0.0, "btc": 0.0, "datetime": "2019-03-04 20:14:35", "type": "1", "xrp": "-2099.84999900", "eur": 0.0}, {"fee": "0.00000000", "btc_usd": "0.00", "datetime": "2019-03-04 20:08:51", "usd": 0.0, "btc": 0.0, "eth": "-2.00000000", "type": "1", "id": 83530844, "eur": 0.0}, {"fee": "0.00006400", "bch": "-0.76380550", "order_id": 2959161577, "datetime": "2019-03-04 20:01:15", "usd": 0.0, "btc": "0.02525182", "bch_btc": 0.03306054, "type": "2", "id": 83530714, "eur": 0.0}, {"fee": "0.00000300", "bch": "0.01131550", "order_id": 1826070832, "datetime": "2018-08-13 16:34:15", "usd": 0.0, "btc": "-0.00100000", "bch_btc": 0.08837442, "type": "2", "id": 72149445, "eur": 0.0}, {"fee": "0.90", "btc_usd": "0.00", "datetime": "2018-07-27 08:56:46", "usd": 0.0, "btc": 0.0, "type": "1", "id": 70988957, "eur": "-1993.69"}, {"usd": "-245.27", "btc_usd": 8273.10000000, "order_id": 1904325293, "datetime": "2018-07-26 08:44:55", "fee": "0.62000", "btc": "0.02964668", "type": "2", "id": 70929774, "eur": 0.0}, {"fee": "0.00018400", "order_id": 1739084557, "eth_btc": 0.07342958, "datetime": "2018-06-25 04:57:22", "usd": 0.0, "btc": "-0.07342958", "eth": "1.00000000", "type": "2", "id": 69032893, "eur": 0.0}, {"fee": "0.79000", "order_id": 1735957430, "datetime": "2018-06-24 15:51:35", "usd": 0.0, "btc": 0.0, "eth": "0.86000000", "eth_eur": 363.80000000, "type": "2", "id": 68993378, "eur": "-312.87"}, {"fee": "0.13000", "order_id": 1735957430, "datetime": "2018-06-24 15:51:35", "usd": 0.0, "btc": 0.0, "eth": "0.14000000", "eth_eur": 363.79000000, "type": "2", "id": 68993377, "eur": "-50.93"}, {"usd": "-1761.24", "btc_usd": 5870.79000000, "order_id": 1734421912, "datetime": "2018-06-24 08:46:06", "fee": "4.41000", "btc": "0.30000000", "type": "2", "id": 68969164, "eur": 0.0}, {"fee": "1.25000", "order_id": 1733870503, "datetime": "2018-06-24 06:36:19", "usd": 0.0, "btc": "0.10000000", "btc_eur": 4993.74000000, "type": "2", "id": 68961144, "eur": "-499.37"}, {"usd": "97.29", "order_id": 1718110096, "datetime": "2018-06-21 09:31:04", "ltc": "-1.00000000", "ltc_usd": 97.29000000, "fee": "0.25000", "btc": 0.0, "type": "2", "id": 68763369, "eur": 0.0}, {"fee": "0.00000000", "btc_usd": "0.00", "datetime": "2018-06-21 07:27:07", "usd": 0.0, "btc": 0.0, "eth": "-16.53281574", "type": "1", "id": 68759185, "eur": 0.0}, {"fee": "0.00000000", "btc_usd": "0.00", "datetime": "2018-06-19 14:23:23", "usd": 0.0, "btc": 0.0, "eth": "-0.10000000", "type": "1", "id": 68690901, "eur": 0.0}, {"usd": "-93.25", "order_id": 1694727197, "datetime": "2018-06-16 15:42:53", "ltc": "1.00000000", "ltc_usd": 93.25000000, "fee": "0.24000", "btc": 0.0, "type": "2", "id": 68563028, "eur": 0.0}, {"usd": "-553.96", "bch": "0.65249000", "order_id": 1693922728, "datetime": "2018-06-16 11:40:33", "fee": "1.39000", "bch_usd": 849.00000000, "btc": 0.0, "type": "2", "id": 68555800, "eur": 0.0}, {"fee": "0.00008500", "order_id": 1672498519, "id": 68283423, "usd": 0.0, "xrp_btc": 0.00008475, "btc": "-0.03390000", "datetime": "2018-06-12 22:36:14", "type": "2", "xrp": "400.00000000", "eur": 0.0}, {"fee": "0.00008500", "order_id": 1672462921, "id": 68283021, "usd": 0.0, "xrp_btc": 0.00008494, "btc": "-0.03397600", "datetime": "2018-06-12 22:29:03", "type": "2", "xrp": "400.00000000", "eur": 0.0}] 
ttodua commented 2 years ago

I am again checking the issue now. This seems weird. In the meanwhile: 1) if you check https://github.com/ccxt/ccxt/blob/f1edcb20c8874241e9b7744f812877336e2d6a95/js/bitstamp.js#L312 you will see that symbolId is same as marketId now: https://github.com/ccxt/ccxt/blob/master/js/bitstamp.js#L347 2) unrelated question in the meanwhile: from where does this line came? _source: 'rest api' 3) also, please upload your /ccxt/js/bitstamp.js file content to somewhere (i.e pastebin(dot)com, with 1 week expiration) and put the link here. 4) also, as suggested by 'how to ask a good question', please show your script part how you initialize and call fetchMyTrades (scramble any sensitive parts, but provide the full sample script that you run), i.e:

let exch = new ccxt.bitstamp(..);
exch.verbose = true;
exch.fetchMyTrades();

5) I think, it will be also good if you provide the full versobse outputs (including the 'markets' response) , so everything that returns including initial 'markets' response.

6) do you use some approaches that uses caching or resetting the markets properties of the loaded exchange?

I will need the above infos to clarify this weird situation, as I'm testing your exact response and on my side, it returns correct values (works 100% cases).

npomfret commented 2 years ago

I will get back to you - perhaps I have picked up some cached data, I didn't think to check that. For me, the symbolId and marketId are different

ttodua commented 2 years ago

ok, please check that and let me know whenever you can, as I am on the trace of this issue, and would be glad if you provide the further info. The issue seems only to be present if market-objects of the exchange class are messed/cached from very old initializations (i.e. days or weeks cached data). It would be even best, if you re-installed ccxt in separate folder/pc , from clean state and (without interaction to your possible cached data) test your 'fetchMyTrades' method again, and see if there wors.