コード例 #1
0
ファイル: index.js プロジェクト: AugurProject/augur.js
function runCommandWithArgs(commandName, method, args, network, callback) {
  console.log("Running with Args");
  console.log(chalk.yellow.dim("command"), commandName);
  console.log(chalk.yellow.dim("parameters"), JSON.stringify(args));
  console.log(chalk.yellow.dim("network"), network);
  console.log(NetworkConfiguration.create);
  var config = NetworkConfiguration.create(network);
  console.log(chalk.yellow("network http:"), config.http);
  var augur = new Augur();
  augur.rpc.setDebugOptions(debugOptions);
  var auth = process.env.ETHEREUM_PRIVATE_KEY ? getPrivateKeyFromEnv() : getPrivateKeyFromString(config.privateKey);
  var augurWs = process.env.AUGUR_WS ? process.env.AUGUR_WS : "http://localhost:9001";
  augur.connect(
    { ethereumNode: { http: config.http, pollingIntervalMilliseconds: 500 }, augurNode: augurWs },
    function (err) {
      if (err) {
        console.log(chalk.red("Error "), chalk.red(err));
        return callback(err);
      }
      method.method(augur, args, auth, function (err) {
        if (err) console.log(chalk.red("Error "), chalk.red(err));
        console.log(chalk.green("Finished Execution"));
        process.exit(0);
      });
    }
  );
}
コード例 #2
0
 augur.augurNode.submitRequest("getWinningBalance", winningPayload, function (err, value) {
   if (err) {
     console.log(chalk.red(err));
     return callback(err);
   }
   console.log(chalk.yellow.dim("Account Winning Balance"));
   console.log(chalk.yellow.dim("Balance: "), chalk.yellow(JSON.stringify(value)));
   callback(err, value);
 });
コード例 #3
0
    approveAugurEternalApprovalValue(augur, auth.address, auth, function (err) {
      if (err) {
        console.log(chalk.red("Error "), chalk.red(err));
        return callback(err);
      }
      var market = marketInfos[0];
      var marketId = market.id;
      console.log(chalk.yellow.dim("user"), chalk.yellow(auth.address));
      console.log(chalk.yellow.dim("outcome:"), chalk.yellow(outcome), chalk.yellow.dim("order type:"), chalk.yellow(orderType));
      console.log(chalk.green.dim("OrderId:"), chalk.green.dim("Account:"), chalk.green.dim("Amount:"), chalk.green.dim("FullPrecisionPrice:"), chalk.green.dim("FullPrecisionAmount"));
      augur.trading.getOrders({ marketId: marketId, outcome: outcome, orderType: orderType }, function (err, orderBook) {
        if (err) {
          console.error(err);
          return callback(err);
        }
        if (!orderBook[marketId]) {
          return callback("No Market Orders Found");
        }
        var orders = orderBook[marketId][outcome][orderType];
        // Right now orders are in a random order
        // sort by price ascending
        var sortedOrders = Object.values(orders).sort(function (a, b) {
          return new BigNumber(a.price).comparedTo(new BigNumber(b.price));
        });
        async.eachSeries(sortedOrders, function (order, nextOrder) {
          console.log(chalk.yellow(order.fullPrecisionPrice), chalk.yellow(order.fullPrecisionAmount));

          augur.trading.placeTrade({
            meta: auth,
            amount: order.fullPrecisionAmount,
            limitPrice: order.fullPrecisionPrice,
            numTicks: market.numTicks,
            minPrice: market.minPrice,
            maxPrice: market.maxPrice,
            sharesProvided: "0",
            _direction: direction,
            _market: marketId,
            _outcome: parseInt(outcome, 10),
            _tradeGroupId: augur.trading.generateTradeGroupId(),
            doNotCreateOrders: true,
            onSent: noop,
            onSuccess: function (tradeAmountRemaining) {
              console.log(chalk.cyan("Trade completed,"), chalk.red.bold(orderType), chalk.green(tradeAmountRemaining), chalk.cyan.dim("shares remaining"));
              nextOrder(null);
            },
            onFailed: function (err) {
              console.log(chalk.red(err));
              nextOrder(err);
            },
          });
        }, function (err) {
          callback(err);
        });
      });
    });
コード例 #4
0
function showBalances(augur, address, label, callback) {
  console.log(chalk.yellow.dim(label), chalk.yellow(address));
  showCashBalance(augur, address, label, function (err) {
    if (err) {
      console.log(chalk.red(err));
    }
    showEthBalance(augur, address, label, callback);
  });
}
コード例 #5
0
 augur.api.ShareToken.balanceOf(shareTokenPayload, function (err, balance) {
   if (err) {
     console.log(chalk.red(err));
     return callback(err);
   }
   var adjusted = new BigNumber(speedomatic.unfix(balance, "string")).times(new BigNumber(numTicks));
   console.log(chalk.yellow.dim("Market Outcome: "), chalk.yellow(outcomeId));
   console.log("attoShare: " + chalk.green(balance), "Shares: " + chalk.green(speedomatic.unfix(balance, "string")), "Adjusted Shares: " + chalk.green(adjusted));
   nextOutcome(null);
 });
コード例 #6
0
 showWinningBalance: function (next) {
   if (address && showMarketWinningBalance) {
     console.log(chalk.yellow.dim("Market State"), chalk.yellow(market.reportingState));
     showWinningBalance(augur, marketId, address, function (err) {
       if (err) {
         console.log(chalk.red(err));
       }
       next(null);
     });
   } else {
     next(null);
   }
 },
コード例 #7
0
 onSent: function (result) {
   console.log(chalk.yellow.dim("Sent:"), chalk.yellow(JSON.stringify(result)));
 },