Code Monkey home page Code Monkey logo

openlimits's Introduction

build security

A open source Rust high performance cryptocurrency trading API with support for multiple exchanges and language wrappers. Focused in safety, correctness and speed.

Project goals

This is an ambitious project that seeks to create a new industry standard API implementation for secure, correct and high performance cryptocurrency trading. It is initially focused on spot exchanges as a method to define how initial data structures and project architecture should be to allow zero cost abstractions around the exchanges' peculiarities. So initial project goals are:

  • Based on Rust, memory safe by default.
  • Support for websockets and user defined networking.
  • Thin layer wrappers for Java, C#, Python and Node.js
  • Easy to add support for additional exchanges.
  • Open-source only, now and forever.

Future goals are:

  • Support for futures trading
  • Support for options trading
  • WASM compilation allowing it to be embedded in static web pages

Warning: the project is still in development and a lot of breaking changes are being made.

Community

Click here to access our Discord Community.

Testing

In order to run the tests you will have to provide environment variables for the sandbox API of the exchanges, you can use environment variables or use a .env file.

Sponsorship

We invite industry participants to join us in sponsoring a new high quality open source standard for crypto trading APIs. Nash is dedicating a maintainer and initial rewards for external contributors that close issues. Look for the wiki rewards table and for reward size labels on open issues.

openlimits's People

Contributors

anykao avatar canesin avatar ejhfast avatar fabianboesiger avatar github-actions[bot] avatar hermanodecastro avatar jankjr avatar jnicholls avatar leruaa avatar mankinskin avatar notdanilo avatar notonamap avatar nyanilo avatar oiaren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openlimits's Issues

Terminology: symbol vs pair

In the openLimits models there are both terminologies (symbol and pair) for the same thing, witch may be confusing.

For instance:

#[derive(Clone, Constructor, Debug)]
pub struct Order<T> {
    pub id: T,
    pub symbol: String, // <------------------------------------
    pub client_order_id: Option<String>,
    pub created_at: DateTime<Utc>,
}

#[derive(Clone, Constructor, Debug)]
pub struct CancelOrderRequest<T> {
    pub id: T,
    pub pair: Option<String>, // <------------------------------------
}

I think it could be harmonized, but which term to choose?

Update market orders tests

Some market order tests are failing because of the recent market changes. The prices should be dynamically fetch in order to place a market order.

Add rules for merging to master

  • CI must be passing
  • The PR must have been reviewed and approved by at least one reviewer
  • No warning messages in the build process

Merging should be blocked otherwise.

Open Telegram Group?

Hi, I am new to this project, and I must say that I found the slack chat room very inaccessible and complicated to find. I am using Telegram for other projects, or basically any chatting at all, already, and it is very versatile and accessible. I would like to suggest opening a telegram group for this project aswell, to make it more accessible.

Binance web socket stream disconnects

The binance web socket API doc states that:

The websocket server will send a ping frame every 3 minutes. If the websocket server does not receive a pong frame back from the connection within a 10 minute period, the connection will be disconnected. Unsolicited pong frames are allowed.

Add Exchange information

The first step toward getting #29 done is to fetch the exchange information (the pairs informations) and cache it in the exchange object.

The function that pull the exchange information should have an option to refresh the cache.

binance
coinbase

Their is no need to expose this as part of the openlimits trait for now.

Decimal precision

Issue

The decimal precision can't be too high otherwise the exchange API will reject the request.

eg: When using binance API, if I want to buy 123.45 USDT value of BTC at 9,500.01, the request will be:

price: 9500.01
qty: 0.01299472316

But binance API only accepts 8 decimal on the BTC asset for this trading pair., the request should be converted to:

price: 9500.01
qty: 0.01299472

Proposed solutions

The exchanges provides a list of the pairs with the precision expected. coinbase binance ftx as you can see some exchange are using quote and price precision others are using a price and size increment.

Solution 1

When creating an order, the exchange SDK will fetch the exchange information (from a cache) in order to get the required precision/increment information and apply the rounding/truncating. This has some performances implication when you have to look for a specific pair every times you want to create a new order especially when you are using an exchange with a lots of pairs like binance (881 now).

Solution 2

Create a new type for pair that replace String that will keep the price and qty increments for the pair.

pair_name: String,
price_increment: Decimal
qty_increment: Decimal

An exchanges trait will be added in order to create the pair type, the implementation will look for the exchanges information to get the increments values.

When creating an order the price and qty increments will be fetched from the pair type.

Usage

I suggest adding a new parameter to the OrderRequest types named precision_rule_qty and precision_rule_price with a default value set. For a sell price precision will be defaulted to Round, for buy it will be Truncate, qty will default to Truncate.

