forked from nocaremc/nodex-ws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
126 lines (102 loc) · 3.63 KB
/
app.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
I'm doing little more than scratching out examples as I go along in this file
*/
const dotenv = require('dotenv')
const log = require('./src/Log.js')
const API = require('./src/API.js')
// Load environment variables
dotenv.load()
// Instantiate api, connecting to rpc node
let api = new API(process.env.RPC_NODE, {perMessageDeflate: false})
api.on("open", () => {
log.success("Websocket ready")
api.login(process.env.DEX_USER, process.env.DEX_PASS, result => {
//log.info("login was " + result)
})
api.database(database => {
// Here we'll wait for the db api to be initialized
log.success("Database initialized")
// Obtain user_id for a given username
// api.database_api.get_account_by_name(process.env.DEX_USER, result => {
// log.warn(result)
// })
// Let's grab a list of assets we care about
// api.database_api.lookup_asset_symbols(process.env.ASSET_SYMBOLS, result => {
// log.warn(result)
// })
// Grab limit orders for bts:cny (unsure on base/quote)
// api.database_api.get_limit_orders('1.3.0', '1.3.113', 20, result => {
// log.warn(result)
// })
// Grab ticker price for bts:cny
// api.database_api.get_ticker('1.3.0', '1.3.113', result => {
// log.warn(result)
// })
// Get account balance for cny and usd
// api.database_api.get_account_balances(
// process.env.DEX_USER_ID,
// ['1.3.0', '1.3.113'],
// result => {
// log.warn(result)
// }
// )
//api.database_api.get_assets(['1.3.113', '1.3.0'], assets => {
//log.error(assets)
//})
// Get some random objects
// api.database_api.get_objects(["2.4.21","2.4.83"], objects => {
// log.warn(objects)
// })
// Get block header
// api.database_api.get_block_header(24614236, block_header => {
// log.warn(block_header)
// })
// Get block's headers
// api.database_api.get_block_header_batch([24614236, 24614695], block_headers => {
// log.warn(block_headers)
// })
// Get block
// api.database_api.get_block(24614236, block => {
// log.warn(block)
// })
// Get a transaction from a block
api.database_api.get_transaction(24614807, 1, transaction => {
log.warn(transaction)
})
})
})
let x = false
// Doing something with assets after knowing they exist
api.on('store.assets.stored',() => {
if(!x) {
//log.warn(api.getStoredAssets(['CNY', 'BTS']))
x = true
}
//log.warn(api.getStoredAsset('CNY'))
//api.database_api.lookup_asset_symbols(process.env.ASSET_SYMBOLS)
})
api.on("message", data => {
if(data.id === 1005) {
//log.error(data)
} else {
//log.warn(data)
}
})
// How might be best to sanely close connection?
/*
let wallet = new Wallet(process.env.WALLET_NODE)
// This wallet is new, let's set it up
// You will need a password set before anything else can be done
wallet.on("is_new", result => {
wallet.set_password(process.env.WALLET_PASS)
})
// We've detected that a password has been set
// unlock wallet before proceeding
wallet.on('init', () => {
wallet.unlock(process.env.WALLET_PASS)
})
wallet.on('unlocked', () => {
// Determine if our target account exists in the wallet already
// It is not until this point a wallet.json file is created by wallet_cli
wallet.import_key(process.env.DEX_USER, process.env.DEX_WIF)
})*/