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.

markets "contractSize" wrong data type

See original GitHub issue
  • OS: linux
  • Programming Language version: all (although i personally only really care about python for now)
  • CCXT version: latest main - v1.65.19

the type of contractSize seems to be a string throughout the exchanges I’ve tested - which seems and feels wrong to me.

Based on the documentation i’d expect it to be a float, which would align the “position structure” with the response of the market response.

Screenshot_20220104_192835

I also don’t think any value other than a float will be a possible/allowed value for contractSize - as we’d expect to multiply (or divide) by that number to go from amount to what the exchange expects and viceversa.

Having this as string makes all calculations necessary for futures quite odd, as we’ll have to do explicitly convert contract-size to number (e.g. amount * float(market['contractSize'])).

 node examples/js/cli.js okex market BTC/USDT:USDT
okex.market (BTC/USDT:USDT)
0 ms
{         limits: { leverage: { min: undefined, max: 125 },
                      amount: { min: 1, max: undefined },
                       price: { min: 0.1, max: undefined },
                        cost: { min: 0.1, max: undefined }  },
       precision: { amount: 1, price: 0.1 },
       tierBased:    undefined,
      percentage:    undefined,
           taker:    0.0005,
           maker:    0.0002,
              id:   "BTC-USDT-SWAP",
          symbol:   "BTC/USDT:USDT",
            base:   "BTC",
           quote:   "USDT",
          baseId:   "BTC",
         quoteId:   "USDT",
        settleId:   "USDT",
          settle:   "USDT",
            info: {     alias: "",
                      baseCcy: "",
                     category: "1",
                       ctMult: "1",
                       ctType: "linear",
                        ctVal: "0.01",
                     ctValCcy: "BTC",
                      expTime: "",
                       instId: "BTC-USDT-SWAP",
                     instType: "SWAP",
                        lever: "125",
                     listTime: "1636620057000",
                        lotSz: "1",
                        minSz: "1",
                      optType: "",
                     quoteCcy: "",
                    settleCcy: "USDT",
                        state: "live",
                          stk: "",
                       tickSz: "0.1",
                          uly: "BTC-USDT"       },
            type:   "swap",
            spot:    false,
         futures:    false,
            swap:    true,
        contract:    true,
          option:    false,
          linear:    true,
         inverse:    false,
          active:    true,
    contractSize:   "0.01",    <-- would like to be a number ... 
          expiry:    undefined,
  expiryDatetime:    undefined                               

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
frosty00commented, Jan 6, 2022

Yeah I think probably we’ll need to have a variable called contractSizeString or similar

2reactions
samgermaincommented, Jan 6, 2022

@xmatthias it may seem like it is the wrong data type but we actually store it as a string on purpose since we need to do stringMaths using contractSize inside of parsePosition and some other places

Having this as string makes all calculations necessary for futures quite odd, as we’ll have to do explicitly convert contract-size to number (e.g. amount * float(market[‘contractSize’])).

that’s cause you are using floating point maths

Based on the documentation i’d expect it to be a float, which would align the “position structure” with the response of the market response.

I’ll update the docs

I think that we should convert contractSize to a string when we need to do string math internally, but the value returned from fetchMarkets should be a float. Almost every user would want the contract size to be a float, and would expect it to be a float, and returning a string is just kind of weird to the user when it’s only a string to help with internal use

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fat-finger error - Wikipedia
A fat-finger error is a keyboard input error or mouse misclick in the financial markets such ... size than intended, for the wrong...
Read more >
Responses to Frequently Asked Questions Concerning Rule ...
The exemption applies to transactions executed by a trading center to correct a “bona fide error,” which is defined as: (1) the inaccurate ......
Read more >
Tick Size: Definition in Trading, Requirements, and Examples
Tick size is the minimum price amount a security can move in an exchange. It's expressed in decimal points, which in U.S. markets...
Read more >
7 Tips Every Futures Trader Should Know | Charles Schwab
Here are seven strategies to help you improve your futures trading knowledge.
Read more >
Excel: Stocks Data Type - Strategic Finance
When you first use the Stocks data type feature in a workbook, a message appears in the information bar to warn that the...
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