-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.js
More file actions
39 lines (35 loc) · 1.19 KB
/
example.js
File metadata and controls
39 lines (35 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* @file example.js
* @description Example on how to use the BorsdataAPI class.
* @author ReineW
* @license MIT
* @link https://github.com/reinew/borsdata-api-js
*
* All sample code is provided for illustrative purposes only.
* These examples have not been thoroughly tested under all conditions.
* The creator cannot guarantee or imply reliability, serviceability, or function of this class.
* All code contained herein are provided to you “AS IS” without any warranties of any kind.
*
* This simple example imports the API class file, initiates the class,
* returns an object of all instruments and prints the result in json format.
*
* Run this script with the following command: node example.js
*/
// Import the API class file.
import BorsdataAPI from "./BorsdataAPI.js"
// Initiate methods from BorsdataAPI class.
const borsdata = new BorsdataAPI()
// Async function to get all instruments.
async function getInstruments() {
try {
const data = await borsdata.getAllInstruments("instruments")
return data.instruments
} catch (error) {
console.error(error)
process.exit(1)
}
}
// Call the async function and print the result.
getInstruments().then((data) => {
console.log(data)
})