-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnodeplaystocksTask1.js
88 lines (77 loc) · 2.69 KB
/
nodeplaystocksTask1.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* PURPOSE: Store test data directly to InterSystems IRIS Data Platform.
*
* NOTES: When running, choose option 1 to store and retrieve test data. The test global should be 8888.
*/
const irisnative = require('intersystems-iris-native')
const readline = require('readline-sync');
const fs = require("fs");
// Helper method: Get connection details from config file
function GetConnections(filename){
var connections = {};
var array = fs.readFileSync(filename).toString().split("\n");
for(i in array) {
// Remove all spaces and split line based on colon
var details = array[i].replace(/\s/g, '').split(":")
connections[details[0]] = details[1]
}
return connections;
}
function main()
{
// Get connection details from connections.config
var connections = GetConnections("connections.config");
// Retrieve connection information from configuration file
var ip = connections["ip"];
var port = connections["port"];
var namespace = connections["namespace"];
var username = connections["username"];
var password = connections["password"];
// Create connection to InterSystems IRIS
const connection = irisnative.createConnection({host: ip, port: port, ns: namespace, user: username, pwd: password})
// Create InterSystems IRIS native object
const iris = connection.createIris()
console.log("Connected to InterSystems IRIS")
// Starting interactive prompt
while(true)
{
console.log("1. Test");
console.log("2. Store stock data");
console.log("3. View stock data");
console.log("4. Generate Trades");
console.log("5. Call routines");
console.log("6. Quit");
var selection = readline.question("What would you like to do? ")
switch(selection){
case "1":
SetTestGlobal(iris)
break;
case "2":
console.log("TO DO: Store stock data");
break;
case "3":
console.log("TO DO: View stock data");
break;
case "4":
console.log("TO DO: Generate trades");
break;
case "5":
console.log("TO DO: Call routines");
break;
case "6":
console.log("Exited");
return;
default:
console.log("Invalid option. Try again!");
break;
}
}
}
// Write to a test global
function SetTestGlobal(irisNative)
{
irisNative.set(8888, "^testglobal", "1");
globalValue = irisNative.get("^testglobal", "1");
console.log("The value of ^testglobal(1) is " + globalValue);
}
main()