Skip to content

Commit

Permalink
Kraken::getLimitPrice - fix off by 1 segfault from last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ezillinger committed Jun 22, 2017
1 parent 9a849b9 commit 48d56b9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/exchanges/kraken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,22 @@ double getLimitPrice(Parameters &params, double volume, bool isBid)
branch = json_object_get(branch, isBid ? "bids" : "asks");

// loop on volume
double tmpVol = 0.0;
double totVol = 0.0;
double currPrice = 0;
double currVol = 0;
unsigned int i;
// [[<price>, <volume>, <timestamp>], [<price>, <volume>, <timestamp>], ...]
for(i = 0; i < json_array_size(branch); i++)
{
// volumes are added up until the requested volume is reached
tmpVol += atof(json_string_value(json_array_get(json_array_get(branch, i), 1)));
if(tmpVol >= volume * params.orderBookFactor)
currVol = atof(json_string_value(json_array_get(json_array_get(branch, i), 1)));
currPrice = atof(json_string_value(json_array_get(json_array_get(branch, i), 0)));
totVol += currVol;
if(totVol >= volume * params.orderBookFactor)
break;
}

return atof(json_string_value(json_array_get(json_array_get(branch, i), 0)));
return currPrice;
}

json_t* authRequest(Parameters& params, std::string request, std::string options)
Expand Down

0 comments on commit 48d56b9

Please sign in to comment.