衍生API
用于衍生应用的 Async Websocket API
要求:
节点.js(建议采用v12.18.0或更高)
安装
安装 Deriv API 库
我们需要安装 Deriv API 库, 如果我们想要连接 Deriv 的网络锁.
国家预防机制
npm install @deriv/deriv-api
线条
yarn add @deriv/deriv-api
安装 Websocket (ws) 库
为了建立网锁连接,我们需要网锁库(ws).
国家预防机制
npm install ws
线条
yarn add ws
使用量
基本图书馆
基础库是Deriv API的较轻版本,适合应用 想要直接处理API电话.
也可以作为单独的模块导入(以减少最后捆绑大小)
或如果 DerivAPI 库已经导入,可使用 api.basic。 。 。 .
const WebSocket = require('ws');
const DerivAPI = require('@deriv/deriv-api/dist/DerivAPI');
// app_id 1089 is for testing, create your own app_id and use it here.
// go to api.deriv.com to register your own app.
const connection = new WebSocket('wss://ws.derivws.com/websockets/v3?app_id=1089');
const api = new DerivAPI({ connection });
const basic = api.basic;
basic.ping().then(console.log);
ES6模块
基本 API
// Smaller bundle size, dealing only with the low-level library
import DerivAPIBasic from '@deriv/deriv-api/dist/DerivAPIBasic.js';
import WebSocket from 'ws';
// app_id 1089 is for testing, create your own app_id and use it here.
// go to api.deriv.com to register your own app.
const connection = new WebSocket('wss://ws.derivws.com/websockets/v3?app_id=1089');
const api = new DerivAPIBasic({ connection });
api.ping().then(console.log);
通用JS模块
基本 API
// Smaller bundle size, dealing only with the low-level library
const WebSocket = require('ws');
const DerivAPIBasic = require('@deriv/deriv-api/dist/DerivAPIBasic');
// app_id 1089 is for testing, create your own app_id and use it here.
// go to api.deriv.com to register your own app.
const connection = new WebSocket('wss://ws.derivws.com/websockets/v3?app_id=1089');
const api = new DerivAPIBasic({ connection });
api.ping().then(console.log);
使用 HTML 脚本标签
基本 API
<script src="https://unpkg.com/@deriv/deriv-api/dist/DerivAPIBasic.js"></script>
<script>
const api = new DerivAPIBasic({
endpoint: 'ws.derivws.com',
app_id: 1089 /* 1089 is a default test app_id, replace with your own app_id */,
lang: 'EN'
});
api.ping().then(console.log);
</script>
创建 WebSocket 连接
建立联系有两种方式:
-
使用先前打开的连接 :
const connection = new WebSocket('wss://ws.derivws.com/websockets/v3?app_id=YOUR_APP_ID'); const api = new DerivAPI({ connection }); -
传递创建连接所需的参数 :
const api = new DerivAPI({ endpoint: 'ws.derivws.com', app_id: /* your app_id */, lang: 'EN' });
文档
维基
关于如何在 DELIV API 中使用 维基页面。 。 。 .
API 参考
完整 API 参考主机 这里
在一页中提到: 衍生API 参考
发展
git clone https://github.com/binary-com/deriv-api
cd deriv-api
npm install
做测试
npm test
在源代码编辑中自动运行测试
npm run devel
运行插件
npm run syntax
运行所有测试( lint + js 测试)
npm run test_all
设定代码( 自动执行)
npm run prettify
生成文档
npm run docs
编辑源代码时自动重生成文件
需求 inotify 工作的时候.
npm run devel_docs
在本地主机上服务文件并更新源代码更改
npm run serve_docs
生成文档的 html 版本并发布到 gh- pages
npm run gh-pages
构建软件包
npm run build
运行示例
DERIV_TOKEN=YourTokenHere npm run examples