-
Notifications
You must be signed in to change notification settings - Fork 26
/
payed-orderbooks-lnd.js
47 lines (36 loc) · 1.17 KB
/
payed-orderbooks-lnd.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
'use strict'
const dazaar = require('dazaar')
const swarm = require('dazaar/swarm')
const Payment = require('@dazaar/payment-lightning')
const terms = require('bitfinex-terminal-terms-of-use')
const Orderbook = require('bitfinex-terminal-order-book')
const card = require('../cards/paid/orderbooks/bitfinex.terminal.btcusd.orderbook.json')
const market = dazaar('dbs/terminal-orderbook-btcusd-lnd')
const buyer = market.buy(card, { sparse: false, terms })
buyer.on('feed', function () {
console.log('got feed')
const o = new Orderbook(buyer.feed)
doQuery(o)
})
buyer.ready(function () {
console.log('ready')
const payment = new Payment(buyer)
payment.requestInvoice(100, function (err, invoice) {
if (err) console.log(err)
console.log(invoice)
})
swarm(buyer)
})
async function doQuery (o) {
const s = o.createReadStream({
start: new Date().getTime() - (1000 * 60 * 10),
live: true
})
// alternative: range query with max 5 results:
// const start = new Date().getTime() - (1000 * 60 * 5)
// const end = Date.now()
// const s = o.createReadStream({ limit: 5, start, end })
for await (const data of s) {
console.log('--->', data)
}
}