yet logging
This commit is contained in:
@@ -240,142 +240,142 @@ int32_t prices_syntheticvec(std::vector<uint16_t> &vec,std::vector<std::string>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calculates price for synthetic expression
|
// calculates price for synthetic expression
|
||||||
int64_t prices_syntheticprice(std::vector<uint16_t> vec,int32_t height,int32_t minmax,int16_t leverage)
|
int64_t prices_syntheticprice(std::vector<uint16_t> vec, int32_t height, int32_t minmax, int16_t leverage)
|
||||||
{
|
{
|
||||||
int32_t i,value,errcode,depth,retval = -1;
|
int32_t i, value, errcode, depth, retval = -1;
|
||||||
uint16_t opcode;
|
uint16_t opcode;
|
||||||
int64_t *pricedata,pricestack[4],price,den,a,b,c;
|
int64_t *pricedata, pricestack[4], price, den, a, b, c;
|
||||||
|
|
||||||
pricedata = (int64_t *)calloc(sizeof(*pricedata)*3,1 + PRICES_DAYWINDOW*2 + PRICES_SMOOTHWIDTH);
|
pricedata = (int64_t *)calloc(sizeof(*pricedata) * 3, 1 + PRICES_DAYWINDOW * 2 + PRICES_SMOOTHWIDTH);
|
||||||
price = den = depth = errcode = 0;
|
price = den = depth = errcode = 0;
|
||||||
|
|
||||||
for (i=0; i<vec.size(); i++)
|
for (i = 0; i < vec.size(); i++)
|
||||||
{
|
{
|
||||||
opcode = vec[i];
|
opcode = vec[i];
|
||||||
value = (opcode & (KOMODO_MAXPRICES-1)); // index or weight
|
value = (opcode & (KOMODO_MAXPRICES - 1)); // index or weight
|
||||||
std::cerr << "prices_syntheticprice" << " i=" << i << " price=" << price << " value=" << value << " depth=" << depth << std::endl;
|
std::cerr << "prices_syntheticprice" << " i=" << i << " price=" << price << " value=" << value << " depth=" << depth << std::endl;
|
||||||
switch( opcode & KOMODO_PRICEMASK )
|
switch (opcode & KOMODO_PRICEMASK)
|
||||||
{
|
{
|
||||||
case 0: // indices
|
case 0: // indices
|
||||||
pricestack[depth] = 0;
|
pricestack[depth] = 0;
|
||||||
if ( prices_extract(pricedata,height,1,value) == 0 )
|
if (prices_extract(pricedata, height, 1, value) == 0)
|
||||||
|
{
|
||||||
|
// push price to the prices stack
|
||||||
|
if (!minmax)
|
||||||
|
pricestack[depth] = pricedata[2]; // use smoothed value if we are over 24h
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// push price to the prices stack
|
// if we are within 24h use min or max price
|
||||||
if ( !minmax )
|
if (leverage > 0)
|
||||||
pricestack[depth] = pricedata[2]; // use smoothed value if we are over 24h
|
pricestack[depth] = (pricedata[1] > pricedata[2]) ? pricedata[1] : pricedata[2]; // MAX
|
||||||
else
|
else
|
||||||
{
|
pricestack[depth] = (pricedata[1] < pricedata[2]) ? pricedata[1] : pricedata[2]; // MIN
|
||||||
// if we are within 24h use min or max price
|
|
||||||
if ( leverage > 0 )
|
|
||||||
pricestack[depth] = (pricedata[1] > pricedata[2]) ? pricedata[1] : pricedata[2]; // MAX
|
|
||||||
else
|
|
||||||
pricestack[depth] = (pricedata[1] < pricedata[2]) ? pricedata[1] : pricedata[2]; // MIN
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ( pricestack[depth] == 0 )
|
}
|
||||||
errcode = -1;
|
if (pricestack[depth] == 0)
|
||||||
|
errcode = -1;
|
||||||
|
|
||||||
depth++;
|
depth++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PRICES_WEIGHT: // multiply by weight and consume top of stack by updating price
|
case PRICES_WEIGHT: // multiply by weight and consume top of stack by updating price
|
||||||
if( depth == 1 ) {
|
if (depth == 1) {
|
||||||
depth--;
|
depth--;
|
||||||
price += pricestack[0] * value;
|
price += pricestack[0] * value;
|
||||||
den += value; // acc weight value
|
den += value; // acc weight value
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
errcode = -2;
|
errcode = -2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PRICES_MULT:
|
case PRICES_MULT:
|
||||||
if( depth >= 2 ) {
|
if (depth >= 2) {
|
||||||
b = pricestack[--depth];
|
b = pricestack[--depth];
|
||||||
a = pricestack[--depth];
|
a = pricestack[--depth];
|
||||||
pricestack[depth++] = (a * b) / SATOSHIDEN;
|
pricestack[depth++] = (a * b) / SATOSHIDEN;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
errcode = -3;
|
errcode = -3;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PRICES_DIV:
|
case PRICES_DIV:
|
||||||
if( depth >= 2 ) {
|
if (depth >= 2) {
|
||||||
b = pricestack[--depth];
|
b = pricestack[--depth];
|
||||||
a = pricestack[--depth];
|
a = pricestack[--depth];
|
||||||
pricestack[depth++] = (a * SATOSHIDEN) / b;
|
pricestack[depth++] = (a * SATOSHIDEN) / b;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
errcode = -4;
|
errcode = -4;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PRICES_INV:
|
case PRICES_INV:
|
||||||
if( depth >= 1 ) {
|
if (depth >= 1) {
|
||||||
a = pricestack[--depth];
|
a = pricestack[--depth];
|
||||||
pricestack[depth++] = (SATOSHIDEN * SATOSHIDEN) / a;
|
pricestack[depth++] = (SATOSHIDEN * SATOSHIDEN) / a;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
errcode = -5;
|
errcode = -5;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PRICES_MDD:
|
case PRICES_MDD:
|
||||||
if( depth >= 3 ) {
|
if (depth >= 3) {
|
||||||
c = pricestack[--depth];
|
c = pricestack[--depth];
|
||||||
b = pricestack[--depth];
|
b = pricestack[--depth];
|
||||||
a = pricestack[--depth];
|
a = pricestack[--depth];
|
||||||
pricestack[depth++] = (((a * SATOSHIDEN) / b) * SATOSHIDEN) / c;
|
pricestack[depth++] = (((a * SATOSHIDEN) / b) * SATOSHIDEN) / c;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
errcode = -6;
|
errcode = -6;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PRICES_MMD:
|
case PRICES_MMD:
|
||||||
if( depth >= 3 ) {
|
if (depth >= 3) {
|
||||||
c = pricestack[--depth];
|
c = pricestack[--depth];
|
||||||
b = pricestack[--depth];
|
b = pricestack[--depth];
|
||||||
a = pricestack[--depth];
|
a = pricestack[--depth];
|
||||||
pricestack[depth++] = (a * b) / c;
|
pricestack[depth++] = (a * b) / c;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
errcode = -7;
|
errcode = -7;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PRICES_MMM:
|
case PRICES_MMM:
|
||||||
if( depth >= 3 ) {
|
if (depth >= 3) {
|
||||||
c = pricestack[--depth];
|
c = pricestack[--depth];
|
||||||
b = pricestack[--depth];
|
b = pricestack[--depth];
|
||||||
a = pricestack[--depth];
|
a = pricestack[--depth];
|
||||||
pricestack[depth++] = ((a * b) / SATOSHIDEN) * c;
|
pricestack[depth++] = ((a * b) / SATOSHIDEN) * c;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
errcode = -8;
|
errcode = -8;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PRICES_DDD:
|
case PRICES_DDD:
|
||||||
if( depth >= 3 ) {
|
if (depth >= 3) {
|
||||||
c = pricestack[--depth];
|
c = pricestack[--depth];
|
||||||
b = pricestack[--depth];
|
b = pricestack[--depth];
|
||||||
a = pricestack[--depth];
|
a = pricestack[--depth];
|
||||||
pricestack[depth++] = (((((SATOSHIDEN * SATOSHIDEN) / a) * SATOSHIDEN) / b) * SATOSHIDEN) / c;
|
pricestack[depth++] = (((((SATOSHIDEN * SATOSHIDEN) / a) * SATOSHIDEN) / b) * SATOSHIDEN) / c;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
errcode = -9;
|
errcode = -9;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
errcode = -10;
|
errcode = -10;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (errcode != 0)
|
if (errcode != 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
std::cerr << "pricestack[depth-1=" << depth-1 << "]=" << pricestack[depth-1] << std::endl;
|
std::cerr << "pricestack[depth=" << depth << "]=" << pricestack[depth] << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
free(pricedata);
|
free(pricedata);
|
||||||
|
|
||||||
if (errcode != 0)
|
if (errcode != 0)
|
||||||
std::cerr << "prices_syntheticprice warning: errcode in switch=" << errcode << std::endl;
|
std::cerr << "prices_syntheticprice warning: errcode in switch=" << errcode << std::endl;
|
||||||
|
|
||||||
if (den == 0) {
|
if (den == 0) {
|
||||||
std::cerr << "prices_syntheticprice den==0 return err=-11" << std::endl;
|
std::cerr << "prices_syntheticprice den==0 return err=-11" << std::endl;
|
||||||
return(-11);
|
return(-11);
|
||||||
|
|||||||
Reference in New Issue
Block a user