Automated monitoring of orders/positions on your BitMEX account.
Project description
BitMEX Supervisor
This is a library-like application, which operates with orders and positions on your account.
Current version: 0.7.4
Features:
- Creating an cancelling orders on your account. Stop-loss, Limit, passive, reduce-only, close-only, hidden orders supported.
- Preventing these orders for being lost, cancelled or rejected: Supervisor will place them anew.
- Supervisor closes all orders, which are not supervised.
- When the supervised order has been filled, Supervisor will not try to place it.
- Put callbacks on supervised orders, which are called when order has been filled, partially executed or cancelled.
- Set and maintain the position size.
- Various market-price or limit entries in position.
- Place Trailing-stop levels
In develop:
- Enter position with rebate by tracking last market price and moving limit order up.
Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Prerequisites
For now we support only the version of Python that we use in development.
Pyhton 3.8 +
Installing
Manual install from repo
Clone and go to directory:
git clone https://github.com/forkcs/bitmex-supervisor.git
cd bitmex-supervisor/
Then create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate
Install project requirements:
pip install -r requirements.txt
Install with pip
pip install bitmex-supervisor
Install from sources
Coming soon...
Running the tests
There are automated tests for this project. Running the tests is optional. For run tests you need to install py.test and responses packages.
Install with pip:
pip install pytest responses
Run tests:
pytest
If all the tests are passed, you may proceed to the next steps.
After successful installation:
Now you can import supervisor module from project dir:
import supervisor
For more details see example.py.
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Usage
Create Exchange instance:
from supervisor.core.interface import Exchange
exchange = Exchange(symbol='XBTUSD',
api_key='YOUR_API_KEY',
api_secret='YOUR_API_SECRET',
test=True) # test=True for use Testnet
Create Supervisor instance:
from supervisor import Supervisor
supervisor = Supervisor(interface=exchange)
Set necessary position size, Supervisor will fix it:
supervisor.position = 150
If Supervisor is already running, you can use one of provided entry methods
supervisor.stop_cycle()
supervisor.enter_by_market_order(150)
supervisor.run_cycle()
Create order:
from supervisor.core.orders import Order
my_order = Order(order_type='Limit', qty=100, side='Buy', price=6500, hidden=True, passive=True)
supervisor.add_order(my_order)
You can attach any callback to order events.
Callback must retrieve *args and **kwargs attributes.
order_with_callback = Order(order_type='Limit', qty=100, side='Buy', price=6500)
# for example, let's attach callback to order fill event
def callback(*args, **kwargs):
print('Order has been filled!!!')
order._on_fill = callback
# Run cycle and when your order filled, the message will be printed.
There are 2 possible events provided:
Order._on_fill: Callable
Order._on_reject: Callable
Run Supervisor cycle (works in own thread):
supervisor.run_cycle()
You can stop, continue and exit Supervisor cycle:
supervisor.stop_cycle()
# do stuff
supervisor.run_cycle() # this method can both run and continue cycle
supervisor.exit_cycle() # this method terminates cycle`s thread and quit correctly
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Fedor Soldatkin - Initial work - forkcs
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
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 Distributions
Built Distribution
File details
Details for the file bitmex_supervisor-0.7.4-py2.py3-none-any.whl
.
File metadata
- Download URL: bitmex_supervisor-0.7.4-py2.py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5ab69fa7760187c2ec518cfb865dd637ed288ebeae30267c1308d12ad1f78ad |
|
MD5 | 749916c518af79c4d6a35b23eb7a795d |
|
BLAKE2b-256 | 03b531f71a2d511b91ceb2d21d3d9be252205e8e934dec2d12adfad100ca8f11 |