|
8 | 8 |
|
9 | 9 | from typing import List, Optional, Tuple, Union |
10 | 10 |
|
11 | | -from ...base_api import KrakenBaseFuturesAPI |
| 11 | +from ...base_api import KrakenBaseFuturesAPI, defined |
12 | 12 |
|
13 | 13 |
|
14 | 14 | class Trade(KrakenBaseFuturesAPI): |
@@ -46,10 +46,10 @@ class Trade(KrakenBaseFuturesAPI): |
46 | 46 |
|
47 | 47 | def __init__( |
48 | 48 | self: "Trade", |
49 | | - key: Optional[str] = "", |
50 | | - secret: Optional[str] = "", |
51 | | - url: Optional[str] = "", |
52 | | - sandbox: Optional[bool] = False, |
| 49 | + key: str = "", |
| 50 | + secret: str = "", |
| 51 | + url: str = "", |
| 52 | + sandbox: bool = False, |
53 | 53 | ) -> None: |
54 | 54 | super().__init__(key=key, secret=secret, url=url, sandbox=sandbox) |
55 | 55 |
|
@@ -93,7 +93,7 @@ def get_fills(self: "Trade", lastFillTime: Optional[str] = None) -> dict: |
93 | 93 | } |
94 | 94 | """ |
95 | 95 | query_params: dict = {} |
96 | | - if lastFillTime: |
| 96 | + if defined(lastFillTime): |
97 | 97 | query_params["lastFillTime"] = lastFillTime |
98 | 98 | return self._request( # type: ignore[return-value] |
99 | 99 | method="GET", |
@@ -248,7 +248,7 @@ def cancel_all_orders(self: "Trade", symbol: Optional[str] = None) -> dict: |
248 | 248 | } |
249 | 249 | """ |
250 | 250 | params: dict = {} |
251 | | - if symbol is not None: |
| 251 | + if defined(symbol): |
252 | 252 | params["symbol"] = symbol |
253 | 253 | return self._request( # type: ignore[return-value] |
254 | 254 | method="POST", |
@@ -331,9 +331,9 @@ def cancel_order( |
331 | 331 | """ |
332 | 332 |
|
333 | 333 | params: dict = {} |
334 | | - if order_id is not None: |
| 334 | + if defined(order_id): |
335 | 335 | params["order_id"] = order_id |
336 | | - elif cliOrdId is not None: |
| 336 | + elif defined(cliOrdId): |
337 | 337 | params["cliOrdId"] = cliOrdId |
338 | 338 | else: |
339 | 339 | raise ValueError("Either order_id or cliOrdId must be set!") |
@@ -394,18 +394,18 @@ def edit_order( |
394 | 394 | } |
395 | 395 | """ |
396 | 396 | params: dict = {} |
397 | | - if orderId is not None: |
| 397 | + if defined(orderId): |
398 | 398 | params["orderId"] = orderId |
399 | | - elif cliOrdId is not None: |
| 399 | + elif defined(cliOrdId): |
400 | 400 | params["cliOrdId"] = cliOrdId |
401 | 401 | else: |
402 | 402 | raise ValueError("Either orderId or cliOrdId must be set!") |
403 | 403 |
|
404 | | - if limitPrice is not None: |
| 404 | + if defined(limitPrice): |
405 | 405 | params["limitPrice"] = limitPrice |
406 | | - if size is not None: |
| 406 | + if defined(size): |
407 | 407 | params["size"] = size |
408 | | - if stopPrice is not None: |
| 408 | + if defined(stopPrice): |
409 | 409 | params["stopPrice"] = stopPrice |
410 | 410 |
|
411 | 411 | return self._request( # type: ignore[return-value] |
@@ -448,9 +448,9 @@ def get_orders_status( |
448 | 448 | {'result': 'success', 'serverTime': '2023-04-04T17:27:29.667Z', 'orders': []} |
449 | 449 | """ |
450 | 450 | params = {} |
451 | | - if orderIds is not None: |
| 451 | + if defined(orderIds): |
452 | 452 | params["orderIds"] = orderIds |
453 | | - elif cliOrdIds is not None: |
| 453 | + elif defined(cliOrdIds): |
454 | 454 | params["cliOrdIds"] = cliOrdIds |
455 | 455 |
|
456 | 456 | return self._request( # type: ignore[return-value] |
@@ -647,22 +647,22 @@ def create_order( |
647 | 647 | "size": size, |
648 | 648 | "symbol": symbol, |
649 | 649 | } |
650 | | - if cliOrdId is not None: |
| 650 | + if defined(cliOrdId): |
651 | 651 | params["cliOrdId"] = cliOrdId |
652 | | - if limitPrice is not None: |
| 652 | + if defined(limitPrice): |
653 | 653 | params["limitPrice"] = limitPrice |
654 | | - if reduceOnly is not None: |
| 654 | + if defined(reduceOnly): |
655 | 655 | params["reduceOnly"] = reduceOnly |
656 | | - if stopPrice is not None: |
| 656 | + if defined(stopPrice): |
657 | 657 | params["stopPrice"] = stopPrice |
658 | | - if triggerSignal is not None: |
659 | | - trigger_signals = ("mark", "spot", "last") |
| 658 | + if defined(triggerSignal): |
| 659 | + trigger_signals: tuple = ("mark", "spot", "last") |
660 | 660 | if triggerSignal not in trigger_signals: |
661 | 661 | raise ValueError(f"Trigger signal must be in [{trigger_signals}]!") |
662 | 662 | params["triggerSignal"] = triggerSignal |
663 | | - if trailingStopDeviationUnit is not None: |
| 663 | + if defined(trailingStopDeviationUnit): |
664 | 664 | params["trailingStopDeviationUnit"] = trailingStopDeviationUnit |
665 | | - if trailingStopMaxDeviation is not None: |
| 665 | + if defined(trailingStopMaxDeviation): |
666 | 666 | params["trailingStopMaxDeviation"] = trailingStopMaxDeviation |
667 | 667 |
|
668 | 668 | return self._request( # type: ignore[return-value] |
|
0 commit comments