> ## Documentation Index
> Fetch the complete documentation index at: https://docs.0xmonaco.com/llms.txt
> Use this file to discover all available pages before exploring further.

# V0.3.0

# Monaco Protocol v0.3.0

## Orderbooks and Flat Fees

This release introduces major improvements to orderbook functionality, fee management, and order lifecycle handling. Key highlights include real-time orderbook snapshots via WebSocket, flat fee support, and comprehensive time-in-force options.

### What's New

**Orderbook Enhancements**

* **Real-time Orderbook Snapshots**: Full orderbook state via WebSocket with initial snapshot on subscription
* **Orderbook Magnitude Grouping**: Optional price level aggregation for cleaner visualization (0.0001 to 10000 increments)
* **Improved Orderbook Endpoint**: Enhanced REST API with better performance and data structure

**Fee System Improvements**

* **Flat Fee Support**: New fee calculation method alongside existing basis point fees
* **Fee HTTP Endpoints**: Dedicated API endpoints for fee management and queries
* **Pre-settlement Fee Calculation**: Fees calculated before settlement for accurate balance checks

**Time-in-Force Support**

* **Full TIF Implementation**: Support for GTC (Good-Till-Cancel), IOC (Immediate-or-Cancel), and FOK (Fill-or-Kill)
* **Order Rejection Events**: New event types for rejected orders with detailed reasons
* **Enhanced Order Validation**: Pre-validation for FOK orders to prevent partial fills

**Order Management Improvements**

* **Order Replacement**: Renamed "Update Order" to "Replace Order" for clarity
* **Order Quantity Validation**: Enhanced validation on order replacement
* **Consistent Enum Formatting**: Uppercase enums across entire codebase (SPOT, MARGIN, BUY, SELL, etc.)
* **Side and Role Fields**: Added to OrderPlaced and OrderPartiallyFilled WebSocket events

### Technical Details

**WebSocket Connection Methods**

Connect to WebSockets using either auto-connect during login or explicit connection:

```typescript theme={null}
// Method 1: Auto-connect authenticated WebSockets during login
const authState = await sdk.login(clientId, { connectWebSocket: true });
// Orders WebSocket is now connected and ready

// Method 2: Explicit connection after login
const authState = await sdk.login(clientId);
await sdk.websocket.orders.connect();

// Public WebSockets (orderbook, OHLCV) don't require authentication
await sdk.websocket.orderbook.connect();
await sdk.websocket.ohlcv.connect();
```

**Orderbook WebSocket with Magnitude**

Subscribe to orderbooks with optional price grouping:

```typescript theme={null}
// Full precision orderbook
sdk.websocket.orderbook.subscribeToOrderbookEvents(
  'BTC/USDC',
  'SPOT',
  (update) => {
    console.log('Bids:', update.bids, 'Asks:', update.asks);
  }
);

// Grouped by $10 increments
sdk.websocket.orderbook.subscribeToOrderbookEvents(
  'BTC/USDC',
  'SPOT',
  (update) => {
    console.log('Grouped orderbook:', update);
  },
  10  // Magnitude: group by $10
);
```

**Time-in-Force Orders**

```typescript theme={null}
// Immediate-or-Cancel
await sdk.trading.placeLimitOrder(
  pairId,
  'BUY',
  '1.0',
  '2500.00',
  { timeInForce: 'IOC' }
);

// Fill-or-Kill
await sdk.trading.placeLimitOrder(
  pairId,
  'BUY',
  '1.0',
  '2500.00',
  { timeInForce: 'FOK' }
);
```

### Architecture & Infrastructure

**Admin API**

* New admin endpoints for system management and monitoring
* Procedural macro-based authentication decorators replacing middleware

**Authentication Improvements**

* Unified auth extractor with procedural macros
* Replace middleware with `#[require_auth]`, `#[require_master]`, and `#[require_permission]` decorators
* Cleaner, more maintainable authentication layer

**Performance Optimizations**

* Reduced lock contention during API initialization and order expiration
* Trading pair cache updates for faster lookups
* Improved matching engine transaction handling

**Testing & Code Quality**

* Split order E2E tests into multiple focused test suites
* Resolved foreign key constraint violations in indexer tests
* Enhanced test coverage with `.env` file support
* Fixed IOC order event emission for partial fills

### Bug Fixes

* Fixed double serialization issues with consistent uppercase enum representation
* Corrected BPS calculation in matching engine for order creation
* Fixed maker order status and balance updates when trades occur
* Resolved insufficient balance errors on order creation
* Fixed IOC/FOK partial fill locked balance issues
* Prevented duplicate blockchain events with enhanced duplicate checking
* Fixed missing cancelled events for IOC orders
* Improved order settlement status checks before cancellation

### Documentation

* Auto-generated API documentation from OpenAPI specs
* Updated SDK documentation for latest features
* Added cloud infrastructure architecture documentation
* Comprehensive orderbook WebSocket examples
* Enhanced trading pair and order object documentation

### Packages Updated

* `@0xmonaco/core@0.3.0`
* `@0xmonaco/types@0.3.0`
* `@0xmonaco/react@0.3.0`

### Installation

```bash theme={null}
npm install @0xmonaco/core@0.3.0
npm install @0xmonaco/react@0.3.0  # For React applications
```

### Migration Notes

**Breaking Changes:**

* Enum values are now consistently uppercase (SPOT, MARGIN, BUY, SELL, etc.)
* Update any hardcoded lowercase enum strings to uppercase

**New Features:**

* Orderbook magnitude parameter is optional (defaults to full precision)
* Time-in-force defaults to GTC if not specified

### Contributors

* @kamwithak
* @codebycarson
* @ogarciarevett
* @dssei
* @ppitlehra
* @Kbhat1

### Full Changelog

This release merged 55 pull requests.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.