示例#1
0
double getLimitPrice(Parameters& params, double volume, bool isBid) {
  json_t* root;
  if (isBid) {
    root = json_object_get(getJsonFromUrl(params, "https://www.bitstamp.net/api/order_book/", ""), "bids");
  } else {
    root = json_object_get(getJsonFromUrl(params, "https://www.bitstamp.net/api/order_book/", ""), "asks");
  }
  // loop on volume
  *params.logFile << "<Bitstamp> Looking for a limit price to fill " << fabs(volume) << " BTC..." << std::endl;
  double tmpVol = 0.0;
  double p;
  double v;
  int i = 0;
  while (tmpVol < fabs(volume) * params.orderBookFactor) {
    p = atof(json_string_value(json_array_get(json_array_get(root, i), 0)));
    v = atof(json_string_value(json_array_get(json_array_get(root, i), 1)));
    *params.logFile << "<Bitstamp> order book: " << v << "@$" << p << std::endl;
    tmpVol += v;
    i++;
  }
  double limPrice = 0.0;
  limPrice = atof(json_string_value(json_array_get(json_array_get(root, i-1), 0)));
  json_decref(root);
  return limPrice;
}
示例#2
0
// get the limit price according to the requested volume
double getLimitPrice(Parameters& params, double volume, bool isBid){
	json_t* root;
	  if (isBid) {
	    root = json_object_get(getJsonFromUrl(params, "http://api.796.com/v3/futures/depth.html?type=weekly", ""), "bids");
	  } else {
	    root = json_object_get(getJsonFromUrl(params, "http://api.796.com/v3/futures/depth.html?type=weekly", ""), "asks");
	  }
	  // loop on volume
	  *params.logFile << "<SevenNintySix> Looking for a limit price to fill " << volume << "BTC..." << std::endl;
	  double tmpVol = 0.0;
	  int i = 0;
	  while (tmpVol < volume) {
	    // volumes are added up until the requested volume is reached
	      double p = json_real_value(json_array_get(json_array_get(root, i), 0));
	      double v = json_real_value(json_array_get(json_array_get(root, i), 1));

	    *params.logFile << "<SevenNintySix> order book: " << v << "@$" << p << std::endl;
	    tmpVol += v;
	    i++;
	  }
	  // return the next offer
	  double limPrice = 0.0;
	  if (params.aggressiveVolume) {
	    limPrice = atof(json_string_value(json_array_get(json_array_get(root, i), 0)));
	  } else {
	    limPrice = atof(json_string_value(json_array_get(json_array_get(root, i+1), 0)));
	  }
	  json_decref(root);
	  return limPrice;
}
示例#3
0
double getLimitPrice(CURL *curl, Parameters params, double volume, bool isBid) {
  json_t *root;
  if (isBid) {
    root = json_object_get(getJsonFromUrl(curl, "https://www.bitstamp.net/api/order_book/", ""), "bids");
  } else {
    root = json_object_get(getJsonFromUrl(curl, "https://www.bitstamp.net/api/order_book/", ""), "asks");
  }

  // loop on volume
  double tmpVol = 0.0;
  int i = 0;
  while (tmpVol < volume) {
    // volumes are added up until the requested volume is reached
    tmpVol += atof(json_string_value(json_array_get(json_array_get(root, i), 1)));
    i++;
  }
  // return the next offer
  double limPrice = 0.0;
  if (params.aggressiveVolume) {
    limPrice = atof(json_string_value(json_array_get(json_array_get(root, i), 0)));
  } else {
    limPrice = atof(json_string_value(json_array_get(json_array_get(root, i+1), 0)));
  }
  json_decref(root);
  return limPrice;
}
示例#4
0
// get the limit price according to the requested volume
double getLimitPrice(Parameters& params, double volume, bool isBid){
  json_t* root;
    if (isBid) {
      root = json_object_get(getJsonFromUrl(params, "http://api.796.com/v3/futures/depth.html?type=weekly", ""), "bids");
    } else {
      root = json_object_get(getJsonFromUrl(params, "http://api.796.com/v3/futures/depth.html?type=weekly", ""), "asks");
    }
    
    // loop on volume
    *params.logFile << "<SevenNintySix> Looking for a limit price to fill " << volume << "BTC..." << std::endl;
    double tmpVol = 0.0;
    int i = 0;
    while (tmpVol < volume) {
      // volumes are added up until the requested volume is reached
        double p = json_real_value(json_array_get(json_array_get(root, i), 0));
        double v = json_real_value(json_array_get(json_array_get(root, i), 1));

      *params.logFile << "<SevenNintySix> order book: " << v << "@$" << p << std::endl;
      tmpVol += .1; //v; had to comment this out in order to advance past this call in sendOrder, as v was always 0
      i++;
    }
    double limPrice = 0.0;
    limPrice = atof(json_string_value(json_array_get(json_array_get(root, i), 0)));

    json_decref(root);
    return limPrice;
}
示例#5
0
double getLimitPrice(Parameters& params, double volume, bool isBid) {
  bool GETRequest = false;
  json_t* root;
  if (isBid) {
    root = json_object_get(getJsonFromUrl(params, "https://api.gemini.com/v1/book/btcusd", "", GETRequest), "bids");
  } else {
    root = json_object_get(getJsonFromUrl(params, "https://api.gemini.com/v1/book/btcusd", "", GETRequest), "asks");
  }
  // loop on volume
  *params.logFile << "<Gemini> Looking for a limit price to fill " << fabs(volume) << " BTC..." << std::endl;
  double tmpVol = 0.0;
  double p;
  double v;
  int i = 0;
  while (tmpVol < fabs(volume) * params.orderBookFactor) {
    p = atof(json_string_value(json_object_get(json_array_get(root, i), "price")));
    v = atof(json_string_value(json_object_get(json_array_get(root, i), "amount")));
    *params.logFile << "<Gemini> order book: " << v << "@$" << p << std::endl;
    tmpVol += v;
    i++;
  }
  double limPrice = 0.0;
  limPrice = atof(json_string_value(json_object_get(json_array_get(root, i-1), "price")));
  json_decref(root);
  return limPrice;
}
示例#6
0
double getLimitPrice(Parameters& params, double volume, bool isBid) {
  json_t* root;
  double limPrice = 0.0;
  if (isBid) {
    root = json_object_get(getJsonFromUrl(params, "https://www.okcoin.com/api/v1/depth.do", ""), "bids");
    // loop on volume
    *params.logFile << "<OKCoin> Looking for a limit price to fill " << volume << " BTC..." << std::endl;
    double tmpVol = 0.0;
    double p;
    double v;
    size_t i = 0;
    while (tmpVol < volume * 2.0) {
      p = json_real_value(json_array_get(json_array_get(root, i), 0));
      v = json_real_value(json_array_get(json_array_get(root, i), 1));
      *params.logFile << "<OKCoin> order book: " << v << "@$" << p << std::endl;
      tmpVol += v;
      i++;
    }
    if (params.aggressiveVolume) {
      limPrice = json_real_value(json_array_get(json_array_get(root, i-1), 0));
    } else {
      p = json_real_value(json_array_get(json_array_get(root, i), 0));
      v = json_real_value(json_array_get(json_array_get(root, i), 1));
      *params.logFile << "<OKCoin> order book: " << v << "@$" << p << " (non-aggressive)" << std::endl;
      limPrice = p;
    }
  } else {
    root = json_object_get(getJsonFromUrl(params, "https://www.okcoin.com/api/v1/depth.do", ""), "asks");
    // loop on volume
    *params.logFile << "<OKCoin> Looking for a limit price to fill " << volume << " BTC..." << std::endl;
    double tmpVol = 0.0;
    double p;
    double v;
    size_t i = json_array_size(root) - 1;
    while (tmpVol < volume * 2.0) {
      p = json_real_value(json_array_get(json_array_get(root, i), 0));
      v = json_real_value(json_array_get(json_array_get(root, i), 1));
      *params.logFile << "<OKCoin> order book: " << v << "@$" << p << std::endl;
      tmpVol += v;
      i--;
    }
    if (params.aggressiveVolume) {
      limPrice = json_real_value(json_array_get(json_array_get(root, i+1), 0));
    } else {
      p = json_real_value(json_array_get(json_array_get(root, i), 0));
      v = json_real_value(json_array_get(json_array_get(root, i), 1));
      *params.logFile << "<OKCoin> order book: " << v << "@$" << p << " (non-aggressive)" << std::endl;
      limPrice = p;
    }
  }
  json_decref(root);
  return limPrice;
}
示例#7
0
double getQuote(CURL *curl, bool isBid) {
  /*root declared as a pointer to json_t type data structure in jansson*/
  /*root will point to json_t structure having key:value pairs. Key can be "bid" or ask" among other things as we are reading from bitstamp ticker API*/
  json_t *root = getJsonFromUrl(curl, "https://www.bitstamp.net/api/ticker/", "");
  const char* quote;
  double quoteValue;
  /*isBid is bool being supplied as parameter to function*/
  if (isBid) {
    /*from root pointer, value corresponding to "bid" key retrieved*/
    quote = json_string_value(json_object_get(root, "bid"));
  } else {
    /*from root pointer, value corresponding to "ask" key retrieved*/
    quote = json_string_value(json_object_get(root, "ask"));
  }
  if (quote != NULL) {
      /*atof : Convert string to double*/
    quoteValue = atof(quote);
  } else {
    quoteValue = 0.0;
  }
 /*The reference count is used to track whether a value is still in use or not. When a value is created, it’s reference count is set to 1. If a reference to a value is kept (e.g. a value is stored somewhere for later use), its reference count is incremented, and when the value is no longer needed, the reference count is decremented. When the reference count drops to zero, there are no references left, and the value can be destroyed.*/
 /*void json_decref(json_t *json)
Decrement the reference count of json. As soon as a call to json_decref() drops the reference count to zero, the value is destroyed and it can no longer be used.*/
  json_decref(root);
  return quoteValue;
}
示例#8
0
double getLimitPrice(Parameters& params, double volume, bool isBid) {

  json_t* root = json_object_get(json_object_get(getJsonFromUrl(params, "https://api.kraken.com/0/public/Depth", "pair=XXBTZUSD"), "result"), "XXBTZUSD");
  if (isBid) {
    root = json_object_get(root, "bids");
  } else {
    root = json_object_get(root, "asks");
  }

  // loop on volume
  double tmpVol = 0.0;
  int i = 0;

  // [[<price>, <volume>, <timestamp>], [<price>, <volume>, <timestamp>], ...]
  while (tmpVol < volume) {
    // volumes are added up until the requested volume is reached
    tmpVol += atof(json_string_value(json_array_get(json_array_get(root, i), 1)));
    i++;
  }

  // return the next offer
  double limPrice = 0.0;
  if (params.aggressiveVolume) {
    limPrice = atof(json_string_value(json_array_get(json_array_get(root, i-1), 0)));
  } else {
    limPrice = atof(json_string_value(json_array_get(json_array_get(root, i), 0)));
  }
  json_decref(root);

  return limPrice;
}
示例#9
0
double getLimitPrice(CURL *curl, double volume, bool isBid) {
  json_t *root;
  if (isBid) {
    root = json_object_get(getJsonFromUrl(curl, "https://api.bitfinex.com/v1/book/btcusd", ""), "bids");
  } else {
    root = json_object_get(getJsonFromUrl(curl, "https://api.bitfinex.com/v1/book/btcusd", ""), "asks");
  }
  // loop on volume
  double tmpVol = 0.0;
  int i = 0;
  while (tmpVol < volume) {
    // volumes are added up until the requested volume is reached
    tmpVol += atof(json_string_value(json_object_get(json_array_get(root, i), "amount")));
    i++;
  }
  // return the second next offer
  double limPrice = atof(json_string_value(json_object_get(json_array_get(root, i+1), "price")));
  json_decref(root);
  return limPrice;
}
示例#10
0
double getQuote(Parameters& params, bool isBid) {
  bool GETRequest = false;
  json_t* root = getJsonFromUrl(params, "https://btc-e.com/api/3/ticker/btc_usd", "", GETRequest);
  double quoteValue;
  if (isBid) {
    quoteValue = json_real_value(json_object_get(json_object_get(root, "btc_usd"), "buy"));
  } else {
    quoteValue = json_real_value(json_object_get(json_object_get(root, "btc_usd"), "sell"));
  }
  json_decref(root);
  return quoteValue;
}
示例#11
0
double getQuote(CURL *curl, bool isBid) {

  double quote;
  json_t *root = getJsonFromUrl(curl, "https://api.bitfinex.com/v1/ticker/btcusd", "");
  if (isBid) {
    quote = atof(json_string_value(json_object_get(root, "bid")));
  } else {
    quote = atof(json_string_value(json_object_get(root, "ask")));
  }
  json_decref(root);
  return quote;
}
示例#12
0
double getLimitPrice(Parameters& params, double volume, bool isBid) {
  bool GETRequest = false;
  json_t* root;
  double limPrice = 0.0;
  if (isBid) {
    root = json_object_get(getJsonFromUrl(params, "https://www.okcoin.com/api/v1/depth.do", "", GETRequest), "bids");
    // loop on volume
    *params.logFile << "<OKCoin> Looking for a limit price to fill " << fabs(volume) << " BTC..." << std::endl;
    double tmpVol = 0.0;
    double p;
    double v;
    size_t i = 0;
    while (tmpVol < fabs(volume) * params.orderBookFactor) {
      p = json_real_value(json_array_get(json_array_get(root, i), 0));
      v = json_real_value(json_array_get(json_array_get(root, i), 1));
      *params.logFile << "<OKCoin> order book: " << v << "@$" << p << std::endl;
      tmpVol += v;
      i++;
    }
    limPrice = json_real_value(json_array_get(json_array_get(root, i-1), 0));
  } else {
    root = json_object_get(getJsonFromUrl(params, "https://www.okcoin.com/api/v1/depth.do", "", GETRequest), "asks");
    // loop on volume
    *params.logFile << "<OKCoin> Looking for a limit price to fill " << fabs(volume) << " BTC..." << std::endl;
    double tmpVol = 0.0;
    double p;
    double v;
    size_t i = json_array_size(root) - 1;
    while (tmpVol < fabs(volume) * params.orderBookFactor) {
      p = json_real_value(json_array_get(json_array_get(root, i), 0));
      v = json_real_value(json_array_get(json_array_get(root, i), 1));
      *params.logFile << "<OKCoin> order book: " << v << "@$" << p << std::endl;
      tmpVol += v;
      i--;
    }
    limPrice = json_real_value(json_array_get(json_array_get(root, i+1), 0));
  }
  json_decref(root);
  return limPrice;
}
示例#13
0
void TwitchTMIJob::runThread()
{
	std::stringstream ss, ss2;
	ss << "https://api.twitch.tv/kraken/channels/" << channel;
	ss2 << "https://api.twitch.tv/kraken/streams/" << channel;

	CString url = ss.str();
	CString url2 = ss2.str();

	Json::Value root = getJsonFromUrl(url.c_str(), "Accept: application/vnd.twitchtv.v3+json");
	Json::Value root2 = getJsonFromUrl(url2.c_str(), "Accept: application/vnd.twitchtv.v3+json");

	if(!root.isNull())
	{
		Json::Value &titleVal = root["status"];
		title = CString();

		if(!titleVal.isString())
			titleVal = root["title"];

		if(titleVal.isString())
		{
			title = titleVal.asString();
			title.Trim();
		}
	}

	live = false;

	if(!root2.isNull())
	{
		Json::Value &streamVal = root2["stream"];

		if(!streamVal.isNull())
			live = true;
	}
}
示例#14
0
double getQuote(Parameters& params, bool isBid) {
  json_t* root = getJsonFromUrl(params, "https://api.kraken.com/0/public/Ticker", "pair=XXBTZUSD");
  const char* quote;
  double quoteValue;
  if (isBid) {
    quote = json_string_value(json_array_get(json_object_get(json_object_get(json_object_get(root, "result"), "XXBTZUSD"), "b"), 0));
  } else {
    quote = json_string_value(json_array_get(json_object_get(json_object_get(json_object_get(root, "result"), "XXBTZUSD"), "a"), 0));
  }
  if (quote != NULL) {
    quoteValue = atof(quote);
  } else {
    quoteValue = 0.0;
  }
  json_decref(root);
  return quoteValue;
}
示例#15
0
double getQuote(Parameters& params, bool isBid) {
  json_t* root = getJsonFromUrl(params, "https://www.bitstamp.net/api/ticker/", "");
  const char* quote;
  double quoteValue;
  if (isBid) {
    quote = json_string_value(json_object_get(root, "bid"));
  } else {
    quote = json_string_value(json_object_get(root, "ask"));
  }
  if (quote != NULL) {
    quoteValue = atof(quote);
  } else {
    quoteValue = 0.0;
  }
  json_decref(root);
  return quoteValue;
}
示例#16
0
double getQuote(Parameters& params, bool isBid) {
  json_t* root = getJsonFromUrl(params, "https://www.okcoin.com/api/ticker.do?ok=1", "");
  const char* quote;
  double quoteValue;
  if (isBid) {
    quote = json_string_value(json_object_get(json_object_get(root, "ticker"), "buy"));
  } else {
    quote = json_string_value(json_object_get(json_object_get(root, "ticker"), "sell"));
  }
  if (quote != NULL) {
    quoteValue = atof(quote);
  } else {
    quoteValue = 0.0;
  }
  json_decref(root);
  return quoteValue;
}
示例#17
0
double getQuote(CURL *curl, bool isBid) {
  json_t *root = getJsonFromUrl(curl, "https://api.bitfinex.com/v1/ticker/btcusd", "");
  const char *quote;
  double quoteValue;
  if (isBid) {
    quote = json_string_value(json_object_get(root, "bid"));
  } else {
    quote = json_string_value(json_object_get(root, "ask"));
  }
  if (quote != NULL) {
    quoteValue = atof(quote);
  } else {
    quoteValue = 0.0;
  }
  json_decref(root);
  return quoteValue;
}
示例#18
0
double getQuote(Parameters& params, bool isBid) {
	json_t* root = getJsonFromUrl(params, "http://api.796.com/v3/futures/ticker.html?type=weekly", "");
	const char* quote;
	double quoteValue;
	if (isBid) {
	  quote = json_string_value(json_object_get(json_object_get(root, "ticker"), "buy"));
	} else {
	  quote = json_string_value(json_object_get(json_object_get(root, "ticker"), "sell"));
	}
	if (quote != NULL) {
		quoteValue = atof(quote);
	} else {
		quoteValue = 0.0;
	}
	json_decref(root);
	return quoteValue;
}
示例#19
0
double getQuote(Parameters& params, bool isBid) {
  json_t* root = getJsonFromUrl(params, "https://api.gemini.com/v1/book/BTCUSD", "");
  const char *quote;
  double quoteValue;
  if (isBid) {
    quote = json_string_value(json_object_get(json_array_get(json_object_get(root, "bids"), 0), "price"));
  } else {
    quote = json_string_value(json_object_get(json_array_get(json_object_get(root, "asks"), 0), "price"));
  }
  if (quote != NULL) {
    quoteValue = atof(quote);
  } else {
    quoteValue = 0.0;
  }
  json_decref(root);
  return quoteValue;
}