HI there, I’m quite new to Meteor, sorry if this is really dumb!
Basically, I am trying to get a wss feed going from Poloniex, and update a collection with it so that I can have ‘latest’ prices in a collection, I have for now called Maindb. I got the wss working and am just trying to insert some of the data in the collection to see if it works, but it doesn’t and I can’t figure out why!
Note: The collection works, I’ve manually inserted a record with the shell.
Here is the code I have now:
import { Meteor } from 'meteor/meteor';
import * as autobahn from "autobahn";
import { Mongo } from 'meteor/mongo'
import { SimpleSchema } from 'meteor/aldeed:simple-schema'
Maindb = new Mongo.Collection('maindb');
Maindb.schema = new SimpleSchema({
place: {type: String},
pair: {type: String},
last: {type: Number, defaultValue: 0}
});
Meteor.startup(() => {
var wsuri = "wss://api.poloniex.com";
var poloniexConnection = new autobahn.Connection({
url: wsuri,
realm: "realm1"
});
poloniexConnection.onopen = Meteor.bindEnvironment(function(session) {
var tickerEvent = function(args,kwargs) {
console.log(args[0]);
Maindb.insert({place: 'Poloniex', pair: args[0]});
}
session.subscribe('ticker', tickerEvent);
poloniexConnection.onclose = function () {
console.log("Websocket connection closed");
}
});
poloniexConnection.open();
});
The console logs the data feed, but the insert doesn’t work.
Does anyone know what could be happening ? I tried wrapping the tickerEvent function in the Meteor.bindEnvironment without success.