summaryrefslogtreecommitdiff
path: root/assets/trading-in-the-rain/CW.js
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2021-01-21 17:22:53 -0700
committerBrian Picciano <mediocregopher@gmail.com>2021-01-21 17:22:53 -0700
commitbcf9b230be6d74c71567fd0771b31d47d8dd39c7 (patch)
tree2d0fc16142d55bbd5876ac6b8174c2857883b40e /assets/trading-in-the-rain/CW.js
parentd57fd70640948cf20eeb41b56e8d4e23e616cec0 (diff)
build the blog with nix
Diffstat (limited to 'assets/trading-in-the-rain/CW.js')
-rw-r--r--assets/trading-in-the-rain/CW.js43
1 files changed, 0 insertions, 43 deletions
diff --git a/assets/trading-in-the-rain/CW.js b/assets/trading-in-the-rain/CW.js
deleted file mode 100644
index 043c1a8..0000000
--- a/assets/trading-in-the-rain/CW.js
+++ /dev/null
@@ -1,43 +0,0 @@
-function CW(resource) {
- this.conn = new WebSocket('wss://stream.cryptowat.ch/connect?apikey=GPDLXH702E1NAD96OSBO');
- this.conn.binaryType = "arraybuffer";
-
- this.conn.onopen = () => {
- console.log("CW websocket connected");
- if (this.onconnect) this.onconnect();
- }
-
- let decoder = new TextDecoder();
- this.conn.onmessage = (msg) => {
- let d = JSON.parse(decoder.decode(msg.data));
-
- // The server will always send an AUTHENTICATED signal when you establish a valid connection
- // At this point you can subscribe to resources
- if (d.authenticationResult && d.authenticationResult.status === 'AUTHENTICATED') {
- if (this.onauth) this.onauth();
- this.conn.send(JSON.stringify({
- subscribe: {
- subscriptions: [
- {streamSubscription: {resource: resource}},
- ],
- }
- }));
- return;
- }
-
- // Market data comes in a marketUpdate
- // In this case, we're expecting trades so we look for marketUpdate.tradesUpdate
- if (!d.marketUpdate || !d.marketUpdate.tradesUpdate) {
- return;
- }
-
- let trades = d.marketUpdate.tradesUpdate.trades;
- for (let i in trades) {
- trades[i].price = parseFloat(trades[i].priceStr);
- trades[i].volume = parseFloat(trades[i].amountStr);
- }
- if (this.ontrades) this.ontrades(trades);
- }
-
- this.close = () => this.conn.close();
-}