Python Client¶
The client signs with a keri_system node. The node's network must include the witnesses and watchers that the subject uses.
from oracle_stack.client import Client
c = Client(node, "http://127.0.0.1:7700", "oracle", oracle_aid)
Agree¶
agreement = c.agreement(["observe", "read_oracle"], ttl_ms=30 * 86400000, limits={"max_calls": 10000})
The agreement is accepted by the administrator of the service:
import httpx
r = httpx.post(f"http://127.0.0.1:7700/oracles/{oracle_aid}/engage", json=agreement, headers={"Authorization": f"Bearer {admin_token}"})
engagement = r.json()["engagement_id"]
Observe¶
c.observe(engagement, "BTC/USD", "64250.10", credential=None, metadata={"source": "exchange-a"})
Read¶
r = c.invoke(engagement, "read_oracle")
if r["success"]:
print(r["result"]["value"], r["result"]["seq"])
The response is signed by the oracle and bound to the request. The client verifies both.
Submit to a contract¶
c = Client(node, "http://127.0.0.1:7700", "contract", contract_aid)
c.submit("payment_observation", {"amount": "100.00", "currency": "EUR", "reference": "INV-7"})
Withdraw¶
c.withdraw(engagement)
Errors¶
Methods raise OracleError with the status and message, and Refused if an answer does not verify. Repeat requests that fail with 503, because the subject is waiting for witnesses or votes.