The precision rule could also be set on the exchange instead of specified on every order.

enum PrecisionRule {
 Round,
 Truncate
 None
}

Notes

Binance

After trying to submit some orders, they are rejected because they should also fit the step size filter, step size seems to be a better indicator of the precision.

{"symbol":"BTCUSDT","status":"TRADING","baseAsset":"BTC","baseAssetPrecision":8,"quoteAsset":"USDT","quotePrecision":8,"quoteAssetPrecision":8,"baseCommissionPrecision":8,"quoteCommissionPrecision":8,"orderTypes":["LIMIT","LIMIT_MAKER","MARKET","STOP_LOSS_LIMIT","TAKE_PROFIT_LIMIT"],"icebergAllowed":true,"ocoAllowed":true,"quoteOrderQtyMarketAllowed":true,"isSpotTradingAllowed":true,"isMarginTradingAllowed":true,"filters":[{"filterType":"PRICE_FILTER","minPrice":"0.01000000","maxPrice":"1000000.00000000","tickSize":"0.01000000"},{"filterType":"PERCENT_PRICE","multiplierUp":"5","multiplierDown":"0.2","avgPriceMins":5},{"filterType":"LOT_SIZE","minQty":"0.00000100","maxQty":"9000.00000000","stepSize":"0.00000100"},{"filterType":"MIN_NOTIONAL","minNotional":"10.00000000","applyToMarket":true,"avgPriceMins":5},{"filterType":"ICEBERG_PARTS","limit":10},{"filterType":"MARKET_LOT_SIZE","minQty":"0.00000000","maxQty":"526.58296769","stepSize":"0.00000000"},{"filterType":"MAX_NUM_ORDERS","maxNumOrders":200},{"filterType":"MAX_NUM_ALGO_ORDERS","maxNumAlgoOrders":5}],"permissions":["SPOT","MARGIN"]},

Nash

query ListMarkets {
  ListMarkets{
    aAsset{
      blockchain
    } ...
  }
}

Exchanges

This exchanges supports getting the market pairs with the price/qty increment

Binance::with_credential causes panic

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ReqError(reqwest::Error { kind: Decode, source: Error("unknown variant `MAX_POSITION`, expected one of `LOT_SIZE`, `PRICE_FILTER`, `MIN_NOTIONAL`, `MAX_NUM_ALGO_ORDERS`, `MAX_NUM_ORDERS`, `ICEBERG_PARTS`, `PERCENT_PRICE`, `MARKET_LOT_SIZE`", line: 1, column: 985268) })', /home/####/git/openlimits/src/binance/mod.rs:45:43
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This was due to Exchange::refresh_market_info being called in Binance::with_credential:

    pub async fn with_credential(api_key: &str, api_secret: &str, sandbox: bool) -> Self {
        let mut state = Binance {
            exchange_info: ExchangeInfo::new(),
            transport: Transport::with_credential(api_key, api_secret, sandbox).unwrap(),
        };

        state.refresh_market_info().await.unwrap();
        state
    }

Removing the last bit fixes the panic.
I am not sure what refresh_market_info exactly does, but it seems unnecessary to run it in the initialization method, because this should just give you a minimal working instance of Binance, and refresh_market_info seems to perform some calls to the binance API, which is not necessarily wanted.

Issues with price-ticker retrieval

#[tokio::test]
async fn get_price_ticker_error() {
    let exchange = init().await;
    let req1 = OrderBookRequest {
        market_pair: "btc_usdc".to_string(),
    };
    let req2 = GetPriceTickerRequest {
        market_pair: "btc_usdc".to_string(),
    };

    let r1 = exchange.get_price_ticker(&req2).await;
    let r2 = exchange.order_book(&req1).await;
    let r3 = exchange.get_price_ticker(&req2).await;

    println!("{:?}", r1);
    println!("{:?}", r2);
    println!("{:?}", r3);
}

It seems like the price ticker retrieval becomes corrupted after we do another protocol action like getting the orderbook etc. Have you seen this before @Ejhfast?

Ok(Ticker { price: 13088.15000000 })
Ok(OrderBookResponse { last_update_id: None, bids: [AskBid { price: 0.20000000, qty: 26.00000000 }, AskBid { price: 1.10000000, qty: 5.00000000 }, AskBid { price: 1.70000000, qty: 3.52941176 }, AskBid { price: 3.40000000, qty: 2.94117647 }, AskBid { price: 5.10000000, qty: 1.00000000 }, AskBid { price: 6.30000000, qty: 3.00000000 }, AskBid { price: 7.00000000, qty: 0.85714285 }, AskBid { price: 10.00000000, qty: 1.00000000 }, AskBid { price: 11.80000000, qty: 0.84745762 }, AskBid { price: 12.60000000, qty: 3.00000000 }, AskBid { price: 20.00000000, qty: 0.33000000 }, AskBid { price: 20.10000000, qty: 1.00000000 }, AskBid { price: 25.00000000, qty: 0.26600000 }, AskBid { price: 25.20000000, qty: 3.00000000 }, AskBid { price: 28.90000000, qty: 0.20761245 }, AskBid { price: 29.00000000, qty: 1.00000000 }, AskBid { price: 30.00000000, qty: 1.00000000 }, AskBid { price: 31.00000000, qty: 2.31935483 }, AskBid { price: 37.90000000, qty: 0.26385224 }, AskBid { price: 50.00000000, qty: 1.00000000 }, AskBid { price: 89.90000000, qty: 2.04449388 }, AskBid { price: 100.00000000, qty: 3.30000000 }, AskBid { price: 111.00000000, qty: 0.09009009 }, AskBid { price: 125.00000000, qty: 0.04080000 }, AskBid { price: 127.00000000, qty: 0.13385826 }, AskBid { price: 204.00000000, qty: 0.17156862 }, AskBid { price: 335.00000000, qty: 0.61432835 }, AskBid { price: 389.00000000, qty: 0.02570694 }, AskBid { price: 540.00000000, qty: 0.39814814 }, AskBid { price: 900.00000000, qty: 1.10000000 }, AskBid { price: 1311.00000000, qty: 1.10000000 }, AskBid { price: 1399.00000000, qty: 0.01429592 }, AskBid { price: 1401.00000000, qty: 0.00613847 }, AskBid { price: 2495.00000000, qty: 0.10020040 }, AskBid { price: 3215.00000000, qty: 0.09953343 }, AskBid { price: 3275.00000000, qty: 0.12213740 }, AskBid { price: 4000.00000000, qty: 0.25000000 }, AskBid { price: 4500.00000000, qty: 0.22222222 }, AskBid { price: 5000.00000000, qty: 0.30000000 }, AskBid { price: 5500.00000000, qty: 0.27272727 }, AskBid { price: 6000.00000000, qty: 0.25000000 }, AskBid { price: 6352.00000000, qty: 0.01500000 }, AskBid { price: 6500.00000000, qty: 0.15384615 }, AskBid { price: 7000.00000000, qty: 0.14285714 }, AskBid { price: 7500.00000000, qty: 0.13333333 }, AskBid { price: 8000.00000000, qty: 0.12500000 }, AskBid { price: 8500.00000000, qty: 0.11764705 }, AskBid { price: 9000.00000000, qty: 0.13283333 }, AskBid { price: 9250.00000000, qty: 0.02162162 }, AskBid { price: 9500.00000000, qty: 0.02105263 }, AskBid { price: 9803.92156863, qty: 0.00102000 }, AskBid { price: 9909.00000000, qty: 0.00999091 }, AskBid { price: 9940.00000000, qty: 0.00054325 }, AskBid { price: 10218.00000000, qty: 0.03266784 }, AskBid { price: 10225.20000000, qty: 0.03237100 }, AskBid { price: 10510.60000000, qty: 0.00189700 }, AskBid { price: 10542.50000000, qty: 0.00189100 }, AskBid { price: 10577.20000000, qty: 0.00188500 }, AskBid { price: 10636.60000000, qty: 0.00187500 }, AskBid { price: 10684.00000000, qty: 0.00186600 }, AskBid { price: 10722.20000000, qty: 0.00186000 }, AskBid { price: 10762.20000000, qty: 0.00185300 }, AskBid { price: 10800.00000000, qty: 0.04649082 }, AskBid { price: 10808.60000000, qty: 0.00070525 }, AskBid { price: 10833.00000000, qty: 0.23367488 }, AskBid { price: 10833.60000000, qty: 0.00184100 }, AskBid { price: 10866.90000000, qty: 0.00183500 }, AskBid { price: 10992.90000000, qty: 0.00181400 }, AskBid { price: 11036.80000000, qty: 0.00180700 }, AskBid { price: 11081.90000000, qty: 0.00179900 }, AskBid { price: 11119.00000000, qty: 0.00179300 }, AskBid { price: 11165.00000000, qty: 0.22673085 }, AskBid { price: 11170.00000000, qty: 0.01000000 }, AskBid { price: 11200.00000000, qty: 0.15000000 }, AskBid { price: 11240.00000000, qty: 0.01000000 }, AskBid { price: 11331.00000000, qty: 0.00510014 }, AskBid { price: 11400.00000000, qty: 0.20000000 }, AskBid { price: 11475.90000000, qty: 0.05300000 }, AskBid { price: 11492.40000000, qty: 0.05300000 }, AskBid { price: 11500.00000000, qty: 0.08695652 }, AskBid { price: 11578.40000000, qty: 0.05300000 }, AskBid { price: 11600.00000000, qty: 0.20000000 }, AskBid { price: 11625.00000000, qty: 22.02484301 }, AskBid { price: 11700.00000000, qty: 0.00670940 }, AskBid { price: 11800.00000000, qty: 0.20000000 }, AskBid { price: 11802.00000000, qty: 0.00500000 }, AskBid { price: 11851.00000000, qty: 0.04541599 }, AskBid { price: 12100.00000000, qty: 0.30000000 }, AskBid { price: 12165.10000000, qty: 0.01644000 }, AskBid { price: 12214.70000000, qty: 0.01000000 }, AskBid { price: 12300.00000000, qty: 0.30000000 }, AskBid { price: 12430.00000000, qty: 0.00288918 }, AskBid { price: 12498.40000000, qty: 0.00044805 }, AskBid { price: 12510.00000000, qty: 0.00399680 }, AskBid { price: 12692.20000000, qty: 0.00400003 }, AskBid { price: 12751.80000000, qty: 0.00800000 }, AskBid { price: 12798.10000000, qty: 0.01600000 }, AskBid { price: 12808.50000000, qty: 0.00800000 }, AskBid { price: 12828.00000000, qty: 0.01000000 }, AskBid { price: 12831.40000000, qty: 0.00092600 }, AskBid { price: 12837.60000000, qty: 0.00800000 }, AskBid { price: 12840.00000000, qty: 0.04027891 }, AskBid { price: 12851.00000000, qty: 0.00194537 }, AskBid { price: 12861.60000000, qty: 0.00800000 }, AskBid { price: 12875.30000000, qty: 0.00800000 }, AskBid { price: 12890.00000000, qty: 0.02674844 }, AskBid { price: 12891.80000000, qty: 0.00736399 }, AskBid { price: 12893.00000000, qty: 0.00739472 }, AskBid { price: 12899.80000000, qty: 0.00775200 }, AskBid { price: 12911.30000000, qty: 0.01400000 }, AskBid { price: 12919.80000000, qty: 0.01158000 }, AskBid { price: 12922.10000000, qty: 0.00092600 }, AskBid { price: 12925.70000000, qty: 0.04933386 }, AskBid { price: 12931.40000000, qty: 0.00600000 }, AskBid { price: 12931.60000000, qty: 0.00800000 }, AskBid { price: 12935.10000000, qty: 0.01543100 }, AskBid { price: 12936.00000000, qty: 0.00600000 }, AskBid { price: 12942.30000000, qty: 0.00772700 }, AskBid { price: 12942.40000000, qty: 0.04572600 }, AskBid { price: 12952.20000000, qty: 0.00800000 }, AskBid { price: 12953.40000000, qty: 0.00500000 }, AskBid { price: 12955.70000000, qty: 0.08221477 }, AskBid { price: 12959.70000000, qty: 0.00385800 }, AskBid { price: 12960.00000000, qty: 0.07716049 }, AskBid { price: 12960.20000000, qty: 0.00414200 }, AskBid { price: 12960.70000000, qty: 0.00800031 }, AskBid { price: 12960.90000000, qty: 0.03200494 }, AskBid { price: 12961.00000000, qty: 0.02314600 }, AskBid { price: 12961.10000000, qty: 0.00600000 }, AskBid { price: 12965.30000000, qty: 0.00667000 }, AskBid { price: 12972.70000000, qty: 0.00767800 }, AskBid { price: 12975.70000000, qty: 0.05471766 }, AskBid { price: 12978.00000000, qty: 0.00385223 }, AskBid { price: 12985.30000000, qty: 0.00600000 }, AskBid { price: 12985.70000000, qty: 0.03644971 }, AskBid { price: 12992.30000000, qty: 0.00769729 }, AskBid { price: 12992.80000000, qty: 0.03095500 }, AskBid { price: 12994.30000000, qty: 0.00384770 }, AskBid { price: 12994.80000000, qty: 0.00769570 }, AskBid { price: 12994.90000000, qty: 0.00500000 }, AskBid { price: 12995.10000000, qty: 0.05775500 }, AskBid { price: 12995.70000000, qty: 0.04856221 }, AskBid { price: 12998.80000000, qty: 0.00614200 }, AskBid { price: 12999.70000000, qty: 0.02731601 }, AskBid { price: 13000.50000000, qty: 0.00500000 }, AskBid { price: 13001.60000000, qty: 0.00384594 }, AskBid { price: 13001.90000000, qty: 0.00600000 }, AskBid { price: 13002.10000000, qty: 0.00871700 }, AskBid { price: 13005.50000000, qty: 0.03667000 }, AskBid { price: 13017.50000000, qty: 0.00500000 }, AskBid { price: 13021.00000000, qty: 0.04114384 }, AskBid { price: 13021.10000000, qty: 0.02312688 }, AskBid { price: 13021.70000000, qty: 0.48874498 }, AskBid { price: 13024.70000000, qty: 0.02567000 }, AskBid { price: 13025.50000000, qty: 2.50000000 }, AskBid { price: 13031.10000000, qty: 1.90000000 }, AskBid { price: 13035.70000000, qty: 0.03065400 }, AskBid { price: 13036.40000000, qty: 1.50000000 }, AskBid { price: 13040.40000000, qty: 1.00000000 }, AskBid { price: 13041.30000000, qty: 0.48874498 }, AskBid { price: 13045.60000000, qty: 0.85000000 }, AskBid { price: 13046.90000000, qty: 0.00153300 }, AskBid { price: 13047.20000000, qty: 0.00800000 }, AskBid { price: 13047.50000000, qty: 0.02299200 }, AskBid { price: 13048.10000000, qty: 0.03916600 }, AskBid { price: 13048.20000000, qty: 0.38938368 }, AskBid { price: 13048.90000000, qty: 0.00382000 }, AskBid { price: 13049.00000000, qty: 0.00153300 }, AskBid { price: 13049.20000000, qty: 0.02767000 }, AskBid { price: 13049.30000000, qty: 0.00092000 }, AskBid { price: 13050.90000000, qty: 0.70000000 }, AskBid { price: 13056.10000000, qty: 0.60000000 }, AskBid { price: 13061.00000000, qty: 2.44372491 }, AskBid { price: 13064.40000000, qty: 0.24380448 }, AskBid { price: 13071.10000000, qty: 0.00500000 }, AskBid { price: 13071.20000000, qty: 0.00800000 }, AskBid { price: 13075.10000000, qty: 0.00764000 }, AskBid { price: 13075.50000000, qty: 0.01400000 }, AskBid { price: 13081.70000000, qty: 0.00473700 }, AskBid { price: 13086.20000000, qty: 0.00091700 }, AskBid { price: 13086.80000000, qty: 0.00458475 }, AskBid { price: 13087.00000000, qty: 0.00343851 }, AskBid { price: 13087.30000000, qty: 0.00343842 }, AskBid { price: 13087.40000000, qty: 0.00191023 }, AskBid { price: 13087.60000000, qty: 0.00343836 }, AskBid { price: 13087.70000000, qty: 0.01143833 }, AskBid { price: 13087.80000000, qty: 0.00076407 }, AskBid { price: 13087.90000000, qty: 0.01107828 }, AskBid { price: 13088.00000000, qty: 0.00458432 }, AskBid { price: 13088.10000000, qty: 0.90205286 }], asks: [AskBid { price: 13088.20000000, qty: 0.32627102 }, AskBid { price: 13088.40000000, qty: 0.01981554 }, AskBid { price: 13088.70000000, qty: 0.01070815 }, AskBid { price: 13088.90000000, qty: 0.00955005 }, AskBid { price: 13089.00000000, qty: 0.00687600 }, AskBid { price: 13089.20000000, qty: 0.00687588 }, AskBid { price: 13089.40000000, qty: 0.01069578 }, AskBid { price: 13089.70000000, qty: 0.00687562 }, AskBid { price: 13090.10000000, qty: 0.00870941 }, AskBid { price: 13091.00000000, qty: 0.04074694 }, AskBid { price: 13094.60000000, qty: 0.01329500 }, AskBid { price: 13098.00000000, qty: 0.03817500 }, AskBid { price: 13098.70000000, qty: 0.10000000 }, AskBid { price: 13100.20000000, qty: 2.74400250 }, AskBid { price: 13101.00000000, qty: 0.13948490 }, AskBid { price: 13101.50000000, qty: 0.00766300 }, AskBid { price: 13102.40000000, qty: 0.00189425 }, AskBid { price: 13106.50000000, qty: 0.10000000 }, AskBid { price: 13109.10000000, qty: 0.32000000 }, AskBid { price: 13111.70000000, qty: 0.19000000 }, AskBid { price: 13113.30000000, qty: 0.01529700 }, AskBid { price: 13119.00000000, qty: 0.70000000 }, AskBid { price: 13119.30000000, qty: 0.02789698 }, AskBid { price: 13119.80000000, qty: 0.54880050 }, AskBid { price: 13120.80000000, qty: 0.01528100 }, AskBid { price: 13121.90000000, qty: 0.01257500 }, AskBid { price: 13122.20000000, qty: 0.00667000 }, AskBid { price: 13123.20000000, qty: 0.85000000 }, AskBid { price: 13126.80000000, qty: 0.02190600 }, AskBid { price: 13127.90000000, qty: 0.00190611 }, AskBid { price: 13129.40000000, qty: 1.00000000 }, AskBid { price: 13134.10000000, qty: 0.08928334 }, AskBid { price: 13134.60000000, qty: 1.50000000 }, AskBid { price: 13136.10000000, qty: 0.10376322 }, AskBid { price: 13136.30000000, qty: 0.00160000 }, AskBid { price: 13137.20000000, qty: 1.90000000 }, AskBid { price: 13137.30000000, qty: 0.00380600 }, AskBid { price: 13137.60000000, qty: 0.02789698 }, AskBid { price: 13139.40000000, qty: 0.54880050 }, AskBid { price: 13143.80000000, qty: 2.50000000 }, AskBid { price: 13155.60000000, qty: 0.01524800 }, AskBid { price: 13156.00000000, qty: 0.06974245 }, AskBid { price: 13156.70000000, qty: 0.00092100 }, AskBid { price: 13158.10000000, qty: 0.01142836 }, AskBid { price: 13159.10000000, qty: 0.00929500 }, AskBid { price: 13162.30000000, qty: 0.02283800 }, AskBid { price: 13165.60000000, qty: 0.03428200 }, AskBid { price: 13181.90000000, qty: 0.01140741 }, AskBid { price: 13191.50000000, qty: 0.00758000 }, AskBid { price: 13192.20000000, qty: 0.00454800 }, AskBid { price: 13197.50000000, qty: 0.00273600 }, AskBid { price: 13217.00000000, qty: 0.00227600 }, AskBid { price: 13221.70000000, qty: 0.00303200 }, AskBid { price: 13225.00000000, qty: 0.10000000 }, AskBid { price: 13225.70000000, qty: 0.03790300 }, AskBid { price: 13231.00000000, qty: 0.00075800 }, AskBid { price: 13244.60000000, qty: 0.00152454 }, AskBid { price: 13259.00000000, qty: 0.00378300 }, AskBid { price: 13275.00000000, qty: 0.10000000 }, AskBid { price: 13308.80000000, qty: 0.02302800 }, AskBid { price: 13317.20000000, qty: 0.00800000 }, AskBid { price: 13325.00000000, qty: 0.10000000 }, AskBid { price: 13326.10000000, qty: 0.00075300 }, AskBid { price: 13339.60000000, qty: 0.00367300 }, AskBid { price: 13339.70000000, qty: 0.00750400 }, AskBid { price: 13342.90000000, qty: 0.03840230 }, AskBid { price: 13344.40000000, qty: 0.01124500 }, AskBid { price: 13344.60000000, qty: 0.00100000 }, AskBid { price: 13357.20000000, qty: 0.00075100 }, AskBid { price: 13369.00000000, qty: 0.01127600 }, AskBid { price: 13369.50000000, qty: 0.00375073 }, AskBid { price: 13375.00000000, qty: 0.10000000 }, AskBid { price: 13399.90000000, qty: 0.01119700 }, AskBid { price: 13425.00000000, qty: 0.10000000 }, AskBid { price: 13475.00000000, qty: 0.10000000 }, AskBid { price: 13550.00000000, qty: 0.08363307 }, AskBid { price: 13725.00000000, qty: 0.20000000 }, AskBid { price: 13800.00000000, qty: 0.50019757 }, AskBid { price: 13975.00000000, qty: 0.20000000 }, AskBid { price: 13980.00000000, qty: 0.25287496 }, AskBid { price: 14285.00000000, qty: 0.10028151 }, AskBid { price: 14400.00000000, qty: 0.20000000 }, AskBid { price: 15000.00000000, qty: 0.20000000 }, AskBid { price: 15015.00000000, qty: 0.00732293 }, AskBid { price: 15600.00000000, qty: 0.11491900 }, AskBid { price: 15950.00000000, qty: 0.00128165 }, AskBid { price: 28544.00000000, qty: 0.00607460 }, AskBid { price: 29000.00000000, qty: 0.07427537 }, AskBid { price: 33329.00000000, qty: 0.02526099 }, AskBid { price: 45000.00000000, qty: 0.04424166 }, AskBid { price: 50000.00000000, qty: 0.03738358 }, AskBid { price: 87700.00000000, qty: 0.02000010 }, AskBid { price: 4989898.00000000, qty: 0.00103737 }, AskBid { price: 5464654.00000000, qty: 0.00030004 }, AskBid { price: 51346465.00000000, qty: 0.00090013 }, AskBid { price: 198989898.00000000, qty: 0.00020000 }] })
Err(NashProtocolError(ProtocolError("ErrorResponse { errors: [Error { message: \"Cannot query field \\\"aVolume24h\\\" on type \\\"Ticker\\\". Did you mean \\\"aVolume24h\\\", \\\"bVolume24h\\\", \\\"usdVolume24h\\\", or \\\"volume24h\\\"?\" }, Error { message: \"Cannot query field \\\"bVolume24h\\\" on type \\\"Ticker\\\". Did you mean \\\"aVolume24h\\\", \\\"bVolume24h\\\", \\\"usdVolume24h\\\", or \\\"volume24h\\\"?\" }, Error { message: \"Cannot query field \\\"highPrice24h\\\" on type \\\"Ticker\\\". Did you mean \\\"highPrice24h\\\", \\\"lowPrice24h\\\", \\\"priceChange24h\\\", \\\"priceChange24hPct\\\", or \\\"usdHighPrice24h\\\"?\" }, Error { message: \"Cannot query field \\\"lowPrice24h\\\" on type \\\"Ticker\\\". Did you mean \\\"highPrice24h\\\", \\\"lastPrice\\\", \\\"lowPrice24h\\\", or \\\"usdLowPrice24h\\\"?\" }, Error { message: \"Cannot query field \\\"priceChange24h\\\" on type \\\"Ticker\\\". Did you mean \\\"highPrice24h\\\", \\\"priceChange24h\\\", or \\\"priceChange24hPct\\\"?\" }, Error { message: \"Cannot query field \\\"volume24h\\\" on type \\\"Ticker\\\". Did you mean \\\"aVolume24h\\\", \\\"bVolume24h\\\", \\\"usdVolume24h\\\", or \\\"volume24h\\\"?\" }] }")))

