@0x/order-watcher

中文文档
4.0.17发布于 2019/08/09Apache-2.0TypeScriptCommonJS近 30 天下载 2484

An order watcher daemon that watches for order validity

原始使用文档
文档目录9 节
  1. OrderWatcher [Deprecated]
  2. Installation
  3. Using the WebSocket Server
  4. Contributing
  5. Install dependencies
  6. Build
  7. Clean
  8. Lint
  9. Run Tests

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

版本与发布记录

@0x/order-watcher 共发布 36 个版本,首次发布于 2018/10/18;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.0.17latest2019/08/097 年前
4.0.162019/08/017 年前
4.0.152019/07/247 年前
4.0.142019/07/157 年前
4.0.132019/07/147 年前
4.0.122019/07/137 年前

关于 @0x/order-watcher 的常见问题

@0x/order-watcher 是什么?

An order watcher daemon that watches for order validity

如何安装 @0x/order-watcher?

在项目目录运行 npm install @0x/order-watcher,或使用 pnpm add / yarn add / bun add。

@0x/order-watcher 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@0x/order-watcher 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@0x/order-watcher 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=6.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@0x/order-watcher 可以商用吗?

@0x/order-watcher 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@0x/order-watcher 的下载量有多少?

根据 npm 官方下载统计,@0x/order-watcher 在 2026/10/04 – 2026/11/02 这 30 天内被下载 2,484 次,日均约 83 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@0x/order-watcher 还在维护吗?

最新版本 4.0.17 发布于 2019/08/09(7 年前);至今共发布 36 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/10/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。