Leveraged Futures Exchange for Simulated Trading (LFEST)
:warning: This is a personal project, use a your own risk.
:warning: The results may not represent real trading results on any given exchange.
lfest-rs is a blazingly fast simulated exchange capable of leveraged positions. It gets fed external data either as a trade or a candle to update the internal state and check for order execution. For simplicity's sake (and performance) the exchange does not use an order book It also cross-leverages positions so the whole margin balance is used as collateral.
Order Types
The supported order types are:
- market - aggressively execute against the best bid / ask
- limit - passively place an order into the orderbook
- stop_market - A protective but aggressive market order which is triggered at a specific price
Currently limit and stop_market orders may not work as expected. I advise you to only use market orders or fix limit and stop_order margin calculation and create a pull request.
Performance Metrics:
The following performance metrics are available through AccTracker struct:
- win_ratio
- profit_loss_ratio
- total_rpnl
- sharpe
- sharpe_daily_returns
- sortino
- cumulative fees
- sharpe_sterling_ratio
- max_drawdown
- max_upnl_drawdown
- num_trades
- turnover
- trade_percentage
- buy_ratio
- limit_order_fill_ratio
- limit_order_cancellation_ratio
Some of these metric may behave differently from what you would expect, so make sure to take a look at the code.
How to use
To use this crate in your project, add the following to your Cargo.toml:
[dependencies]
lfest = "^0.7.0"
Then proceed to use it in your code.
Here is a basic example:
//! Example usage of Exchange using external trade data.
//! A randomly acting agent places market buy / sell orders every 100 candles
extern crate log;
use ;
use load_prices_from_csv;
use ;
use Instant;
/// analyze the resulting performance metrics of the traded orders
TODOs:
- proper order margin mechanism
- proper liquidations
- add order filter configuration such as min_qty and qty_precision
- add max_num_limit_orders to config
- add max_num_stop_orders to config
- impl Display for Side and FuturesType
Contributions
If you find a bug or would like to help out, feel free to create a pull-request.
Donations :moneybag: :money_with_wings:
I you would like to support the development of this crate, feel free to send over a donation:
Monero (XMR) address:
47xMvxNKsCKMt2owkDuN1Bci2KMiqGrAFCQFSLijWLs49ua67222Wu3LZryyopDVPYgYmAnYkSZSz9ZW2buaDwdyKTWGwwb
License
Copyright (C) 2020 <Mathis Wellmann wellmannmathis@gmail.com>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.