Skip to content

Instantly share code, notes, and snippets.

@monossido
Last active May 8, 2018 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monossido/5e08aecbeec3324dbbc46d086f91fc3c to your computer and use it in GitHub Desktop.
Save monossido/5e08aecbeec3324dbbc46d086f91fc3c to your computer and use it in GitHub Desktop.
[Blackbird] Kraken issue on getActivePos (with eur)
diff --git a/src/exchanges/kraken.cpp b/src/exchanges/kraken.cpp
index 902dfa1..7a69f5a 100644
--- a/src/exchanges/kraken.cpp
+++ b/src/exchanges/kraken.cpp
@@ -18,6 +18,7 @@ namespace Kraken
static unique_json krakenTicker = nullptr;
static bool krakenGotTicker = false;
+double shortOrderVolume = 0.0;
static RestApi &queryHandle(Parameters &params)
{
@@ -35,14 +36,14 @@ quote_t getQuote(Parameters &params)
else
{
auto &exchange = queryHandle(params);
- krakenTicker.reset(exchange.getRequest("/0/public/Ticker?pair=XXBTZUSD"));
+ krakenTicker.reset(exchange.getRequest("/0/public/Ticker?pair=XXBTZEUR"));
krakenGotTicker = true;
}
json_t *root = krakenTicker.get();
- const char *quote = json_string_value(json_array_get(json_object_get(json_object_get(json_object_get(root, "result"), "XXBTZUSD"), "b"), 0));
+ const char *quote = json_string_value(json_array_get(json_object_get(json_object_get(json_object_get(root, "result"), "XXBTZEUR"), "b"), 0));
auto bidValue = quote ? std::stod(quote) : 0.0;
- quote = json_string_value(json_array_get(json_object_get(json_object_get(json_object_get(root, "result"), "XXBTZUSD"), "a"), 0));
+ quote = json_string_value(json_array_get(json_object_get(json_object_get(json_object_get(root, "result"), "XXBTZEUR"), "a"), 0));
auto askValue = quote ? std::stod(quote) : 0.0;
return std::make_pair(bidValue, askValue);
@@ -50,28 +51,32 @@ quote_t getQuote(Parameters &params)
double getAvail(Parameters &params, std::string currency)
{
- unique_json root{authRequest(params, "/0/private/Balance")};
- json_t *result = json_object_get(root.get(), "result");
- if (json_object_size(result) == 0)
- {
- return 0.0;
- }
- double available = 0.0;
- if (currency.compare("usd") == 0)
- {
- const char *avail_str = json_string_value(json_object_get(result, "ZUSD"));
- available = avail_str ? atof(avail_str) : 0.0;
+ if(shortOrderVolume == 0.0 || currency.compare("eur") == 0) {
+ unique_json root{authRequest(params, "/0/private/Balance")};
+ json_t *result = json_object_get(root.get(), "result");
+ if (json_object_size(result) == 0)
+ {
+ return 0.0;
+ }
+ double available = 0.0;
+ if (currency.compare("eur") == 0)
+ {
+ const char *avail_str = json_string_value(json_object_get(result, "ZEUR"));
+ available = avail_str ? atof(avail_str) : 0.0;
+ }
+ else if (currency.compare("btc") == 0)
+ {
+ const char *avail_str = json_string_value(json_object_get(result, "XXBT"));
+ available = avail_str ? atof(avail_str) : 0.0;
+ }
+ else
+ {
+ *params.logFile << "<Kraken> Currency not supported" << std::endl;
+ }
+ return available;
+ } else {
+ return shortOrderVolume;
}
- else if (currency.compare("btc") == 0)
- {
- const char *avail_str = json_string_value(json_object_get(result, "XXBT"));
- available = avail_str ? atof(avail_str) : 0.0;
- }
- else
- {
- *params.logFile << "<Kraken> Currency not supported" << std::endl;
- }
- return available;
}
std::string sendLongOrder(Parameters &params, std::string direction, double quantity, double price)
@@ -89,7 +94,7 @@ std::string sendOrder(Parameters &params, std::string direction, double quantity
*params.logFile << "<Kraken> Trying to send a \"" << direction << "\" limit order: "
<< std::setprecision(6) << quantity << " @ $"
<< std::setprecision(2) << price << "...\n";
- std::string pair = "XXBTZUSD";
+ std::string pair = "XXBTZEUR";
std::string type = direction;
std::string ordertype = "limit";
std::string pricelimit = std::to_string(price);
@@ -118,7 +123,7 @@ std::string sendShortOrder(Parameters &params, std::string direction, double qua
*params.logFile << "<Kraken> Trying to send a short \"" << direction << "\" limit order: "
<< std::setprecision(6) << quantity << " @ $"
<< std::setprecision(2) << price << "...\n";
- std::string pair = "XXBTZUSD";
+ std::string pair = "XXBTZEUR";
std::string type = direction;
std::string ordertype;
std::string options;
@@ -137,6 +142,12 @@ std::string sendShortOrder(Parameters &params, std::string direction, double qua
std::string txid = json_string_value(json_array_get(json_object_get(res, "txid"), 0));
*params.logFile << "<Kraken> Done (transaction ID: " << txid << ")\n"
<< std::endl;
+
+ if(direction.compare("sell") == 0)
+ shortOrderVolume = quantity;
+ else
+ shortOrderVolume = 0.0;
+
return txid;
}
@@ -173,8 +184,8 @@ double getActivePos(Parameters &params)
double getLimitPrice(Parameters &params, double volume, bool isBid)
{
auto &exchange = queryHandle(params);
- unique_json root { exchange.getRequest("/0/public/Depth?pair=XXBTZUSD") };
- auto branch = json_object_get(json_object_get(root.get(), "result"), "XXBTZUSD");
+ unique_json root { exchange.getRequest("/0/public/Depth?pair=XXBTZEUR") };
+ auto branch = json_object_get(json_object_get(root.get(), "result"), "XXBTZEUR");
branch = json_object_get(branch, isBid ? "bids" : "asks");
// loop on volume
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment