client-lib
The JavaScript client library for the core backend. The client library abstracts away the HTTP request details such as names of the endpoints, the selection of HTTP verbs, whether an input is in the request body or query parameters, and so forth. In addition, typing is provided for both input and output. The goal is to simplify the user exeperience of interacting with the core.
Installation
https://www.npmjs.com/package/trading-client
npm install trading-client
Getting Started
Setting up the client
const { Client } = require("trading-client");
const fetch = require("node-fetch");
const client = new Client({
fetchFunction: fetch,
accessToken: "<my access token>"
});
fetchFunction
: You will need to provide your own fetch function.
It is recommended to use node-fetch.
accessToken
: This is what is used to determine your identity. The access token for UI users can be found in request headers made from the UI.
Additional access tokens must be acquired by requesting them directly from the admin.
Currently, there is no self service token distribution.
host (optional)
: The url of the core, such as http://localhost:8080
. This can be used to switch the environments from production to local when testing with a local backend.
Examples
Searching an item with the name starting with "app"
const items = await client.searchItems("app");
Buying an apple for 3 coins:
await client.submitOrder(myUserId, OrderType.BUY, apple, 1, 3);
Retrieving my 2 most recent transactions
const transactions = await client.listTransactions(myUserId, 2);
Contributing
Test
Select Node version
nvm use
Install dependencies
npm install
Run tests
npm test
Build
npm run build
This creates the JavaScript output in ./dist
, along with the types and source maps.
Publish
npm publish --access public