Catalog npm
Back to packageRELEASE DETAILS

4.0.9

npm

@0x/order-watcher

An order watcher daemon that watches for order validity

0x0xprojectethereumexchangeorderbook
Published14 May 2019
Direct dependencies43
Transitive dependenciesNot calculated

README

Current package documentation

OrderWatcher [Deprecated]

:no_entry: WARNING: This project is deprecated. Please use 0x Mesh for all your orderbook pruning needs. It can be used with or without order sharing enabled. If you have any questions about how to use Mesh, reach out to us in the #mesh channel on Discord :no_entry:

An order watcher daemon that watches for order validity.

Read the wiki article.

OrderWatcher also comes with a WebSocket server to provide language-agnostic access to order watching functionality. We used the WebSocket Client and Server Implementation for Node. The server sends and receives messages that conform to the JSON RPC specifications.

Installation

Install

npm install @0x/order-watcher --save

Import

import { OrderWatcher } from '@0x/order-watcher';

If your project is in TypeScript, add the following to your tsconfig.json:

"compilerOptions": {
    "typeRoots": ["node_modules/@0x/typescript-typings/types", "node_modules/@types"],
}

Using the WebSocket Server

Setup

Environmental Variables Several environmental variables can be set to configure the server:

  • ORDER_WATCHER_HTTP_PORT specifies the port that the http server will listen on and accept connections from. When this is not set, we default to 8080.

Requests The server accepts three types of requests: ADD_ORDER, REMOVE_ORDER and GET_STATS. These mirror what the underlying OrderWatcher does. You can read more in the wiki. Unlike the OrderWatcher, it does not expose any subscribe or unsubscribe functionality because the WebSocket server keeps a single subscription open for all clients.

The first step for making a request is establishing a connection with the server. In Javascript:

var W3CWebSocket = require('websocket').w3cwebsocket;
wsClient = new W3CWebSocket('ws://127.0.0.1:8080');

In Python, you could use the websocket-client library and run:

from websocket import create_connection
wsClient = create_connection("ws://127.0.0.1:8080")

With the connection established, you prepare the payload for your request. The payload is a json object with a format established by the JSON RPC specification:

  • id: All requests require you to specify a numerical id. When the server responds to the request, the response will have the same id as the one supplied with your request.
  • jsonrpc: This is always the string '2.0'.
  • method: This specifies the OrderWatcher method you want to call. I.e., 'ADD_ORDER', 'REMOVE_ORDER' or 'GET_STATS'.
  • params: These contain the parameters needed by OrderWatcher to execute the method you called. For ADD_ORDER, provide { signedOrder: <your signedOrder> }. For REMOVE_ORDER, provide { orderHash: <your orderHash> }. For GET_STATS, no parameters are needed, so you may leave this empty.

Next, convert the payload to a string and send it through the connection. In Javascript:

const addOrderPayload = {
    id: 1,
    jsonrpc: '2.0',
    method: 'ADD_ORDER',
    params: { signedOrder: <your signedOrder> },
};
wsClient.send(JSON.stringify(addOrderPayload));

In Python:

import json
remove_order_payload = {
    'id': 1,
    'jsonrpc': '2.0',
    'method': 'REMOVE_ORDER',
    'params': {'orderHash': '0x6edc16bf37fde79f5012088c33784c730e2f103d9ab1caf73060c386ad107b7e'},
}
wsClient.send(json.dumps(remove_order_payload));

