ccxt: For-loops are translated incorrectly for Python

When I run npm run build, the piece of JS, like:

        for (var i = 0; i < rawOrders.length; i++) {
          let order = rawOrders[i];
          result.push (this.parseOrder (order, market));
        }

translated into Python code:

        for(var i = 0 i < len(rawOrders) i++) {
          order = rawOrders[i]
          result.append(self.parse_order(order, market))
        }

which is wrong and annoying šŸ‘Ž

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 47 (46 by maintainers)

Commits related to this issue

Most upvoted comments

@kroitor, tried to add better exception handling: https://github.com/ccxt/ccxt/pull/837

@orkenstein yep, it should throw an exception. We also have handleErrors() to catch the errors before the standard default HTTP error handler, you might want to put all checks into handleErrors(), see other existing implementations for examples. Most of the time it does throw an exception of a specific type (if recognized, like InsufficientFunds or InvalidOrder), or a generic exception (like DDoSProtection, NetworkError or ExchangeError).

More on error handling here: https://github.com/ccxt/ccxt/wiki/Manual#error-handling

@orkenstein the point is: you will never trade that much if you don’t account for the above. So, if you wish to trade that much some day, you have to consider this very carefully.

@orkenstein

what’s the crossplatform type conversion method. Say float -> int.

parseInt (floatNumberOrString)
parseFloat (StringOrInt)
...

Sorry, for asking too much.

No worries at all, feel free to ask questions, even if you think they might not be worth it…

Why don’t add this stuff to contribution guide?

Would love to, but didn’t have enough time for it just yet, that is why it’s a little outdated… I guess an answer to that sort of questions would always be ā€œwe never said we don’t want to do that, we just didn’t have time for that yetā€. In other words, if you see something missing, it’s most likely in progress. Your help on this would be appreciated a lot! I mean, the contribution guide is editable, if you think we should add something there, feel free to submit the edits, I’ll merge them all asap.

@orkenstein those should be handled like milliseconds timestamps in UTC. There’s a set of functions:

this.parse8601 (string)  // parse ISO8601 string to milliseconds-timestamp
this.iso8601 (timestamp) // convert a milliseconds-timestamp to ISO8601 string
this.microseconds ()     // get current timestamps in microseconds
this.milliseconds ()     // ...
this.seconds ()          // ...

@orkenstein oh, then you can raise the timeout (defaults to 10000 ms), just do exchange.timeout = 20000 or pass 'timeout': 20000 along with other constructor params upon instantiation.

@orkenstein currenty, it’s the long version of it:

if (string.indexOf (substring) >= 0) {
}

This is because includes can be used on arrays in JS in an interchangeable fashion, whereas in other languages the methods for lists and strings are different.

I know it can be frustrating sometimes, but until we have a full-featured AST any ←→ any converter, we have to be syntactically precise. Feel free to ask if you have any difficulty with it. Thx!

@kroitor yep, thanks, found and issue right before you posted a comment. Cheers. P.S: working on some Livecoin updates.