Pacifica
Read Pacifica markets and trade perpetuals or spot from Python Scripting V2.
Use pacificaf for perpetuals and pacifica for spot. The source and execution exchange are explicit on each request. No Pacifica SDK or Market Lab Python package is required inside the script.
Read market data
This read-only script prints the best perpetual bid and ask:
BOOK = "btc@orderbook@pacificaf:depth=10"
script = {
"name": "pacifica-book",
"version": "2",
"lookback": 1,
}
def on_data(ctx, history):
book = history.source(BOOK, 0)
if book and book["bids"] and book["asks"]:
print(book["bids"][0]["price"], book["asks"][0]["price"])Run it with:
mlab script run pacifica_book.py --duration 300Add --testnet to use testnet data and accounts. For spot, change the source to an available pair such as "sol/usdc@orderbook@pacifica:depth=10". The two networks have independent market catalogs.
Trade through the shared execution API
Configure an authorized Pacifica agent before deploying a trading script. In Furge, connect Pacifica in Accounts.
An intentional perpetual entry uses the normal ctx.trade request:
reference = ctx.trade({
"exchange": "pacificaf",
"symbol": "BTC",
"position": "open-long",
"margin": 100,
"leverage": 2,
"max_slippage_bps": 50,
})This is a request illustration. Call it only after the script's entry condition and duplicate guard. Declare a compatible BTC source in the same script.
Use a raw order for spot inventory:
reference = ctx.order({
"exchange": "pacifica",
"symbol": "SOL/USDC",
"side": "sell",
"size": 0.1,
"order": {"type": "limit", "price": 150, "tif": "alo"},
})The price is illustrative and must follow the selected market's current tick size. A spot sell requires available SOL; it does not open a short.
Both calls return a local order reference, not a confirmed fill. Follow on_execution(ctx) for venue acknowledgements, partial fills, fills, cancellations and rejections. Cancel a managed order with its local reference:
ctx.cancel({"order": reference["id"]})Pacifica uses the main execution account configured for the selected network. Market Lab named subaccounts are not provided by this integration. Never store owner or agent keys in the Python file.
See Python execution and Sources.