Depends on crates, not github repos

From Cargo.toml:

nash-protocol  = { git = "https://github.com/nash-io/nash-rust"}
nash-native-client = { git = "https://github.com/nash-io/nash-rust"}

Because of that, I'm not able to build openLimits right now:

   Updating git repository `https://github.com/nash-io/nash-rust`
    Updating crates.io index
error: failed to select a version for `tungstenite`.
    ... required by package `tokio-tungstenite v0.11.0`
    ... which is depended on by `nash-native-client v0.1.1 (https://github.com/nash-io/nash-rust#5702be57)`
    ... which is depended on by `openlimits v0.1.0 (/home/aurel/Dev/Bazaar/Nash/openlimits)`
versions that meet the requirements `^0.11.1` are: 0.11.1

all possible versions conflict with previously selected packages.

  previously selected package `tungstenite v0.11.0`
    ... which is depended on by `openlimits v0.1.0 (/home/aurel/Dev/Bazaar/Nash/openlimits)`

failed to select a version for `tungstenite` which could resolve this conflict

Add a ``ping()`` call.

That returns the current server-time and possibly status (in case of (partial) downtimes).

Order history

Exchanges endpoints

OpenLimits

Function:

get_order_history

Data format: Array of the existing order structure.

Websockets trait

In order to start supporting websockets connections we should define what should be the basic traits

