client lib for trading platform
npm install trading-clientThe 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.
https://www.npmjs.com/package/trading-client
```
npm install trading-client
Setting up the client
`javascript
const { Client } = require("trading-client");
const fetch = require("node-fetch");
const client = new Client({
fetchFunction: fetch,
accessToken: "
});
`
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.
Searching an item with the name starting with "app"
`javascript`
const items = await client.searchItems("app");
Buying an apple for 3 coins:
`javascript`
await client.submitOrder(myUserId, OrderType.BUY, apple, 1, 3);
Retrieving my 2 most recent transactions
`javascript`
const transactions = await client.listTransactions(myUserId, 2);
Select Node version
``
nvm use
Install dependencies
``
npm install
Run tests
``
npm test
``
npm run build
This creates the JavaScript output in ./dist, along with the types and source maps.
```
npm publish --access public