Before I move on to more complicated things, like actually placing orders, here is another basic example of using the Revolut API. This one will show us the history of our orders.
The workflow is the same as we saw on the previous page , the only difference is in the code within the Python script node. I have marked the changed lines in a larger and underlined typeface. Actually there are just 2 changes, the path and url variables.
import knime.scripting.io as knio
import requests
import base64
import time
from pathlib import Path
from nacl.signing import SigningKey
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.backends import default_backend
# 1. Load your Private Key
pem_data = Path("private.pem").read_bytes()
private_key_obj = serialization.load_pem_private_key(
pem_data,
password=None,
backend=default_backend()
)
# Extract raw bytes for PyNaCl
raw_private = private_key_obj.private_bytes(
encoding=serialization.Encoding.Raw,
format=serialization.PrivateFormat.Raw,
encryption_algorithm=serialization.NoEncryption()
)
# 2. Prepare the message
timestamp = str(int(time.time() * 1000))
method = "GET"
path = "/api/1.0/orders/historical"
query = "" # No query for balances endpoint
body = "" # Empty for GET
# Concatenate without separators
message = f"{timestamp}{method}{path}{query}{body}".encode('utf-8')
# 3. Sign and Encode
signing_key = SigningKey(raw_private)
signed = signing_key.sign(message)
signature = base64.b64encode(signed.signature).decode()
url = "https://revx.revolut.com/api/1.0/orders/historical"
headers = {
'Accept': 'application/json',
'X-Revx-Timestamp': timestamp,
'X-Revx-Signature': signature,
'X-Revx-API-Key': '<API key goes here>'
}
response = requests.get(url, headers=headers)
print(response.content)
# Optionally, parse the response as JSON and output as a KNIME table
import pandas as pd
try:
data = response.json()
# If the response is a list of balances
if isinstance(data, list):
df = pd.DataFrame(data)
# If the response is a dict with a key containing the balances
elif isinstance(data, dict):
# Try to find a likely key
for key in ['balances', 'data', 'results']:
if key in data and isinstance(data[key], list):
df = pd.DataFrame(data[key])
break
else:
# Fallback: just wrap the dict
df = pd.DataFrame([data])
else:
df = pd.DataFrame([{"response": str(data)}])
except Exception as e:
df = pd.DataFrame([{"error": str(e), "response_text": response.text}])
knio.output_tables[0] = knio.Table.from_pandas(df)
Below is a screenshot from running this. You can see the one order I have executed.
In the next example we will try to place an order.