Remove mutability of self reference in getter methods of Exhange trait

"get" methods should not require mutable access to self. I know this was probably done to provide more flexibility to trait users, but this breaks the common principle of "get" being a reading operation, and requires trait users to ensure mutable access all the way through the code that uses Exchange.

#[async_trait]
pub trait Exchange {
    type OrderIdType;
    type TradeIdType;
    type PaginationType;
    async fn refresh_market_info(&mut self) -> Result<()>;
    async fn order_book(&mut self, req: &OrderBookRequest) -> Result<OrderBookResponse>;
    async fn limit_buy(&mut self, req: &OpenLimitOrderRequest) -> Result<Order<Self::OrderIdType>>;
    async fn limit_sell(&mut self, req: &OpenLimitOrderRequest)
        -> Result<Order<Self::OrderIdType>>;
    async fn market_buy(
        &mut self,
        req: &OpenMarketOrderRequest,
    ) -> Result<Order<Self::OrderIdType>>;
    async fn market_sell(
        &mut self,
        req: &OpenMarketOrderRequest,
    ) -> Result<Order<Self::OrderIdType>>;
    async fn cancel_order(
        &mut self,
        req: &CancelOrderRequest<Self::OrderIdType>,
    ) -> Result<OrderCanceled<Self::OrderIdType>>;
    async fn cancel_all_orders(
        &mut self,
        req: &CancelAllOrdersRequest,
    ) -> Result<Vec<OrderCanceled<Self::OrderIdType>>>;
    async fn get_all_open_orders(&mut self) -> Result<Vec<Order<Self::OrderIdType>>>;
    async fn get_order_history(
        &mut self,
        req: &GetOrderHistoryRequest<Self::PaginationType>,
    ) -> Result<Vec<Order<Self::OrderIdType>>>;
    async fn get_account_balances(
        &mut self,
        paginator: Option<&Paginator<Self::PaginationType>>,
    ) -> Result<Vec<Balance>>;
    async fn get_trade_history(
        &mut self,
        req: &TradeHistoryRequest<Self::OrderIdType, Self::PaginationType>,
    ) -> Result<Vec<Trade<Self::TradeIdType, Self::OrderIdType>>>;
    async fn get_price_ticker(&mut self, req: &GetPriceTickerRequest) -> Result<Ticker>;
    async fn get_historic_rates(
        &mut self,
        req: &GetHistoricRatesRequest<Self::PaginationType>,
    ) -> Result<Vec<Candle>>;
    async fn get_order(
        &mut self,
        req: &GetOrderRequest<Self::OrderIdType>,
    ) -> Result<Order<Self::OrderIdType>>;
}

