The best way to code to the API is with an IDE that does type checking (e.g. VSCode with the Pylance extension).
The package has typing throughout, and the package will generally work when the types all work out.
Example
In this example, we'll use the architect-py SDK to place a limit order on CME's Micro Ethereum (MET) futures front month contract, 10% below the current best bid
import asyncio
import time
from decimal import Decimal
from architect_py.async_client import AsyncClient, OrderDir
from architect_py.graphql_client.enums import OrderStatus
async def main():
c = AsyncClient(
host="app.architect.co",
api_key="<api key>",
api_secret="<api secret>",
paper_trading=False,
)
market = "ES 20281215 CME Future/US"
execution_venue = "CME"
# Get market snapshot for a single market
# Market snapshots tell you the current best bid, best ask,
# and other ticker info for the given symbol.
print()
print(f"Market snapshot for {market}")
market_snapshot = await c.get_market_snapshot(symbol=market, venue=execution_venue)
print(f"Best bid: {market_snapshot.bid_price}")
print(f"Best ask: {market_snapshot.ask_price}")
# List your FCM accounts
print()
print("Your FCM accounts:")
accounts = await c.list_accounts()
for account in accounts:
print(f"{account.account.name}")
account_id = accounts[0].account.id
# Place a limit order $100 below the best bid
best_bid = market_snapshot.bid_price
if best_bid is None:
raise ValueError("No bid price available")
limit_price = best_bid - Decimal(100)
quantity = Decimal(1)
account = accounts[0]
order = None
print()
if (
input(
f"Place a limit order to BUY 1 LIMIT {limit_price} on account {account.account.name}? [y/N]"
)
== "y"
):
order = await c.send_limit_order(
symbol=market,
execution_venue=execution_venue,
odir=OrderDir.BUY,
quantity=quantity,
limit_price=limit_price,
account=str(account_id),
)
else:
raise ValueError("Order was not placed")
print(f"Order placed with ID: {order.id}")
# Poll order status until rejected or fully executed
# After 5 seconds, cancel the order
i = 0
while OrderStatus.OPEN == order.status:
time.sleep(1)
print(f"...order state: {order.status}")
order = await c.get_order(order.id)
assert order is not None
i += 1
if i == 5:
print("Canceling order")
await c.cancel_order(order.id)
# Print final order state
if OrderStatus.REJECTED == order.status:
print(f"Order was rejected: {order.reject_message}")
elif OrderStatus.CANCELED == order.status:
print("Order was canceled")
elif OrderStatus.OUT == order.status:
print(f"Order was filled for qty: {order.filled_quantity}")
print(f"Average execution price: {order.average_fill_price}")
if __name__ == "__main__":
asyncio.run(main())
Async SDK
The python SDK also includes an sync version of the client. To use this flavor of the client, import from architect_py.client and import the Clientinstead. It is completely identical to the AsyncClientexcept 2 key differences:
Not async, so if you simply remove the async/await keywords from every example