Giter Site home page Giter Site logo

forkcs / bitmex-supervisor Goto Github PK

View Code? Open in Web Editor NEW
15.0 4.0 6.0 122 KB

Automated monitoring of orders/positions on your BitMEX account.

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%
bitmex bitmex-api bitmex-python trading trading-algorithms trading-systems trading-bot bitmexbot cryptocurrency cryptocurrency-exchanges

bitmex-supervisor's Introduction

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.

Python 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.

bitmex-supervisor's People

Contributors

dependabot[bot] avatar forkcs avatar woowgers avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

bitmex-supervisor's Issues

test filed

--------------------------------------------------------------------- Captured log call ---------------------------------------------------------------------
INFO supervisor:_supervisor.py:267 Supervisor cycle has been continued.
INFO supervisor:_supervisor.py:278 Exited from Supervisor.
================================================================== short test summary info ==================================================================
FAILED tests/integration/test_supervisor.py::SupervisorEntryTests::test_fb_last_position_enter_while_running_cycle - TypeError: 'Mock' object is not subsc...
FAILED tests/unit/test_supervisor.py::SupervisorEntryTests::test_fb_entry_last_price - TypeError: 'Mock' object is not subscriptable
FAILED tests/unit/test_supervisor.py::SupervisorEntryTests::test_fb_entry_last_price_timedout - TypeError: 'Mock' object is not subscriptable
=============================================================== 3 failed, 74 passed in 18.67s ===============================================================

Requirements.txt is excees.

Problem:
File requirements.txt may contain unnecessary dependencies. So it`s good anyway to clean them.

Note, that websocket-client must be exact in 0.56.0 version, it`s essential.

Missing file

Hi,

Thank u so much for your hard work.
Like to test but i am missing setup.py?

Thanks
Patrick

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.