diff --git a/README.md b/README.md index 4437220..6b390f5 100644 --- a/README.md +++ b/README.md @@ -244,22 +244,21 @@ if (placeOrderFetchResult.isErr()) { Available subscriptions: ```ts -ASSET_PAIRS_CONFIG_UPDATES_SUBSCRIBE = 'apcus', -AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE = 'aobus', ADDRESS_UPDATES_SUBSCRIBE = 'aus', // Orders history, balances info -BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATES_SUBSCRIBE = 'btasabus', SWAP_SUBSCRIBE = 'ss', // Swap info updates +AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE = 'aobus', // Bids and asks +ASSET_PAIRS_CONFIG_UPDATES_SUBSCRIBE = 'apcus', +BROKER_TRADABLE_ATOMIC_SWAP_ASSETS_BALANCE_UPDATES_SUBSCRIBE = 'btasabus', // Need for Orion Bridge ``` Example: ```ts -import { services } from "@orionprotocol/sdk"; import { v4 as uuidv4 } from "uuid"; const swapRequestId = uuidv4(); orionUnit.orionAggregator.ws.subscribe( - services.orionAggregator.ws.SubscriptionType.SWAP_SUBSCRIBE, + "ss", // SWAP_SUBSCRIBE { payload: { d: swapRequestId, // generated by client @@ -282,3 +281,45 @@ orionUnit.orionAggregator.ws.subscribe( } ); ``` + +### Balances and order history stream + +```ts +orionUnit.orionAggregator.ws.subscribe( + "aus", // ADDRESS_UPDATES_SUBSCRIBE — orders, balances + { + payload: "0x0000000000000000000000000000000000000000", // Some wallet address + callback: ({ fullOrders, orderUpdate, balances }) => { + // Each field is optional + if (fullOrders) console.log(fullOrders); // Completed orders + + if (orderUpdate) { + switch (orderUpdate.kind) { + case "full": + console.log("Order completed", orderUpdate); + break; + case "update": + console.log("Order in the process of execution", orderUpdate); + break; + default: + break; + } + } + + if (balances) console.log("Balance update", balances); + }, + } +); +``` + +### Orderbook stream + +```ts +orionUnit.orionAggregator.ws.subscribe("aobus", { + payload: "ORN-USDT", // Some trading pair + callback: (asks, bids, pairName) => { + console.log("Orderbook asks", asks); + console.log("Orderbook bids", bids); + }, +}); +```