Repository navigation
Expand file tree
/
Copy pathsend_receive.js
More file actions
54 lines (41 loc) · 1.67 KB
/
Copy pathsend_receive.js
File metadata and controls
54 lines (41 loc) · 1.67 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* eslint-disable prefer-const,no-loss-of-precision */
'use strict'
const proto = require('../proto/proto')
class MySender extends proto.Sender {
// noinspection JSUnusedLocalSymbols
onSend (buffer, offset, size) {
// Send nothing...
return 0
}
onSendLog (message) {
console.log(`onSend: ${message}`)
}
}
class MyReceiver extends proto.Receiver {
onReceive_OrderMessage (value) {} // eslint-disable-line
onReceive_BalanceMessage (value) {} // eslint-disable-line
onReceive_AccountMessage (value) {} // eslint-disable-line
onReceiveLog (message) {
console.log(`onReceive: ${message}`)
}
}
let sender = new MySender()
// Enable logging
sender.logging = true
// Create and send a new order
let order = new proto.Order(1, 'EURUSD', proto.OrderSide.buy, proto.OrderType.market, 1.23456, 1000.0)
sender.send(new proto.OrderMessage(order))
// Create and send a new balance wallet
let balance = new proto.Balance('USD', 1000.0)
sender.send(new proto.BalanceMessage(balance))
// Create and send a new account with some orders
let account = new proto.Account(1, 'Test', proto.State.good, new proto.Balance('USD', 1000.0), new proto.Balance('EUR', 100.0))
account.orders.push(new proto.Order(1, 'EURUSD', proto.OrderSide.buy, proto.OrderType.market, 1.23456, 1000.0))
account.orders.push(new proto.Order(2, 'EURUSD', proto.OrderSide.sell, proto.OrderType.limit, 1.0, 100.0))
account.orders.push(new proto.Order(3, 'EURUSD', proto.OrderSide.buy, proto.OrderType.stop, 1.5, 10.0))
sender.send(new proto.AccountMessage(account))
let receiver = new MyReceiver()
// Enable logging
receiver.logging = true
// Receive all data from the sender
receiver.receive(sender.buffer)