Skip to main content

Installation

pip install rivermarkets

Quick Start

from rivermarkets import RiverMarkets

client = RiverMarkets(api_key="your_api_key")

# Search markets
results = client.markets.search_markets(q="bitcoin")
for market in results.results:
    print(f"{market.river_id}: {market.title}")

Async Support

from rivermarkets import AsyncRiverMarkets

client = AsyncRiverMarkets(api_key="your_api_key")
results = await client.markets.search_markets(q="bitcoin")

Trading

Place an Order

order = client.orders.create_order(
    subaccount_id="your_subaccount_id",
    river_id=4552150,
    order_type="LIMIT",
    time_in_force="GTC",
    buy_flag=True,
    price=0.50,
    qty=10,
)
print(f"Order placed: {order.river_order_id}")

List Orders

orders = client.orders.list_orders(status="RESTING")
for order in orders.orders:
    print(f"{order.river_order_id}: {order.status}")

Cancel an Order

client.orders.cancel_order(order_id="your_order_id")

Portfolio

Get Positions

positions = client.positions.get_positions()

Get Fills

fills = client.fills.get_fills(subaccount_id="your_subaccount_id")

Market Data

Orderbook

orderbook = client.orderbooks.get_orderbook(river_id=4552150)

Price History

prices = client.prices.get_prices(river_id=4552150, type="candlestick", interval="1d")

Subaccounts

# List subaccounts
subaccounts = client.subaccounts.list_subaccounts()

# Create a subaccount
subaccount = client.subaccounts.create_subaccount(name="My Strategy")

Error Handling

The SDK raises typed exceptions for API errors:
from rivermarkets import BadRequestError, NotFoundError

try:
    order = client.orders.get_order(order_id="invalid")
except NotFoundError:
    print("Order not found")
except BadRequestError as e:
    print(f"Bad request: {e.body}")

Configuration

client = RiverMarkets(
    api_key="your_api_key",
    base_url="https://api.rivermarkets.com",  # default
    timeout=30.0,                              # seconds, default 60
)

GitHub

View the source code and contribute on GitHub.