project-serum / serum-ts

Project Serum TypeScript monorepo
https://projectserum.com
Apache License 2.0
270 stars 245 forks source link

Market Precision rounding #239

Open Triggsy22 opened 2 years ago

Triggsy22 commented 2 years ago

There are some possibilites to get the number of decimal places a market has. But how do i get the amount of decimal places that are allowed to trade with.

As an example SOL/USD. SOL has 9 decimal places but its just allowe to trade with 1. So if you try to create an order to buy 0.12345678 SOL, it will be automatically converted to an order to buy just 0.1 SOL. You get no error or something and you notice it only if you check your order after creating it.

And why is only 1 decimal place allowed? Thats realy strange. On kraken, where my bots currently runnig, are 8 places the maximum. For me, this is again crucial.

On other Markets it looks the same.

Triggsy22 commented 2 years ago

Ok, i found why serum is not using more decimal precision. Because its just not possible. Or it would create terrible results. Some Parts of the orderCreation stuff works with the datatype number. And Number is a float value. It begins with placeOrder in market.ts and goes down until priceNumberToLots or baseSizeNumberToLots, where it gets converted.

Right now I don't understand serum well enough, so I don't know how much it affects the network. But i think this is a big Problem.

We all know the Problems of float precisions. There are some great Librarys out there to deal with this issue, like math.js