WASM compatibility

If this crate was WASM compatible, it would be possible to serve WASM packages to web clients, running the crate locally. This could reduce overhead, as there was no server between client and exchange API.

Publish to crates.io

We need a script to publish openlimits to crates.io. Nash will want ownership of the account for crates.io and integrate it into the GitHub Actions CI pipeline.

Historic rates

Exchanges endpoints

OpenLimits

Function:

get_historic_rates

Data format:

{
  time:  u64,
  low: Decimal,
  high: Decimal,
  open: Decimal,
  clone: Decimal,
  volume: Decimal
}

Docker container environment for building and running tests locally

OpenLimits will begin to utilize a set of open source tooling for running its code coverage tests that does not come standard with the Rust cargo toolchain. Additionally, OpenLimits will eventually introduce various language bindings on top of it that will involve lots of various toolsets that will begin to become cumbersome to maintain by hand.

What we want is a build environment within a Docker container that can be executed on any contributor's machine, as easily as cloning the repository and running a set of make targets. Every machine has easy access to make and Docker as the two environmental dependencies.

Add trades history

  • Add trade history to the binance and coinbase SDK
  • Add the wrapper and data structures for a openlimits trade
  • Add get_trade_history trait to the Exchange traits

Binance: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#account-trade-list-user_data