Response The server responds to all requests in a similar format. In the data field, you'll find another object containing the following fields:

  • id: The id corresponding to the request that the server is responding to. UPDATE responses are not based on any requests so the id field is omitted`.
  • jsonrpc: Always '2.0'.
  • method: The method the server is responding to. Eg. ADD_ORDER. When order states change the server may also initiate a response. In this case, method will be listed as UPDATE.
  • result: This field varies based on the method. UPDATE responses contain the new order state. GET_STATS responses contain the current order count. When there are errors, this field is omitted.
  • error: When there is an error executing a request, the JSON RPC error object is listed here. When the server responds successfully, this field is omitted.

In Javascript, the responses can be parsed using the onmessage callback:

wsClient.onmessage = (msg) => {
    const responseData = JSON.parse(msg.data);
    const method = responseData.method
};

In Python, recv is a lightweight way to receive a response:

result = wsClient.recv()
method = result.method

Contributing

We strongly recommend that the community help us make improvements and determine the future direction of the protocol. To report bugs within this package, please create an issue in this repository.

Please read our contribution guidelines before getting started.

Install dependencies

If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:

yarn config set workspaces-experimental true

Then install dependencies

yarn install

Build

To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory:

PKG=@0x/order-watcher yarn build

Or continuously rebuild on change:

PKG=@0x/order-watcher yarn watch

Clean

yarn clean

Lint

yarn lint

Run Tests

yarn test

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 43

Native requirements
43 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
ethers
Environment
{
  "local_name": "ethers",
  "alias": false,
  "peer_metadata": null
}
~4.0.4runtime
lodash
Environment
{
  "local_name": "lodash",
  "alias": false,
  "peer_metadata": null
}
^4.17.11runtime
bintrees
Environment
{
  "local_name": "bintrees",
  "alias": false,
  "peer_metadata": null
}
^1.0.2runtime
@0x/types
Environment
{
  "local_name": "@0x/types",
  "alias": false,
  "peer_metadata": null
}
^2.2.2runtime
@0x/utils
Environment
{
  "local_name": "@0x/utils",
  "alias": false,
  "peer_metadata": null
}
^4.3.3runtime
websocket
Environment
{
  "local_name": "websocket",
  "alias": false,
  "peer_metadata": null
}
^1.0.26runtime
@0x/assert
Environment
{
  "local_name": "@0x/assert",
  "alias": false,
  "peer_metadata": null
}
^2.0.10runtime
ethereum-types
Environment
{
  "local_name": "ethereum-types",
  "alias": false,
  "peer_metadata": null
}
^2.1.2runtime
@0x/order-utils
Environment
{
  "local_name": "@0x/order-utils",
  "alias": false,
  "peer_metadata": null
}
^8.0.2runtime
@0x/json-schemas
Environment
{
  "local_name": "@0x/json-schemas",
  "alias": false,
  "peer_metadata": null
}
^3.0.10runtime
@0x/web3-wrapper
Environment
{
  "local_name": "@0x/web3-wrapper",
  "alias": false,
  "peer_metadata": null
}
^6.0.6runtime
@0x/base-contract
Environment
{
  "local_name": "@0x/base-contract",
  "alias": false,
  "peer_metadata": null
}
^5.1.0runtime
@0x/fill-scenarios
Environment
{
  "local_name": "@0x/fill-scenarios",
  "alias": false,
  "peer_metadata": null
}
^3.0.8runtime
@0x/abi-gen-wrappers
Environment
{
  "local_name": "@0x/abi-gen-wrappers",
  "alias": false,
  "peer_metadata": null
}
^4.3.0runtime
@0x/contract-wrappers
Environment
{
  "local_name": "@0x/contract-wrappers",
  "alias": false,
  "peer_metadata": null
}
^9.1.2runtime
semaphore-async-await
Environment
{
  "local_name": "semaphore-async-await",
  "alias": false,
  "peer_metadata": null
}
^1.5.1runtime
@0x/contract-addresses
Environment
{
  "local_name": "@0x/contract-addresses",
  "alias": false,
  "peer_metadata": null
}
^2.3.3runtime
@0x/contract-artifacts
Environment
{
  "local_name": "@0x/contract-artifacts",
  "alias": false,
  "peer_metadata": null
}
^1.5.1runtime
@0x/typescript-typings
Environment
{
  "local_name": "@0x/typescript-typings",
  "alias": false,
  "peer_metadata": null
}
^4.2.2runtime
ethereumjs-blockstream
Environment
{
  "local_name": "ethereumjs-blockstream",
  "alias": false,
  "peer_metadata": null
}
6.0.0runtime
nyc
Environment
{
  "local_name": "nyc",
  "alias": false,
  "peer_metadata": null
}
^11.0.1development
shx
Environment
{
  "local_name": "shx",
  "alias": false,
  "peer_metadata": null
}
^0.2.2development
chai
Environment
{
  "local_name": "chai",
  "alias": false,
  "peer_metadata": null
}
^4.0.1development
mocha
Environment
{
  "local_name": "mocha",
  "alias": false,
  "peer_metadata": null
}
^4.1.0development
sinon
Environment
{
  "local_name": "sinon",
  "alias": false,
  "peer_metadata": null
}
^4.0.0development
tslint
Environment
{
  "local_name": "tslint",
  "alias": false,
  "peer_metadata": null
}
5.11.0development
opn-cli
Environment
{
  "local_name": "opn-cli",
  "alias": false,
  "peer_metadata": null
}
^3.1.0development
dirty-chai
Environment
{
  "local_name": "dirty-chai",
  "alias": false,
  "peer_metadata": null
}
^2.0.1development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
3.0.1development
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
*development
npm-run-all
Environment
{
  "local_name": "npm-run-all",
  "alias": false,
  "peer_metadata": null
}
^4.1.2development
@types/mocha
Environment
{
  "local_name": "@types/mocha",
  "alias": false,
  "peer_metadata": null
}
^2.2.42development
@types/sinon
Environment
{
  "local_name": "@types/sinon",
  "alias": false,
  "peer_metadata": null
}
^2.2.2development
@0x/dev-utils
Environment
{
  "local_name": "@0x/dev-utils",
  "alias": false,
  "peer_metadata": null
}
^2.2.2development
@types/lodash
Environment
{
  "local_name": "@types/lodash",
  "alias": false,
  "peer_metadata": null
}
4.14.104development
@0x/migrations
Environment
{
  "local_name": "@0x/migrations",
  "alias": false,
  "peer_metadata": null
}
^4.1.4development
chai-bignumber
Environment
{
  "local_name": "chai-bignumber",
  "alias": false,
  "peer_metadata": null
}
^3.0.0development
@types/bintrees
Environment
{
  "local_name": "@types/bintrees",
  "alias": false,
  "peer_metadata": null
}
^1.0.2development
@0x/subproviders
Environment
{
  "local_name": "@0x/subproviders",
  "alias": false,
  "peer_metadata": null
}
^4.0.6development
chai-as-promised
Environment
{
  "local_name": "chai-as-promised",
  "alias": false,
  "peer_metadata": null
}
^7.1.0development
@0x/tslint-config
Environment
{
  "local_name": "@0x/tslint-config",
  "alias": false,
  "peer_metadata": null
}
^3.0.1development
make-promises-safe
Environment
{
  "local_name": "make-promises-safe",
  "alias": false,
  "peer_metadata": null
}
^1.1.0development
source-map-support
Environment
{
  "local_name": "source-map-support",
  "alias": false,
  "peer_metadata": null
}
^0.5.0development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "760fd24043a12d5f4dbd17a79b18770dffbace69",
  "tarball": "https://registry.npmjs.org/@0x/order-watcher/-/order-watcher-4.0.9.tgz",
  "fileCount": 92,
  "integrity": "sha512-iD1JC0BgisdsaH7eAfCX6eKxjirQVEUoTF6iv3UWwF1dCgLV/xMLdafWSX2KYABX8NaA5ptp9gKmwUNGXRGOGw==",
  "signatures": [
    {
      "sig": "MEQCID+RhoUt1zEQhL7XEmygtjmVcZ8bUywe556h41u13Ex/AiBkvqhggzAmuQQ0K2jaOUs3firTtznITp5QH/aNGjGC4A==",
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
    }
  ],
  "unpackedSize": 353142,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc2iS6CRA9TVsSAnZWagAAHLkP/2gxKwAia9pwzF5rVHzP\nmvlHlu+pD6Gsu4qxx/MihlBQeZ+B7vITvqGAtmmwtEoB1/K06CcgmdqPIUca\nFdD64tpZG47dMPKhNftHeM3tP2AdnY6z3heaUR9IQINmG+cXx7YUi/uXDomN\nwEg/cBYhuLojm6szX05cq9bpbTs8/dzVW3Cp0Yx7QBihlBABBiML1uC4g59o\njUFAlxg1HRRiE0o04zYkL7CeMVx80MPkbexRm3oeFW9geal0xbbKGIdPgQYd\nkv7Am4twh/k3ZVJ8df7K5NgFJZrI+m7KcsKKSWZW/ADxehRJqeCR9zZL77co\n8XlS71J0OjfSXnnOaHkAECKEATZRpytfxSBBGx2yLM1FhwvoV8GWzWNpLSvJ\nWyHXpOZ2wV0fLWCUWrH/vgC6jWiOcVnX2/fz9LjRpP8SY7bndidsqDFftygn\nHuoi+nubNx04kQ0VQOudV/fE3+dQG4+nzFXC0VYlokbIO+AK7ZaGmxgXKmE+\nFMo2t8MDRjjHHO9U/h67zegWfyxNnLlKgCtdrxCCSXtGGTFBba14rZzgFcD4\n1b5gbSbZa8UFXXfVHK53ZVioOsMhz/hz5fvBkzAFYs7V17ZSFlf60f0rE1fw\nO5JOz39zZIT0UByvNgt10vX0/xA/r1FqIobCcj5NbX1cLf74+i4N1wAJEJU/\nGOTJ\r\n=ZdQc\r\n-----END PGP SIGNATURE-----\r\n"
}

Repository

PENDING
0xproject/0x-monorepo

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:28 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:93bb98e08159dc353d2b7924fa6b1c4e96e013763799633db86951794e717455

Other collected versions

4.0.178 Aug4.0.1631 Jul4.0.1524 Jul4.0.1415 Jul4.0.1313 Jul4.0.1213 JulView all collected versions →