{"id":22608982,"url":"https://github.com/bitfinexcom/sunbeam","last_synced_at":"2025-07-21T11:33:00.320Z","repository":{"id":55425677,"uuid":"141120592","full_name":"bitfinexcom/sunbeam","owner":"bitfinexcom","description":null,"archived":false,"fork":false,"pushed_at":"2020-12-31T09:00:20.000Z","size":373,"stargazers_count":46,"open_issues_count":0,"forks_count":19,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-06-16T19:18:47.028Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitfinexcom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-16T09:59:01.000Z","updated_at":"2025-05-15T07:47:07.000Z","dependencies_parsed_at":"2022-08-15T00:01:02.822Z","dependency_job_id":null,"html_url":"https://github.com/bitfinexcom/sunbeam","commit_stats":null,"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"purl":"pkg:github/bitfinexcom/sunbeam","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fsunbeam","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fsunbeam/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fsunbeam/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fsunbeam/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitfinexcom","download_url":"https://codeload.github.com/bitfinexcom/sunbeam/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fsunbeam/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266291826,"owners_count":23906337,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-08T15:10:26.257Z","updated_at":"2025-07-21T11:33:00.300Z","avatar_url":"https://github.com/bitfinexcom.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/bitfinexcom/sunbeam.svg?branch=master)](https://travis-ci.org/bitfinexcom/sunbeam)\n\n# Sunbeam\n\neosfinex Websocket adapter for Node and the browser.\n\nWe designed the eosfinex Websocket API with both speed and compatibility in mind.\nIt is a subset of the existing Bitfinex API v2, with modifications\nfor on-chain trading. Existing API v2 users should be able to start with\nonly a small changeset to their existing clients.\n\nSunbeam is the current reference implementation of the Websocket API client. It\ninteracts with the contract ABI. For more details, see the\n[signing section](#signing).\n\nThis readme covers both the Sunbeam API and explains how it interacts behind\nthe scenes with the server.\n\nThe main difference between the Bitfinex WS API and eosfinex's API is the\nsigning of messages. For eosfinex, we have to sign actions with our eosjs\nprivate key. A signed transaction is also used for subscriptions to trade,\norder and wallet snapshots and updates.\n\n```js\nconst Sunbeam = require('sunbeam')\n\n// Browser usage: import into browsers\nimport Sunbeam from 'sunbeam/dist'\n```\n\n## Paper Trading\n\nOn paper trading tokens are generally prefixed by `P`. So `BTC` becomes\n`PBTC`. The only exception is the resource token `EOX`. For a list of\navailable trading pairs, see [trade-pairs](#trading-pairs).\n\n## Examples\n\n### Node.js\n\nExample of the Websocket client usage: [example-ws.js](example-ws.js)\n\n\nRun with:\n```\nnode example-ws.js\n```\n\n\n## Websocket API\n\nYou can see all API calls in [example-ws.js](example-ws.js) or [example-ual.js](example-ual.js).\nSunbeam support private key or [UAL](https://github.com/EOSIO/universal-authenticator-library) for authentication.\n\n### `new Sunbeam(client, opts) =\u003e sunbeam`\n  - `client \u003cObject\u003e`\n    - `rpc` official eosjs rpc class instance\n    - `api` official eosjs Api class instance\n  - `opts \u003cObject\u003e`\n    - `urls \u003cObject\u003e` Websocket transports\n      - `pub \u003cString\u003e` Public transport\n      - `priv \u003cString\u003e`Private transport\n      - `aux \u003cString\u003e` Aux transport\n    - `eos \u003cObject\u003e` options passed to Eos client for signing transactions\n      - `expireInSeconds \u003cNumber\u003e` Expiration time for signed tx. 7 days by default\n      - `httpEndpoint \u003cString|null\u003e` an Eos node HTTP endpoint, used to get the contract abi, if abi not passed via options.\n      - `exchangeContract \u003cString|null\u003e` name of the used exchange contract, defaults to `efinexchange`\n    - `auth` Auth options\n      - `keys` use default signing\n        - `keyProvider \u003cString\u003e` your key, used to sign transactions\n        - `account \u003cString\u003e` accountname to use for the key\n        - `permission \u003cString\u003e` permission level to use for the account\n      - `ual \u003cObject\u003e` UAL options if UAL is used for signing\n        - `user \u003cString\u003e` Authenticated UAL user\n    - `state \u003cObject\u003e` Options passed to state components\n      - `transform \u003cObject\u003e` transformation options (keyed objects or array format)\n        - `orderbook \u003cObject\u003e`\n          - `keyed \u003cBoolean\u003e` Manage state as keyed Objects instead of an Array\n        - `wallet \u003cObject\u003e`\n        - `orders \u003cObject\u003e`\n          - `keyed \u003cBoolean\u003e` Manage state as keyed Objects instead of an Array\n          - `markDeleted \u003cBoolean\u003e` cancelled orders are flagged as deleted, but not removed from the state\n\n```js\n// prepare eosjs lib for signing of websocket messages\n\nconst { Api, JsonRpc } = require('eosjs')\nconst { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig')\n\n\nconst fetch = require('node-fetch')\nconst { TextDecoder, TextEncoder } = require('util')\nconst keys = ['SECRET']\n\nconst signatureProvider = new JsSignatureProvider(keys)\n\nconst httpEndpoint = 'https://api.eosfinex.com'\n\nconst rpc = new JsonRpc(httpEndpoint, { fetch })\nconst api = new Api({\n  rpc,\n  signatureProvider,\n  textDecoder: new TextDecoder(),\n  textEncoder: new TextEncoder()\n})\n\nconst client = {\n  rpc,\n  api\n}\n\n// setup sunbeam\nconst opts = {\n  urls: {\n    pub: 'wss://api.bitfinex.com/ws/2',\n    priv: 'wss://api.eosfinex.com/ws'\n  },\n  eos: {\n    expireInSeconds: 7 * 24 * 60 * 60, // 7 days\n    httpEndpoint, // Used to get metadata for signing transactions\n    exchangeContract: 'eosfinexeos1', // Name of the exchange contract\n    auth: {\n      ual: {\n        user: '', // UAL user object\n      },\n    },\n  },\n  state: {\n    transform: {\n      orderbook: { keyed: true },\n      wallet: {},\n      orders: {}\n    }\n  }\n}\n\nconst ws = new Sunbeam(client, opts)\n```\nIn order to start trading it is required to sign up for the platform at [eosfinex.com](https://www.eosfinex.com/) and accept [terms of services](https://www.eosfinex.com/legal/exchange/terms).\n\nFor an example how to use Scatter for auth, see [example-scatter.js](example-scatter.js).\n\n### Events emitted\n\n#### `Event: open`\n\nEmitted when the socket connection is established.\n\n*Example:*\n\n```js\nconst ws = new Sunbeam(opts)\n\nws.on('open', () =\u003e {\n  // ready to trade!\n})\n\nws.open()\n```\n\n#### `Event: message`\n\nEmitted for every message that the Websocket client receives. Useful for\ndebugging and custom extensions.\n\n*Example:*\n\n```js\nws.on('message', (m) =\u003e {\n  console.log(m)\n})\n```\n\n#### `Event: error`\n\nEmitted in case of an error.\n\n*Example:*\n\n```js\nws.on('error', (m) =\u003e {\n  console.error(m)\n})\n```\n\n### General methods\n\nYou can see all API calls in [example-ws.js](example-ws.js).\nBefore you can run it, make sure to configure your environment:\n\n```sh\ncp config/example-ws.config.json.example config/example-ws.config.json\n\nvim config/example-ws.config.json\n```\n\nor see [example-scatter.js](example-scatter.js) on the in-code configuration example.\n\n#### `sunbeam.open()`\n\nOpens a Websocket.\n\n*Example:*\n\n```js\nws.open()\n```\n\n#### `sunbeam.close()`\n\nCloses the connection to the server.\n\n*Example:*\n\n```js\nws.close()\n```\n\n#### `sunbeam.auth() =\u003e Promise`\n\nSubscribes you to `wallet`, `trade` and `order` updates for the specified account.\n\n\nTakes the account name you have defined when creating a Sunbeam instance with\n`opts.eos.auth` or receives the account name from Scatter. Your private key\nstays on your machine.\n\nYou can authenticate on the eosfinex Websocket API like with the Bitfinex API.\nThe API will then send you your wallet, order and trades snapshots and updates.\nFor this a special action is available in the contract ABI called `validate`.\nThe Websocket plugin uses it to verify that the transaction belongs to the\nproper account.\n\nSunbeam signs a verification transaction that is send to the Websocket endpoint\nfor validation. This transaction is just used for verifying the signature.\n\nIf you configured auth via scatter, it will connect to scatter. Remember to remove\nany global references to ScatterJS **and any global references to Sunbeam**:\n\n```js\nwindow.ScatterJS = null;\n```\n\n*Sent payload:*\n\n```\n{\n event: 'auth',\n account: \u003cusername\u003e,\n meta: \u003csigned\u003e\n}\n```\n\nWhere `\u003csigned\u003e` is a signed transaction for the `validate` action.\n\n*Important:* to be able to trade, you have to sign up for the platform and accept the terms of service at [eosfinex.com](https://www.eosfinex.com/).\n\n#### `sunbeam.getSignedTx(?user) =\u003e Promise`\n\n  - `user \u003cObject\u003e` optional user object. If not defined, the data provided in the constructor will be used or retrieved from Scatter\n\nSigns a transaction that can be used for login on the WS server for custom auth flows.\n\nExample:\n\n```js\nconst { Serialize } = require('eosjs')\n\nconst user = {\n  authorization: {\n    authorization: \"testuser1114@active\"\n  },\n  account: \"testuser1114\",\n  permission: \"active\"\n}\n\nconst signed = await ws.getSignedTx(user)\nconst serializedTransaction = api.serializeTransaction(signed)\nconst authTxHex = Serialize.arrayToHex(serializedTransaction)\nconst authTxPayload = {\n  t: authTxHex,\n  s: signed.signatures[0]\n}\n\nconst history = await fetch(moonbeamUrl + '/v1/history', {\n  method: 'POST',\n  body: JSON.stringify({\n    auth: authTxPayload,\n    data: { limit: 100 }\n  }),\n  headers: { 'Content-Type': 'application/json' }\n}).then(res =\u003e res.json())\n\nconsole.log(JSON.stringify(history, null, 2))\n```\n\n#### `sunbeam.logoutScatter() =\u003e Promise`\n\nForgets scatter identity (if scatter is used for auth).\n\n#### `sunbeam.place(order) =\u003e Promise`\n  - `order \u003cObject\u003e`\n    - `symbol \u003cString\u003e` Token pair to trade for\n    - `amount \u003cString\u003e` Amount to buy/sell\n    - `type \u003cString\u003e` Order type, `EXCHANGE MARKET`, `EXCHANGE LIMIT`, `EXCHANGE STOP`, `EXCHANGE FOK`, `EXCHANGE IOC`\n    - `price \u003cString\u003e` Price for orders except market orders\n    - `cid \u003cNumber\u003e` Every order must have a unique id assigned from the client, defaults to current timestamp\n    - `gid \u003cNumber\u003e` Group id for the order, optional\n    - `flags \u003cNumber\u003e` See [flags list](#list-of-available-flags)\n    - `tif \u003cDatetime string\u003e or \u003cNumber\u003e` Time-In-Force: datetime for automatic order cancellation (ie. `2020-01-01 10:45:23`). *Applicable to `EXCHANGE LIMIT` orders only.*\n    `tif` may be an integer value representing the number of milliseconds since January 1, 1970, or a string value representing a date ([see more here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse#Date_Time_String_Format)). **NOTE:** if no timezone is passed, client timezone will be implied. \n\nCreates an order compatible with the contract ABI, pre-signs it and sends it\nto the Websocket endpoint.\n\nTo be able to identify the order, a client **MUST** send a custom client id with it\nthat must be unique to the clients orders.\n\n##### Price deviation\n\nThe following Websocket message is sent on authentication and contains the maximum possible \nprice deviation from the best price when placing an order`{ event: 'pl', val: 0.1 }`.\nFor example, if the best price is 10 and deviation is 0.1, you won't be able to place a buy order for the price \nless than 10 - 10 * 0.1 = 9. \nIf the price in the `order` exceeds the deviation, an error event will be generated.\n\n##### List of available flags\n\nSome flags are abstracted by Sunbeam. Here is a full list of available flags:\n\n```\nFlag            Type    Value   Description\n-------------------------------------------------------------------------------------------------------------------------------------------------------------------\nHidden          int     64      The hidden order option ensures an order does not appear in the order book; thus does not influence other market participants.\nClose           int     512     Close position if position present.\nReduce Only     int     1024    Ensures that the executed order does not flip the opened position.\nPost Only       int     4096    The post-only limit order option ensures the limit order will be added to the order book and not match with a pre-existing order.\n```\n\u003ca id=\"signing\" /\u003e\nBehind the scenes Sunbeam uses the exchange contract ABI to sign the transaction.\nThe ABI is publicly available via `cleos` or curl:\n\n```\ncurl --request POST \\\n  --url https://api.eosfinex.com/v1/chain/get_abi \\\n  --header 'accept: application/json' \\\n  --header 'content-type: application/json' \\\n  --data '{\"account_name\":\"eosfinexeos1\"}'\n```\n\nAfter signing, the transaction is sent to the Websocket server:\n\n```js\nconst signed = {\n  \"expiration\": \"2020-05-10T18:17:13.000\",\n  \"ref_block_num\": 27684,\n  \"ref_block_prefix\": 959416581,\n  \"max_net_usage_words\": 0,\n  \"max_cpu_usage_ms\": 0,\n  \"delay_sec\": 0,\n  \"context_free_actions\": [],\n  \"actions\": [\n    {\n      \"account\": \"efinexchange\",\n      \"name\": \"place\",\n      \"authorization\": [\n        {\n          \"actor\": \"testuser1114\",\n          \"permission\": \"active\"\n        }\n      ],\n      \"data\": \"40420857619DB1CAF1B4BFA26A01000000800139610D3A5548DA2D0000000000942A00000000000000\"\n    }\n  ],\n  \"transaction_extensions\": [],\n  \"signatures\": [\n    \"SIG_K1_Ke541LARCg24Zg66cacNLEfrJXJzfdgeZKNmyKEsxyGUVFxxEPxqJqYQJgv8gc2CXsG9a5HYvDrMePUGyfH8P6uihDoiSp\"\n  ]\n}\n\n// payload sent to the server:\n[0, 'on', null, {\n                      cid,\n                      type,\n                      symbol,\n                      price,\n                      amount,\n                      flags,\n                      meta: \u003ctransaction data\u003e\n                 }]\n```\n\n\n*Example:*\n\n```js\n\nconst order = {\n  symbol: pair,\n  price: '8100',\n  amount: '-0.01',\n  type: 'EXCHANGE LIMIT',\n  cid: '1332'\n}\nws.place(order)\n```\n\nThe request will be signed locally using the `eosjs` module.\n\n*Sent payload:*\n\n```\n[0, 'on', null, {\n                     cid,\n                     type,\n                     symbol,\n                     price,\n                     amount,\n                     flags,\n                     meta: \u003ctransaction data\u003e\n                }]\n```\n\n`\u003ctransaction data\u003e` is a signed transaction payload in array notation for the `place` [action of the **exchange contract**](#signing).\n\n#### `sunbeam.cancel(data) =\u003e Promise`\n\n  - `data`\n    - `id \u003cString\u003e` The id returned from the contract on placement\n\nCancels an order.\n\n*Example:*\n\n```js\nws.cancel({ id: '18446744073709551612' })\n```\n\n*Sent payload:*\n\n```\n[0, 'oc', null, { id }]\n```\n\n#### `sunbeam.withdraw(data) =\u003e Promise`\n\n- `data` - an Object or Array of Objects with the following properties\n  - `currency \u003cString\u003e` The currency to withdraw, e.g. `BTC`\n  - `amount \u003cString\u003e` The amount to withdraw\n  - `memo \u003cString\u003e (optional)` Additional note\n\nWithdraws tokens to the account used for authentication.\n\nA transaction is created, signed using `eosjs client` that was passed at Sunbeam instantiation, and pushed to the chain.\n\nA single transaction may hold several withdrawals.\n\nTransaction data and push result are returned.\n\n*Example:*\n\n```js\nconst { txResult, txData } = await ws.withdraw({\n  currency: 'EUR',\n  amount: '0.678'\n})\n\n// txData - array of objects: { currency, amount }\n// txResult - data returned from `eosjs.api.transact(..)`\n```\n\nThe request will be [signed locally](#signing) using the `eosjs` module.\n\n#### `sunbeam.deposit(data) =\u003e Promise`\n  - `data` - an Object or Array of Objects with the following properties\n    - `currency \u003cString\u003e` The currency to deposit, e.g. `BTC`\n    - `amount \u003cString\u003e` The amount to deposit\n    - `to \u003cString\u003e (optional)` The receiver. Defaults to `exchangeContract` from the configuration object\n    - `memo \u003cString\u003e (optional)` Additional note\n\nDeposits the desired amount to the exchange.\nTakes the user account used for auth.\n\nA transaction is created, signed using `eosjs client` passed at Sunbeam instantiation, and pushed to the chain.\n\nA single transaction may hold several deposits.\n\nTransaction data and push result are returned.\n\n*Example:*\n\n```js\nconst { txResult, txData } = await ws.deposit({\n  currency: 'EUR',\n  amount: '2'\n})\n\n// txData - array of objects: { currency, amount, to }\n// txResult - data returned from `eosjs.api.transact(..)`\n```\n\nThe request will be [signed locally](#signing) using the `eosjs` module.\n\n#### `sunbeam.subscribe(transport, channel, ?opts)`\n  - `transport \u003cString\u003e` The Websocket transport to use (`priv`, `pub`, `aux`)\n  - `channel \u003cString\u003e` The channel name to subscribe to\n  - `opts \u003cObject\u003e` Additional data to send\n\n\nSubscribes to a Websocket channel.\n\nAvailable channels for `priv`:\n\n```\nreports         trade updates\nwallets         wallet snapshots / updates\n```\n\nThe channels `reports` and `wallets` are automatically subscribed on authentication\nvia Websocket.\n\n*Example:*\n\n```js\nws.subscribe('priv', 'wallets', { account: 'testuser1431' })\n```\n\n*Sent Payload:*\n\n```\n{\n  event: 'subscribe',\n  channel: 'wallets',\n  account: 'testuser1431'\n}\n```\n\nChannel `book` is available for `pub` and represents orderbook information. \nSee [bitfinex docs](https://docs.bitfinex.com/reference#ws-public-books) for more details.\n\n#### `sunbeam.unsubscribe(transport, channel, ?opts)`\n  - `transport \u003cString\u003e` The Websocket transport to use (`priv`, `pub`, `aux`)\n  - `channel \u003cString\u003e` The channel name or channel id to unsubscribe from\n  - `opts \u003cObject\u003e` Additional data to send\n\nUnsubscribes from a channel.\n\nThe channels `reports` and `wallets` are automatically subscribed on authentication\nvia Websocket.\n\n*Example:*\n\n```js\nws.unsubscribe('priv', 'wallets', { account: 'testuser1431' })\n\n```\n\n*Sent Payload:*\n\n```\n{\n  event: 'unsubscribe',\n  channel: 'wallets',\n  account: 'testuser1431'\n}\n```\n\n#### Websocket API helper RPC calls\n\nThere are a few additional RPC calls that can help when writing your own\nclient.\n\n##### Chain metadata - { event: 'chain' }\n\nReturns metadata used for signing transactions via Websocket.\n\nFormat is:\n\n```\n[0, 'ci', [\n  $headBlockTime,\n  $lastIrreversibleBlockNumber,\n  $chainId,\n  $refBlockPrefix\n]]\n```\n\n*Example:*\n\n```js\nws.on('message', (m) =\u003e {\n  console.log(m)\n})\n\nws.send('priv', { event: 'chain' })\n```\nor\n```js\nconst meta = await ws.requestChainMeta('priv')\n```\n\n*Example response:*\n\n```\n[ '0',\n  'ci',\n  [ '1557850696',\n    9296555,\n    'cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f',\n    '372320450' ] ]\n```\n\n##### Trading pairs - { event: 'si' }\n\u003ca id=\"trading-pairs\" /\u003e\nReturns available trading pairs and their properties.\n\n*Example:*\n\n```js\nws.on('message', (m) =\u003e {\n  console.log(m)\n})\n\nws.send('priv', { event: 'symbols' })\n```\n\n*Example response:*\n\n```\n[\n  0,\n  'si',\n  [\n    {\n      pair: 'tEOSUST',\n      price_precision: 5,\n      initial_margin: '0.0',\n      minimum_margin: '0.0',\n      maximum_order_size: '100000.0',\n      minimum_order_size: '1',\n      expiration: 'NA',\n      margin: 0\n    },\n    {\n      pair: 'tBTCUSD',\n      price_precision: 5,\n      initial_margin: '0.0',\n      minimum_margin: '0.0',\n      maximum_order_size: '100000.0',\n      minimum_order_size: '1',\n      expiration: 'NA',\n      margin: 0\n    },\n    {\n      pair: 'tBTCUST',\n      price_precision: 5,\n      initial_margin: '0.0',\n      minimum_margin: '0.0',\n      maximum_order_size: '100000.0',\n      minimum_order_size: '1',\n      expiration: 'NA',\n      margin: 0\n    }\n  ]\n]\n```\n\n### Managed State Updates\n\nUsually the Bitfinex trading protocol will send a snapshot, and later just\nupdates, for performance reasons.\n\nWhen you register a `managed` orderbook handler, the managed state component\nwill take care of parsing the snapshots update the state when partial updates arrive.\n\nFor every update, the full updated data is emitted.\n\n*Orderbook updates come for the orders of authenticated user.\nPublic orderbook data is available via Bitfinex Websocket connection.*\n\n#### `sunbeam.onManagedOrderbook(opts, handler)`\n  - `opts \u003cObject\u003e`\n    - `symbol \u003cString\u003e` The symbol to emit the orderbook update for, i.e. `tBTCUST`\n  - `handler \u003cFunction\u003e` Called every time the state is updated\n\nThe input format is `R0`: see [bitfinex docs](https://docs.bitfinex.com/reference#ws-public-raw-books) for more details\n\nIf you want to manage state on your own, our just need a stream of updates, use\nthe `onOrderbook` handler.\n\n*Example:*\n\n```js\nconst pair = 'tBTCUST'\n\nws.onManagedOrderbook({ symbol: pair }, (ob) =\u003e {\n  console.log(`ws.onManagedOrderbook({ symbol: ${pair} })`)\n  console.log(ob)\n\n  ws.unsubscribeOrderbook(pair)\n})\n```\n\nRegistered for messages from the corresponding book channel (received on subscribe).\n\n#### `sunbeam.onManagedWallet(opts, handler)`\n  - `opts \u003cObject\u003e`\n  - `handler \u003cFunction\u003e` Called every time the state is updated\n\n*Example:*\n\n```js\nws.onManagedWallet({}, (mw) =\u003e {\n  console.log('ws.onManagedWallet')\n  console.log(mw)\n})\n\nws.auth()\n```\n\nRegistered for `ws`, `wu` messages via channel `0`.\nChannel is automatically subscribed by the API when doing an auth.\n\n#### `sunbeam.onManagedOrders(filter, handler)`\n  - `opts \u003cObject\u003e`\n  - `handler \u003cFunction\u003e` Called every time the state is updated\n\n*Example:*\n\n```js\nws.onManagedOrders({}, (orders) =\u003e {\n  console.log(orders)\n})\nws.auth()\n```\n\nRegistered for `os`, `on`, `ou`, `oc` messages via channel `0`.\n\n### Plain updates\n\nIf you want to manage state on your own, or have a special use case, you can\nuse unmanaged handlers.\n\n#### `sunbeam.onWallet(opts, handler)`\n  - `opts \u003cObject\u003e`\n  - `handler \u003cFunction\u003e` Called every time the state is updated\n\n*Example:*\n\n```js\nws.onWallet({}, (wu) =\u003e {\n  console.log('ws.onWallet')\n  console.log(wu)\n})\n\nws.auth()\n```\n\nRegistered for `ws`, `wu` messages via channel `0`.\nChannel is automatically subscribed by the API when doing an auth.\n\n#### `sunbeam.onOrders(opts, handler)`\n  - `opts \u003cObject\u003e`\n      `?symbol \u003cString\u003e` optional: filter by pair\n  - `handler \u003cFunction\u003e` The callback called for every update\n\n*Example:*\n\n```js\nconst pair = 'tBTCUST'\n\nws.onOrders({}, (data) =\u003e {\n  console.log('ws.onOrders({})')\n  console.log(data)\n})\n\n// filter enabled\nws.onOrders({ symbol: pair }, (data) =\u003e {\n  console.log(`ws.onOrders({ symbol: ${pair} })`)\n  console.log(data)\n})\n\nws.auth()\n```\n\nRegistered for `os`, `on`, `ou`, `oc` messages via channel `0`.\n\n#### `sunbeam.onPrivateTrades(opts, handler)`\n  - `opts \u003cObject\u003e`\n  - `handler \u003cFunction\u003e` The callback called for every update\n\n\nCalled when an own, submitted order matches.\n\n*Example:*\n\n```js\nws.onPrivateTrades({}, (data) =\u003e {\n  console.log('ws.onPrivateTrades({})')\n  console.log('private trade', data) // emits [ 'ETH.USD', 'te', [ '3', 1537196302500, -0.9, 1 ] ]\n})\n\nws.auth()\n```\n\nRegistered for `tu`, `te` messages via channel `0`.\n\n#### `sunbeam.onPublicTrades(opts, handler)`\n  - `opts \u003cObject\u003e`\n    - `?symbol \u003cString\u003e` optional: the symbol to emit the public trade updates for, i.e. `tBTCUST`\n  - `handler \u003cFunction\u003e` The callback called for every update\n\n*Example:*\n\n```js\nconst pair = 'tBTCUST'\n\nws.onPublicTrades({}, (data) =\u003e {\n  console.log(`ws.onPublicTrades({})`)\n  console.log('public trade', data)\n})\n\nws.onPublicTrades({ symbol: pair }, (data) =\u003e {\n  console.log(`ws.onPublicTrades({ symbol: ${pair} })`)\n  console.log('public trade', data)\n})\n\nws.subscribePublicTrades('tBTCUST')\n```\n\nRegistered for `tu`, `te` messages via the corresponding channel for the symbol.\n\n\n#### `sunbeam.onOrderbook(opts, handler)`\n  - `opts \u003cObject\u003e`\n    - `symbol \u003cString\u003e` The symbol to emit the orderbook update for, i.e. `tBTCUST`\n  - `handler \u003cFunction\u003e` The callback called for every update\n\nJust emits order updates and order snapshots without keeping or managing state.\n\n*Example:*\n\n```js\nconst pair = 'tBTCUST'\n\nws.onOrderbook({ symbol: pair }, (ob) =\u003e {\n  console.log(`ws.onOrderbook({ symbol: ${pair} })`)\n  console.log(ob)\n})\n\nws.subscribeOrderbook(pair)\n```\n\nRegistered for messages from the corresponding book channel (received on subscribe).\n\n## Standalone Managed State Helper\n\nSunbeam can take care of managing state snapshots for you, and keeps them up to date when the API sends updates.\nSometimes you may want to interact with Sunbeam's managed state. They are exposed through `this.state`\n\n```js\n\nws.state\n```\n\n## Setup your node\n\nStart nodeos:\n\n```\nnodeos --access-control-allow-origin \"*\" --verbose-http-error --http-validate-host=false --enable-stale-production --producer-name eosio --plugin eosio::chain_api_plugin --plugin eosio::net_api_plugin\n```\n\n`--contracts-console` will output the logging from custom contracts\n\n### Browsers\n\nEnable CORS for your EOS node, by enabling it via config:\n\n```\ncd ~/eosdata/\n\necho \"access-control-allow-origin = *\" \u003e\u003e config.ini\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitfinexcom%2Fsunbeam","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitfinexcom%2Fsunbeam","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitfinexcom%2Fsunbeam/lists"}