Skip to content

Commit 7c7c664

Browse files
feat: integrate cancel_all_by_kind_or_type endpoint (#42)
* feat: integrate cancel_all_by_kind_or_type endpoint * Update deribit_wrapper/trading.py Co-authored-by: Copilot <[email protected]> * Update deribit_wrapper/trading.py Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 7023993 commit 7c7c664

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

deribit_wrapper/trading.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Trading(AccountManagement):
1616
__GET_OPEN_ORDERS = '/private/get_open_orders'
1717
__BUY = '/private/buy'
1818
__SELL = '/private/sell'
19-
__CLOSE_ALL_BY_KIND_OR_TYPE = '/private/cancel_all_by_kind_or_type'
19+
__CANCEL_ALL_BY_KIND_OR_TYPE = '/private/cancel_all_by_kind_or_type'
2020
__CANCEL_BY_LABEL = '/private/cancel_by_label'
2121
__CLOSE_POSITION = '/private/close_position'
2222
__GET_MARGINS = '/private/get_margins'
@@ -211,10 +211,7 @@ def close_position(self, asset: str, limit: float | int = None) -> dict:
211211
ret = self._request(uri, params)
212212
return ret
213213

214-
def cancel_orders(self, currency: str | list[str] = None, label: str = None) -> dict:
215-
# Expand the function to cancel all orders by kind or type
216-
if label is None:
217-
raise ValueError("The 'label' parameter is required to cancel orders.")
214+
def _cancel_by_label(self, label: str, currency: str | list[str] = None) -> dict:
218215
uri = self.__CANCEL_BY_LABEL
219216
params = {
220217
'label': label,
@@ -228,3 +225,25 @@ def cancel_orders(self, currency: str | list[str] = None, label: str = None) ->
228225
params['currency'] = c
229226
r[c] = self._request(uri, params)
230227
return r
228+
229+
def cancel_orders(self, currency: str | list[str] = None, kind: str = None,
230+
order_type: str = None, label: str = None) -> dict:
231+
if label is not None:
232+
return self._cancel_by_label(label, currency)
233+
uri = self.__CANCEL_ALL_BY_KIND_OR_TYPE
234+
params = {
235+
'currency': '',
236+
}
237+
if kind is not None:
238+
params['kind'] = kind
239+
if order_type is not None:
240+
params['type'] = order_type
241+
if currency is None:
242+
currency = self.currencies
243+
elif not isinstance(currency, list):
244+
currency = [currency]
245+
r = {}
246+
for c in currency:
247+
params['currency'] = c
248+
r[c] = self._request(uri, params)
249+
return r

0 commit comments

Comments
 (0)