afp-sdk 0.1.2__py3-none-any.whl → 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
afp/api/trading.py CHANGED
@@ -54,6 +54,7 @@ class Trading(ExchangeAPI):
54
54
  max_trading_fee_rate: Decimal,
55
55
  good_until_time: datetime,
56
56
  margin_account_id: str | None = None,
57
+ rounding: str | None = None,
57
58
  ) -> Intent:
58
59
  """Creates an intent with the given intent data, generates its hash and signs it
59
60
  with the configured account's private key.
@@ -62,6 +63,13 @@ class Trading(ExchangeAPI):
62
63
  is assumed to be the same as the margin account if the margin account ID is not
63
64
  specified.
64
65
 
66
+ The limit price must have at most as many fractional digits as the product's
67
+ tick size, or if `rounding` is specified then the limit price is rounded to the
68
+ appropriate number of fractional digits. `rounding` may be one of
69
+ `ROUND_CEILING`, `ROUND_FLOOR`, `ROUND_UP`, `ROUND_DOWN`, `ROUND_HALF_UP`,
70
+ `ROUND_HALF_DOWN`, `ROUND_HALF_EVEN` and `ROUND_05UP`; see the rounding modes of
71
+ the `decimal` module of the Python Standard Library.
72
+
65
73
  Parameters
66
74
  ----------
67
75
  product : afp.schemas.ExchangeProduct
@@ -71,6 +79,8 @@ class Trading(ExchangeAPI):
71
79
  max_trading_fee_rate : decimal.Decimal
72
80
  good_until_time : datetime.datetime
73
81
  margin_account_id : str, optional
82
+ rounding : str, optional
83
+ A rounding mode of the `decimal` module or `None` for no rounding.
74
84
 
75
85
  Returns
76
86
  -------
@@ -85,7 +95,9 @@ class Trading(ExchangeAPI):
85
95
  intent_data = IntentData(
86
96
  trading_protocol_id=self._trading_protocol_id,
87
97
  product_id=product.id,
88
- limit_price=limit_price,
98
+ limit_price=validators.validate_limit_price(
99
+ Decimal(limit_price), product.tick_size, rounding
100
+ ),
89
101
  quantity=quantity,
90
102
  max_trading_fee_rate=max_trading_fee_rate,
91
103
  side=getattr(OrderSide, side.upper()),