From 4d8148b7827764fc5d3b1b8f96b0248629abc481 Mon Sep 17 00:00:00 2001 From: Fedor Soldatkin Date: Fri, 8 May 2020 11:11:04 +0300 Subject: [PATCH] Add position-related features. Change __version__ to '0.4'. Update README.md. Update example.py. --- README.md | 15 ++++++++++----- example.py | 6 ++++++ supervisor/__init__.py | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4f1ebef..170a732 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,17 @@ This is a library-like application, which operates with orders and positions on your account. -*Current version:* **0.3** +*Current version:* **0.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. #### In develop: -* Manage positions on your account. - * Maintaining position size. - * Various market-price or limit entries in position. - * Enter position with rebate by tracking last market price and moving limit order up. +* Various market-price or limit entries in position. +* Enter position with rebate by tracking last market price and moving limit order up. ## Getting Started @@ -112,6 +111,12 @@ from supervisor import Supervisor supervisor = Supervisor(interface=exchange) ``` +Set necessary position size, Supervisor will fix it: + +```python +supervisor.position = 150 +``` + Create order: ```python diff --git a/example.py b/example.py index 3a91869..b48e75b 100644 --- a/example.py +++ b/example.py @@ -8,14 +8,20 @@ TEST_API_SECRET = 'your-api-secret' if __name__ == '__main__': + # Exchange is a interface-like class to call api methods exchange = Exchange(api_key=TEST_API_KEY, api_secret=TEST_API_SECRET, test=True, symbol='XBTUSD') supervisor = Supervisor(interface=exchange) + # create Order objects stop_loss = Order(order_type='Stop', stop_px=Decimal(2000), qty=10, side='Sell') tp1 = Order(order_type='Limit', price=Decimal(15000), qty=6, side='Sell', passive=True, reduce_only=True) tp2 = Order(order_type='Limit', price=Decimal(20000), qty=4, side='Sell', hidden=True) + # set needed position price + supervisor.position_size = 10 + + # attach some callbacks to stop-loss, note that events starts with "_" stop_loss._on_reject = lambda: print('Rejected') stop_loss._on_fill = lambda: print('We lost position(') stop_loss._on_cancel = lambda: print('Trading without stops is risking ;)') diff --git a/supervisor/__init__.py b/supervisor/__init__.py index 5058611..72a6251 100644 --- a/supervisor/__init__.py +++ b/supervisor/__init__.py @@ -1,3 +1,3 @@ from supervisor._supervisor import * -__version__ = '0.3' +__version__ = '0.4'