Comments (2)
Hello maintainer, I've been doing some research on this topic recently, so I want to tell you my opinion on this part.
I think using "String" as-is is the best choice for this crate,
because the reason why we need some monetary data type is for arithmetic operations. inside this crate, However, we do not perform any arithmetic operations.
this crate is responsible for communicate with coinbase, not for arithmetic operation. So I think it's a good idea to leave it up to the user to decide which monetary data type (like rust-decimal) to use.
If rust-decimal is the only best option for monetary data type, it will be good idea to use it as base data type for this crate. but it is inherently slower than some other options. below is the simple benchmark result of arithmetic operation. d128, decimal, f64 correspond to IBM's decnumber(IEEE754-2008 DPD implementation), rust-decimal, f64 respectively.
as you see rust-decimal is much more slower than f64.
I know f64 is not a good option for financial calculation. (some say it's fine in most realistic value range if you round the value after every operation. I'm not sure whether this proposition is true or not.) However, there are the way to achieve performance comparable to the f64. you can rescale the value to make it into integer and doing arithmetic operation with integer value. For example, BTC's quote_increment is 0.01 at coinbase, so that we can convert BTC price as integer by multiplying it with 100. This method has a downside that user should take in mind that the value is rescaled, but it will be much more faster than rust-decimal.
In conclusion, I think user should choose which data type to use. if they want to simple solution to solve precision error, use rust-decimal(or arbitrary precision type), and if they care about speed, use integer-rescale(or f64 with rounding?). It will be better for this crate to not limit the user's choice.
thanks for reading! I'll look forward to hearing your opinion.
from coinbase-pro-rs.
@SeanKim Awesome exploration. Thank you.
I really did not expect decimal is so slow, I know there are a lot of different implementations, but I expect that one of them is just to fix precision (0.01 for the BTC) and I expected that it has +- the same performance like 100* solution.
from coinbase-pro-rs.
Related Issues (11)
- Avoid creation of runtime on every Sync request HOT 1
- Async updates HOT 7
- dynamic subscription HOT 1
- new_size value missing in Full::Change json message
- get_orders() API doesn't allow getting "all" orders
- Could you publish a new release? HOT 3
- Question on API Docs
- Add pagination to the Public::get_trades API
- base_min_size not present in get_product, causing a crash HOT 3
- Serde { error: Error("EOF while parsing a value", line: 1, column: 0), data: "" } HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coinbase-pro-rs.