Helpers & Utilities Reference
Helper classes and functions for payload construction and fee calculation.
helpers
FeeCalculator
Calculator for order fees on Revolut X.
calculate
classmethod
calculate(side: OrderSide, price: Any, is_maker: bool, *, base_size: Any | None = None, quote_size: Any | None = None) -> FeeEstimate
Calculates exact fees for a specified trade.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
side
|
OrderSide
|
BUY or SELL. |
required |
price
|
Any
|
The execution price in quote currency per 1 base currency unit. |
required |
is_maker
|
bool
|
True if the order is executed as a maker (0.00% fee), False for taker (0.09% fee). |
required |
base_size
|
Any | None
|
The amount of the base currency (e.g., BTC) if provided. |
None
|
quote_size
|
Any | None
|
The amount of the quote currency (e.g., EUR) if provided. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
FeeEstimate |
FeeEstimate
|
An object containing detailed fee estimates. |
Raises:
| Type | Description |
|---|---|
OrderValidationError
|
If neither base_size nor quote_size is provided. |
Example
FeeCalculator.calculate(OrderSide.BUY, '90000', is_maker=False, quote_size='1000')
Source code in src/revolut_x/helpers.py
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
FeeEstimate
dataclass
FeeEstimate(side: str, order_type: str, is_maker: bool, fee_rate_percent: Decimal, trade_value_eur: Decimal, estimated_base_qty: Decimal, price: Decimal, fee_amount: Decimal, fee_currency: str, net_received: Decimal, net_received_currency: str, explanation: str)
Estimated fee calculation result for an order.
OrderPayloadBuilder
Builder and validator for Revolut X API order payloads.
build_limit_order
classmethod
build_limit_order(symbol: str, side: OrderSide, price: Any, *, base_size: Any | None = None, quote_size: Any | None = None, post_only: bool = False, time_in_force: TimeInForce | str = TimeInForce.GTC, client_order_id: str | None = None) -> dict[str, Any]
Builds a payload for a Limit Order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The trading symbol (e.g., 'BTC-EUR'). |
required |
side
|
OrderSide
|
The side of the order (BUY or SELL). |
required |
price
|
Any
|
The limit price in quote currency per 1 base currency unit. |
required |
base_size
|
Any | None
|
The amount of the base currency (e.g., BTC) to buy/sell. |
None
|
quote_size
|
Any | None
|
The amount of the quote currency (e.g., EUR) to buy/sell. |
None
|
post_only
|
bool
|
If True, ensures the order is entered as a MAKER order. |
False
|
time_in_force
|
TimeInForce | str
|
The time in force for the order (e.g., 'gtc' or 'ioc'). |
GTC
|
client_order_id
|
str | None
|
A unique client order ID. A UUID will be generated if not provided. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: The constructed JSON payload for the Revolut X API. |
Raises:
| Type | Description |
|---|---|
OrderValidationError
|
If exactly one of base_size or quote_size is not provided. |
Example
OrderPayloadBuilder.build_limit_order('BTC-EUR', OrderSide.SELL, '90000.00', base_size='0.1')
Source code in src/revolut_x/helpers.py
build_maker_order
classmethod
build_maker_order(symbol: str, side: OrderSide | str, price: Any, *, base_size: Any | None = None, quote_size: Any | None = None, time_in_force: TimeInForce | str = TimeInForce.GTC, client_order_id: str | None = None) -> dict[str, Any]
Builds a payload for a guaranteed zero-fee Maker Order (Limit with post_only=True).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The trading symbol (e.g. 'BTC-EUR'). |
required |
side
|
OrderSide | str
|
OrderSide.BUY or OrderSide.SELL. |
required |
price
|
Any
|
Limit price in quote currency per 1 base unit. |
required |
base_size
|
Any | None
|
Amount in base currency (e.g. BTC). |
None
|
quote_size
|
Any | None
|
Amount in quote currency (e.g. EUR). |
None
|
time_in_force
|
TimeInForce | str
|
Time in force (default: GTC). |
GTC
|
client_order_id
|
str | None
|
Optional client UUID. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: JSON payload ready for the Revolut X API. |
Source code in src/revolut_x/helpers.py
build_market_order
classmethod
build_market_order(symbol: str, side: OrderSide, *, base_size: Any | None = None, quote_size: Any | None = None, client_order_id: str | None = None) -> dict[str, Any]
Builds a payload for a Market Order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The trading symbol (e.g., 'BTC-EUR'). |
required |
side
|
OrderSide
|
The side of the order (BUY or SELL). |
required |
base_size
|
Any | None
|
The amount of the base currency (e.g., BTC) to buy/sell. |
None
|
quote_size
|
Any | None
|
The amount of the quote currency (e.g., EUR) to buy/sell. |
None
|
client_order_id
|
str | None
|
A unique client order ID. A UUID will be generated if not provided. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: The constructed JSON payload for the Revolut X API. |
Raises:
| Type | Description |
|---|---|
OrderValidationError
|
If exactly one of base_size or quote_size is not provided. |
Example
OrderPayloadBuilder.build_market_order('BTC-EUR', OrderSide.BUY, quote_size='50.00')
Source code in src/revolut_x/helpers.py
build_order
classmethod
build_order(symbol: str, side: OrderSide | str, order_type: OrderType | str = OrderType.MARKET, *, price: Any | None = None, base_size: Any | None = None, quote_size: Any | None = None, post_only: bool = False, time_in_force: TimeInForce | str = TimeInForce.GTC, client_order_id: str | None = None) -> dict[str, Any]
Builds a payload for either a Market or Limit Order based on order_type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The trading symbol (e.g., 'BTC-EUR'). |
required |
side
|
OrderSide | str
|
The side of the order (BUY or SELL). |
required |
order_type
|
OrderType | str
|
OrderType.MARKET ('market') or OrderType.LIMIT ('limit'). |
MARKET
|
price
|
Any | None
|
Required for limit orders. Must be None for market orders. |
None
|
base_size
|
Any | None
|
The amount of the base currency (e.g., BTC) to buy/sell. |
None
|
quote_size
|
Any | None
|
The amount of the quote currency (e.g., EUR) to buy/sell. |
None
|
post_only
|
bool
|
If True, ensures the order is entered as a MAKER order (limit only). |
False
|
time_in_force
|
TimeInForce | str
|
The time in force policy (limit only). |
GTC
|
client_order_id
|
str | None
|
Optional client-side UUID for idempotency. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: The constructed JSON payload for the Revolut X API. |
Raises:
| Type | Description |
|---|---|
OrderValidationError
|
If parameters are invalid for the given order_type. |
Example
OrderPayloadBuilder.build_order('BTC-EUR', OrderSide.BUY, order_type=OrderType.MARKET, quote_size='50.00')
Source code in src/revolut_x/helpers.py
validate_against_pair_rules
classmethod
validate_against_pair_rules(payload: dict[str, Any], pair_rules: dict[str, Any]) -> tuple[bool, list[str]]
Validates the constructed payload against the exchange's trading pair rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict[str, Any]
|
The order payload to validate. |
required |
pair_rules
|
dict[str, Any]
|
The trading rules for the specific asset pair. |
required |
Returns:
| Type | Description |
|---|---|
tuple[bool, list[str]]
|
tuple[bool, list[str]]: A tuple containing a boolean indicating if the payload is valid, and a list of error messages (if any). |
Example
valid, errors = OrderPayloadBuilder.validate_against_pair_rules(payload, rules)
Source code in src/revolut_x/helpers.py
calculate_maker_price
calculate_maker_price(side: OrderSide | str, *, best_bid: Any | None = None, best_ask: Any | None = None, last_price: Any | None = None, offset: Any = Decimal('0.10'), tick_size: Any = Decimal('0.01')) -> Decimal
Calculates an optimal limit price to guarantee entry into the order book as a Maker (0.00% fee).
For BUY orders
price = (best_bid or last_price) - offset
For SELL orders: price = (best_ask or last_price) + offset
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
side
|
OrderSide | str
|
OrderSide.BUY / OrderSide.SELL or string ('buy' / 'sell'). |
required |
best_bid
|
Any | None
|
Current best bid price (highest buyer in book). |
None
|
best_ask
|
Any | None
|
Current best ask price (lowest seller in book). |
None
|
last_price
|
Any | None
|
Fallback price if best bid/ask is not available. |
None
|
offset
|
Any
|
Safety offset in quote currency (default: 0.10 EUR/USD). |
Decimal('0.10')
|
tick_size
|
Any
|
Minimum price increment for quantisation (default: 0.01). |
Decimal('0.01')
|
Returns:
| Name | Type | Description |
|---|---|---|
Decimal |
Decimal
|
The quantised target price. |
Raises:
| Type | Description |
|---|---|
OrderValidationError
|
If side is invalid or no valid reference price can be determined. |
Example
calculate_maker_price(OrderSide.BUY, best_bid="80000.00", offset="0.10") Decimal('79999.90') calculate_maker_price(OrderSide.SELL, best_ask="80000.50", offset="0.10") Decimal('80000.60')
Source code in src/revolut_x/helpers.py
normalize_symbol
Normalizes the trading symbol for the Revolut X API.
Accepts formats such as 'BTC/EUR', 'BTC-EUR', 'btc-eur', 'btceur', 'BTCEUR'. Returns the normalized symbol with a dash separator (e.g. 'BTC-EUR').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The trading symbol to normalize. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The normalized symbol. |
Example
normalize_symbol('BTC/EUR') 'BTC-EUR' normalize_symbol('btceur') 'BTC-EUR'
Source code in src/revolut_x/helpers.py
to_timestamp_ms
Converts a point in time to a Unix timestamp in milliseconds.
Used by the market data methods so that time ranges can be expressed with
datetime objects instead of raw millisecond integers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
TimeLike
|
One of
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The Unix timestamp in milliseconds. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the value is not one of the supported types. |
ValueError
|
If a string is neither a valid ISO-8601 timestamp nor a long enough run of digits. |
Example
from datetime import datetime, timezone to_timestamp_ms(datetime(2024, 1, 1, tzinfo=timezone.utc)) 1704067200000 to_timestamp_ms("2024-01-01") 1704067200000 to_timestamp_ms(1704067200000) 1704067200000 to_timestamp_ms("1704067200000") 1704067200000