adshao / go-binance

A Go SDK for Binance API
MIT License
1.48k stars 663 forks source link

Why no correct types on structs #435

Closed byroncoetsee closed 2 weeks ago

byroncoetsee commented 1 year ago

Hi How come most of the structs use string on almost all of the variables which would always be, for example, a float64?

For example:

type CreateOrderResponse struct {
    Price                    string `json:"price"`
    OrigQuantity             string `json:"origQty"`
    ExecutedQuantity         string `json:"executedQty"`
}

Could be

type CreateOrderResponse struct {
    Price                    float64 `json:"price,string"`
    OrigQuantity             float64 `json:"origQty,string"`
    ExecutedQuantity         float64 `json:"executedQty,string"`
}

Which would allow one to actually do maths on those values without having to convert from a string every time...

I'm happy to make the change and submit a PR - I just want to check the reasoning (if any) for keeping them strings.

adshao commented 1 year ago

float64 is an inaccurate data type, you should not use it in price calculation, please use another decimal lib instead, for example, github.com/shopspring/decimal

xyq-c-cpp commented 2 weeks ago

No response for a long time, close this issue