Skip to main content

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.

Release files for bitmex-supervisor 0.7.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for bitmex-supervisor 0.7.4
File Interpreter ABI Platform
bitmex_supervisor-0.7.4-py2.py3-none-any.whl Python 2, Python 3 none any Details

Release files / bitmex_supervisor-0.7.4-py2.py3-none-any.whl

Download URL bitmex_supervisor-0.7.4-py2.py3-none-any.whl
Size 29.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
a5ab69fa7760187c2ec518cfb865dd637ed288ebeae30267c1308d12ad1f78ad
BLAKE2b-256 checksum
How to use checksums
03b531f71a2d511b91ceb2d21d3d9be252205e8e934dec2d12adfad100ca8f11
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.7.4 This release

1 release file

0.7.3

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.3

2 release files

0.4.1

1 release file

0.4

2 release files

0.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page