Skip to content

Instantly share code, notes, and snippets.

@carlosgj94
Last active July 9, 2020 03:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosgj94/ebcef1cbd82cf789987a34c5cb47ad9c to your computer and use it in GitHub Desktop.
Save carlosgj94/ebcef1cbd82cf789987a34c5cb47ad9c to your computer and use it in GitHub Desktop.
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