Orderbook API
Overview
This documentation details the API endpoints for interacting with Polarity's Orderbook, catering to node implementations and developers seeking market data for Flashnet or broader applications.
API Endpoints
Market Data
Get the Orderbook
GET
/api/ordernook
Response Schema:
Get Recent Trades
GET
/api/trades
Request Schema:
Response Schema:
Get Order Info
GET
/api/trades/{orderId}
Response Schema:
Candlestick Data
GET
/api/candles
Request Schema:
Response Schema:
Trading Endpoints
Create an Order
POST
/api/order/create
Request Schema:
Response Schema:
Cancel Order
DELETE
/api/order/cancel
Request Schema:
Response Schema:
Cancel All Open Orders
DELETE
/api/order/cancelAll
Response Schema:
WebSocket Communication
WebSocket communication enables real-time data exchange between clients and the server, eliminating the need for polling the server for updates. This section describes how to adapt REST API functionalities to WebSocket communications for creating orders, matching orders, and exchanging invoices within the Flashnet Orderbook.
Establishing a WebSocket Connection
Clients must establish a WebSocket connection to the orderbook server using the WebSocket URL. Once connected, clients can subscribe to specific channels for updates and perform trading actions in real-time.
Websockets are P2P, the orderbook simply helps connect the peers together and monitors the information going through. Settlement happens trustlessly on the Lightning Network.
WebSocket Channels and Actions
Creating an Order
Order creation can happen via REST or WS
Action:
createOrder
Request Schema:
Response Schema:
Notification of Order Match
Upon a successful order match, both the maker and taker are notified through their WebSocket connection.
Notification Schema:
Generating Invoices
Once notified of a match, the taker is expected to generate invoices immediately.
Action:
generateInvoices
Request Schema:
Response Schema:
Once notified of taker invoices, the maker is expected to generate invoices immediately.
Action:
generateInvoices
Request Schema:
Response Schema:
The peers then pay each others invoices on the Lightning Network.
Completing the Trade
Upon settlement completion on the Lightning Network, the Taker is expected to settle on the LN (which instantly settle the maker invoices since they have the same hash) and signal the preimage of his invoices to the WS connection with the maker.
Action:
completeTrade
Request Schema:
Response Schema:
The order is now considered closed and settled. This all happens in less than a second if actors are all working properly. If a pre-image is invalid, the orderbook releases the hash to the collateral invoice to the Taker, which he can use to claim the collateral punishing the Taker for cheating. There are some time based reasons for the collateral being released as well.
Websocket market data
The websockets can also be used to receive live updates on the orderbook, recent trades, or chart data.
Last updated