Bancor python carbon and carbon library.
Project description
Carbon Simulator
Warning
The simulator is a work in progress with potentially broken features, unfinished sections, and a non-exhaustive overview of commands and example usage. Moreover, the entirety of the codebase and documentation is subject to change without warning. Having said this -- we will make an effort to keep the interface backwards compatible so that existing code will not break.
About Carbon
Carbon is decentralized exchange infrastructure that gives users the ability to create automated flexible trading strategies on-chain. Its key technical features are adjustable parametric bonding curves, asymmetric concentrated liquidity, and an efficient routing algorithm.
This simulator has been developed by Bancor Research to assist in the design, testing, and validation of Carbon strategies. It can be run interactively in a Jupyter notebook environment, or via Python scripting.
The permament URL for this repo is github.com/bancorprotocol/carbon-simulator. The Carbon project website is at carbondefi.xyz. On this site you will find in particular the Litepaper and the patent application.
Getting started
If you already have Python and Jupyter installed, you can launch a Jupyter instance in the root directory of the project and run the notebook CarbonSim-Example.ipynb
, or any of the other notebooks in that directory.
You may run into missing modules that need to be installed via pip. In this case, either install them manually based on the list in the requirements.txt
or refer to the instructions below.
Project setup
The project should be able to run in any Python3 environment with the correct dependencies installed via pip. If you start from a Conda installation, most dependencies should already be available. Nevertheless we recommend setting up a virtual environment to ensure libraries installed for this project do not collide with other Python modules installed on the system.
Whilst this simulation is designed to run in any Python environment, we strongly recommend running it in Jupyter Notebooks for the convenience they provide.
Method 1. Quick setup
Navigate to the top level project directory and start the Jupyter server:
$ jupyter notebook
Then run the notebook CarbonSim-Example.ipynb
or any of the other notebooks. If you are getting import errors, make sure all modules from requirements.txt
are installed, eg by running
$ pip install -r requirements.txt
or by installing the required modules manually.
The upside of this method is that you get started quickly and easily. The downside is that the carbon
library may only work for notebooks and scripts located in the root directory of this project.
Method 2. Installation
This method will install the carbon
package as well as all its dependencies on your system. We highly recommend to do this in a virtual environment, in which case no permanent changes will be made. To install the simulator, navigate to the top level project directory, and run the installation process via
$ python setup.py install
Then again you launch a Jupyter session running the following command
$ jupyter notebook
As the carbon
library is now installed on your system, you can run the simulation code from anywhere whilst the virtual environment is active.
Usage
There are numerous usage examples in the Jupyter notebooks in the root directory of this project, and we refer to those for more elaborate examples. A very basic example for a simulation is the one from CarbonSim-Example.ipynb
:
from carbon import CarbonSimulatorUI
# Set up a simulator instance, with default pair ETHUSDC
Sim = CarbonSimulatorUI(pair="ETHUSDC")
# Add a strategy. This strategy is initially seeded with 10 ETH
# and 10000 USDC. It will selling ETH between 2000-2500 USDC per ETH,
# making the received USDC available for sale. It will also be buying ETH
# between 1000-750 USDC per ETH.
Sim.add_strategy("ETH", 10, 2000, 2500, 10000, 1000, 750)
# We can look at this order by examining the simulator state
Sim.state()["orders"]
# Someone is now trading against the pool, BUYING 1 ETH.
# The price will be driven by the 2000-2500 range.
Sim.trader_buys("ETH", 1)
# We see that that 1 ETH disappeared from the ETH curve,
# and reappeared as USDC on the other curve
Sim.state()["orders"]
# Someone is trading against the pool, SELLING 1 ETH.
# The price will be driven by the 1000-750 range
Sim.trader_sells("ETH", 1)
# Now the ETH curve is at 10 ETH, where it was initially.
# We have however taken profits of about USD 2021 on the
# USDC account.
Sim.state()["orders"]
Branches and versioning
Branches
This repo contains two key branches, main
, and beta
. Their respective properties are as follows:
-
main
. The main branch is the main release branch of this project. It may not contain all bleeding edge features, but it has been tested thoroughly (but see the disclaimer on top). The main branch will never be rewritten. -
beta
. The beta branch is the branch to go for if you are interested in the latest features of the project. It will have usually passed the test suite, so should not be broken in obvious ways. The beta branch may be rewritten from time to time.
Versioning
We attempt to use semantic versioning (major.minor.patch
), so the major number is changed on backward incompatible API changes, the minor number on compatible changes, and the patch number for minor patches.
The API in this respect is defined as "all public methods in the SimulationUI
" object, as well as those in the objects it returns (currently CarbonPair
and CarbonOrderUI
).
The in-library location of those objects is not part of the API, they need to be imported from the top level. There may be additional objects in the top-level of the library that are not currently considered part of the API. As of version 1.0, those objects are ExactRouterX0Y0N
and analytics
which we do not currently consider in a state suitable for semantic versioning.
Modules may have version numbers of their own. Those are mostly for use of the dev team and they do not follow any specific policies.
Change log
- v1.1 - more advanced analytics, order books
- v1.0 - initial release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file carbon-simulator-1.2.tar.gz
.
File metadata
- Download URL: carbon-simulator-1.2.tar.gz
- Upload date:
- Size: 35.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.2 keyring/21.8.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 607e33a844274def6707c4b8dfdce8cfe92f216b55144de6d0e6fda0b0f39b30 |
|
MD5 | c13d709bce71187cf03cb5c83fd5e624 |
|
BLAKE2b-256 | f3c9448b8e0ab2355b1c515f4da5c5948eb61b3c50027f2624c8369b8c1eaf3a |
File details
Details for the file carbon_simulator-1.2-py3.8.egg
.
File metadata
- Download URL: carbon_simulator-1.2-py3.8.egg
- Upload date:
- Size: 88.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.2 keyring/21.8.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f88b604e143081544097584a92f0e47ad41ba1f6f9c787215f410b423fe1e783 |
|
MD5 | 1e157b2966f56ea5ff71845c5a2d4df0 |
|
BLAKE2b-256 | 3370c007bd8201412bd9b27e458f7e5c4b56f17e48137fbee8983883692ead6a |
File details
Details for the file carbon_simulator-1.2-py3-none-any.whl
.
File metadata
- Download URL: carbon_simulator-1.2-py3-none-any.whl
- Upload date:
- Size: 40.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.2 keyring/21.8.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73641e2e543c6d68a99ff9ad0e74910a1537b4db4378bb3dc58cb6f564be8f47 |
|
MD5 | ca2411ceeb4024b599cd99ec3896e351 |
|
BLAKE2b-256 | 144e16a1d08c785a3182472652f008c58d2fcf90a4944641f9aa2332447766a7 |