Skip to content

Instantly share code, notes, and snippets.

@carlosgj94 carlosgj94/augur.js
Last active Jun 10, 2019

Embed
What would you like to do?
const Augur = require('augur.js');
const augur = new Augur();
const augurConnection = 'ws://predictions.market:9001';
const connect = () => new Promise((resolve, reject) => {
augur.augurNode.connect(
augurConnection,
(error, wsTransport) => {
if (error) reject(error);
resolve(wsTransport);
},
);
});
const getMarketsInfo = marketIds => new Promise((resolve, reject) => {
augur.markets.getMarketsInfo(
{
marketIds,
},
(error, markets) => {
if (error) reject(error);
resolve(markets);
},
);
});
const getOpenOrders = marketId => new Promise((resolve, reject) => {
augur.trading.getOrders(
{
marketId,
orderState: 'OPEN',
sortBy: 'fullPrecisionPrice',
},
(error, orders) => {
if (error) reject(error);
resolve(orders);
},
);
});
const flatOrders = orders => Object.keys(orders).map(orderHash => orders[orderHash])
;(async () => {
const coolMarkets = [
'0xc34aaf15e2b0eb72e4db436ee9e304f35e392886',
'0x8499fca0a811ede100c36a438dca755bc89c1fc3',
];
try {
await connect();
const [
{ description: uberDescription, volume: uberVolume },
{ description: spaceXDescription, volume: spaceXVolume },
] = await getMarketsInfo(coolMarkets);
console.log(`${spaceXDescription} --> ${spaceXVolume}`);
console.log(`${uberDescription} --> ${uberVolume}`);
const orders = await getOpenOrders(coolMarkets[0]);
const ordersByOutcome = orders[coolMarkets[0]]; // Getting the orders of the first market
const buyingOrders = flatOrders(ordersByOutcome[1].buy); // Choosing outcome 1 orders and flattening it
const { price, amount } = buyingOrders[0];
console.log(`Uber Order Price: ${price}`);
console.log(`Uber Order Amount: ${amount}`);
} catch (error) {
throw error;
} finally {
process.exit()
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.