Package: bitmex-supervisor
BitMEX SupervisorThis is a library-like application, which operates with orders and positions on your account.Current version:0.7.4Features: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 levelsIn develop:Enter position with rebate by tracking last market price and moving limit order up.Getting StartedThese instructions will get you a copy of the project up and running on your local machine for development and testing purposes.PrerequisitesFor now we support only the version of Python that we use in development.Pyhton 3.8 +InstallingManual install from repoClone 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/activateInstall project requirements:pip install -r requirements.txtInstall with pippipinstallbitmex-supervisorInstall from sourcesComing soon...Running the testsThere 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 responsesRun tests:pytestIf all the tests are passed, you may proceed to the next steps.After successful installation:Now you can import supervisor module from project dir:importsupervisorFor more details see example.py.ContributingPlease readCONTRIBUTING.mdfor details on our code of conduct, and the process for submitting pull requests to us.UsageCreate Exchange instance:fromsupervisor.core.interfaceimportExchangeexchange=Exchange(symbol='XBTUSD',api_key='YOUR_API_KEY',api_secret='YOUR_API_SECRET',test=True)# test=True for use TestnetCreate Supervisor instance:fromsupervisorimportSupervisorsupervisor=Supervisor(interface=exchange)Set necessary position size, Supervisor will fix it:supervisor.position=150If Supervisor is already running, you can use one of provided entry methodssupervisor.stop_cycle()supervisor.enter_by_market_order(150)supervisor.run_cycle()Create order:fromsupervisor.core.ordersimportOrdermy_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 eventdefcallback(*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:CallableOrder._on_reject:CallableRun Supervisor cycle (works in own thread):supervisor.run_cycle()You can stop, continue and exit Supervisor cycle:supervisor.stop_cycle()# do stuffsupervisor.run_cycle()# this method can both run and continue cyclesupervisor.exit_cycle()# this method terminates cycle`s thread and quit correctlyVersioningWe useSemVerfor versioning. For the versions available, see thetags on this repository.AuthorsFedor Soldatkin-Initial work-forkcsLicenseThis project is licensed under the MIT License - see theLICENSE.mdfile for details.