Coinbase:
https://docs.pro.coinbase.com/#fills

Openlimits:

Example:

get_trades(pair_name)

Data structure:

    "time": u64,
    "trade_id":Depending on the exchange type,
    "price": Decimal,
    "size": Decimal,
    "side": Side Type

Are all dependencies really needed?

Hello there :)

I started looking at the code and something quickly caught my eye: there seem to be room for improvement in the dependencies.

Chrono

This is included in the coinbase sub-crate but never used in the code. I see it's used in binance sub-crate only to get the timestamp in milliseconds. This can be achieved also with the std library:

use std::time::SystemTime;

fn main() {
    let ts = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_millis();
    println!("{}", ts);
}

Reqwest: blocking

Using reqwest with the blocking feature will block the entire thread while waiting for the response from the server. This can kill the performance of the dependent project. I've experienced the complexity of using the async version of reqwest on earlier versions, but seems it's working much better in the latest version.

Tokio: full

This pulls all of tokio while only a few parts are needed in the compilable code, while the others can be moved to [dev-dependencies]

Dotenv

Love the crate, but this is only required for the tests, so why not have it [dev-dependencies]?

Ring

Can't find where it's used ๐Ÿ˜ข

I'd be more than happy to help on improving and building this library. I can do a PR with some of the proposed cleanups if you like.

Regards,
Marc

Paginators and date ranges

We need to support paginator and date ranges to openlimits to the current functions that are already implemented.

Paginators

Binance

Param Description
fromId integer id
limit limit

Coinbase

Parameter Default Description
before ย  Request page before (newer) this pagination id.
after ย  Request page after (older) this pagination id.
limit 100 Number of results per request. Maximum 100. (default 100)

Date Ranges

Binance

Param Description
startTime Start time in ms
endTime End time in ms

Coinbase

Param Description
start Start time in ISO 8601
end End time in ISO 8601

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.