Skip to content

Commit

Permalink
✨ OHLC Price Bot, Tinyman + PactFi
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed May 20, 2022
1 parent fb9f9da commit 878e890
Show file tree
Hide file tree
Showing 14 changed files with 1,498 additions and 98 deletions.
10 changes: 9 additions & 1 deletion docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ services:
volumes:
- ./:/app
- ./docker.env:/app/.env
worker-price-pactfi:
volumes:
- ./:/app
- ./docker.env:/app/.env
worker-price-tinyman:
volumes:
- ./:/app
- ./docker.env:/app/.env
service:
volumes:
- ./:/app
Expand All @@ -36,4 +44,4 @@ services:
environment:
- REDIS_HOSTS=events:events:6379,queues:queues:6379
ports:
- "8081:8081"
- "8081:8081"
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ services:
- APP_CONTEXT=broker
command:
- start
worker-price-tinyman:
image: ghcr.io/algodex/algodex-node-gradation:${GHCR_TARGET}
entrypoint: npm
environment:
- APP_CONTEXT=tinyman
depends_on:
- events
- queues
command:
- start
worker-price-pactfi:
image: ghcr.io/algodex/algodex-node-gradation:${GHCR_TARGET}
entrypoint: npm
environment:
- APP_CONTEXT=pactfi
depends_on:
- events
- queues
command:
- start
worker:
image: ghcr.io/algodex/algodex-node-gradation:${GHCR_TARGET}
entrypoint: npm
Expand Down
87 changes: 82 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,97 @@
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/pouchdb.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/lightweight-charts.standalone.production.js"></script>
<style>
html{
background: #eeeee4;
}
</style>
</head>
<body>

<div id="root"><div id="data">⏳ Loading data...</div><div id="message">❌ Disconnected!</div></div>
<script>
function mapCouchToLightweight(rows){
return rows.map(kv=>{
const date = {
year: kv.key[1] || 0,
month: kv.key[2] || 0,
day: kv.key[3] || 0,
hour: kv.key[4] || 0,
minute: kv.key[5] || 0,
second: kv.key[6] || 0,
}
let time = new Date(`${date.month}/${date.day}/${date.year} ${date.hour}:${date.minute}:${date.second}`)
console.log({
open: kv.value.o,
close: kv.value.c,
low: kv.value.l,
high: kv.value.h,
time: time.getTime()/1000
// time: {year: kv.key[1], month: kv.key[2], day: kv.key[3], hour: kv.key[4]}
})
return {
open: kv.value.o,
close: kv.value.c,
low: kv.value.l,
high: kv.value.h,
time: time.getTime()/1000
// time: {year: kv.key[1], month: kv.key[2], day: kv.key[3], hour: kv.key[4]}
}
})
}
const chart = LightweightCharts.createChart(document.body, { width: 400, height: 300, timeScale: {
timeVisible: true,
secondsVisible: true,
} });
const lineSeries = chart.addCandlestickSeries({
upColor: 'rgb(38,166,154)',
downColor: 'rgb(255,82,82)',
wickUpColor: 'rgb(38,166,154)',
wickDownColor: 'rgb(255,82,82)',
borderVisible: false,
});
function setData(data){
document.getElementById('data').innerHTML = '✅ Loaded Data for 21582668'
lineSeries.setData(mapCouchToLightweight(data.rows));
chart.timeScale().fitContent()
}
function setMessage(msg){
document.getElementById('message').innerHTML = msg
}

const db = new PouchDB('http://localhost:5984/dex', {auth: {
username: 'admin',
password: 'dex'
}})
// _design/chart/_view/sieve
db.query('chart/sieve', {
reduce: true, group: true, group_level: 6,
startkey: [ 21582668 , 0, 0, 0, 0, 0, 0 ],
endkey: [ 21582668, Date.now(), 0, 0, 0, 0, 0 ],
}).then(function (res) {
// got the query results
setData(res)
}).catch(function (err) {
// some error
});

let retry = 0;
(
function run(){
setMessage('🚀 Connecting...')
console.log({
msg: '🚀 Connecting to Service...',
retry
});
const ws = new WebSocket('ws://localhost:9001/');
window.ws = ws;
ws.onopen = function () {
const msg = '⚡ Connected: Waiting for messages...'
setMessage(msg)
console.log({
msg: '🎉 Connected to Service!',
msg,
retry
});
// socket.send(`asset/${15322902}`);
Expand All @@ -27,14 +102,16 @@
// Listen for messages
ws.addEventListener('message', function (event) {
console.log({msg: '📝 Message Received', event: event.data});
document.body.innerHTML = event.data;
setMessage(`⬇ Message: ${event.data}`);
let {type} = JSON.parse(event.data);
if(type === 'SHUTDOWN') ws.close();
});

ws.onclose = function({reason}) {
const msg = '💥 Socket Closed'
setMessage(msg)
console.log({
msg: '💥 Socket Closing',
msg,
reason,
retry,
});
Expand All @@ -46,4 +123,4 @@
})();
</script>
</body>
</html>
</html>
Loading

0 comments on commit 878e890

Please sign in to comment.