Putting transactions information into MariaDB

Hi Guys,

Hope you also had a lovely weekend!

It’s time to work a liitle bit and today’s very natural next step is about to store into database transactions from GDax.

Let’s first create a new table to store results:

CREATE TABLE gdax_matches (

id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
size FLOAT (15,8) NOT NULL,
product_id CHAR (7) NOT NULL,
price FLOAT (15,8) NOT NULL,
time DATETIME NOT NULL,

INDEX (product_id),
INDEX (time)
);

It shouldn’t be hard to write a few lines of code in NodeJS. Google is my friend here.

So here it goes:

const websocketCallback = (data) => console.dir(data);
websocket.on('message', storeResult);
websocket.on('error', websocketCallback);

function storeResult( data ) {
if ( data.type != 'match' ) return;

var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'user',
password : 'secret',
database : 'dbname'
});

connection.connect();

var data2 = {};
data2.size = data.size;
data2.price = data.price;
data2.time = data.time;
data2.product_id = data.product_id;

connection.query('INSERT INTO gdax_matches SET ?', data2, function (error, results, fields) {
if (error) throw error;
console.log(data2);
});

}

Now it’s time to run the script:

forever start transactions.js

And it’s working:

| 8 | 0.00707114 | BTC-USD | 6755.79003906 | 2018-07-08 19:59:58 |
| 9 | 0.00700682 | BTC-USD | 6755.79003906 | 2018-07-08 19:59:59 |
| 10 | 0.01274750 | BTC-USD | 6755.79003906 | 2018-07-08 20:00:02 |
| 11 | 0.01060598 | BTC-USD | 6755.79003906 | 2018-07-08 20:00:05 |
| 12 | 0.00137000 | BTC-USD | 6755.77978516 | 2018-07-08 20:00:07 |
| 13 | 0.00113000 | BTC-USD | 6755.77978516 | 2018-07-08 20:00:07 |
| 14 | 0.01550000 | BTC-USD | 6755.00000000 | 2018-07-08 20:00:07 |
| 15 | 0.01287671 | BTC-USD | 6755.00976562 | 2018-07-08 20:00:14 |
| 16 | 0.00560000 | BTC-USD | 6755.00000000 | 2018-07-08 20:00:19 |
| 17 | 0.00103259 | BTC-USD | 6755.00976562 | 2018-07-08 20:00:27 |
| 18 | 0.01841419 | BTC-USD | 6755.00976562 | 2018-07-08 20:00:28 |
| 19 | 0.05730000 | BTC-USD | 6755.00976562 | 2018-07-08 20:00:32 |
| 20 | 0.01451356 | BTC-USD | 6755.00976562 | 2018-07-08 20:00:37 |
| 21 | 0.00184032 | BTC-USD | 6755.00976562 | 2018-07-08 20:00:44 |
| 22 | 0.04427864 | BTC-USD | 6755.00976562 | 2018-07-08 20:01:03 |
| 23 | 0.00160000 | BTC-USD | 6755.00000000 | 2018-07-08 20:01:08 |
| 24 | 0.01000000 | BTC-USD | 6755.00976562 | 2018-07-08 20:01:17 |
| 25 | 1.32224405 | BTC-USD | 6755.00976562 | 2018-07-08 20:01:20 |
| 26 | 0.00400000 | BTC-USD | 6755.00976562 | 2018-07-08 20:01:20 |
| 27 | 0.12515602 | BTC-USD | 6755.00976562 | 2018-07-08 20:01:20 |
| 28 | 0.00190000 | BTC-USD | 6755.00000000 | 2018-07-08 20:01:30 |
| 29 | 0.00229349 | BTC-USD | 6755.00976562 | 2018-07-08 20:01:31 |

Let it run for a few days!

Thanks for reading,
Łukasz.

PS: please ignore ugliest possible codes. it’s all about Proof Of Concept, not the nicest codes.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s