coblox / nectar

GNU General Public License v3.0
0 stars 1 forks source link

Better `Rate` model #24

Closed da-kami closed 4 years ago

da-kami commented 4 years ago

Note: In an attempt to document this closer to the code and have proper highlighting I decided to write a ticket instead of a ToDo on Basecamp. Please don't hate me for that :)

Problem

Rate, Order and Spread are not aligned (which is a problem on top of this ticket).

To fix this I would propose to get the Rate model fixed first and then see how/if we want to change Order and Spread.

The Rate is currently depicted like this: https://github.com/coblox/nectar/blob/44cd27c4ecd2537123a996121d9e5b11f60932c4/src/markets.rs#L9-L15

I would generally suggest to stick to bid and ask for rates and buy and sell for orders. Because buy and sell are order positions, whereas the rate is independent of the order and expressed the bid and ask price for a trading pair.

This is an attempt to iterate on the model to come up with a better one. I want to document this choice and put it up for discussion first, because I feel otherwise the model will not improve :)

Goal

The Rate should include enough information to crate orders for both positions (both buy and sell orders).

Have a more uniform model that adheres to the actual meaning of certain terms.

Suggestion:

I came to the conclusion that the Rate is agnostic of the order. It's probably better to stick to bid/ask and not buy/sell to avoid confusion. Only the order has to decide which part of the rate (bid/ask) is relevant to come up with the correct amounts.

Depict the Rate similar to Kraken (they actually did think about it when they modelled it...) so it is relatable what we are doing.

Suggested:

#[derive(Debug, Copy, Clone, PartialEq)]
pub struct Rate {
    trading_pair: TradingPair,
    bid: f64,
    ask: f64,
    timestamp: DateTime<Utc>,
}

Note that we don't have to use f64, but could also depict as satoshi to USD-millicents (as DAI represents USD), but that is a different discussion that can be solved at a later point.

da-kami commented 4 years ago

will move to basecamp