satoshiden to prices_normfactor (signed)
This commit is contained in:
@@ -35,7 +35,9 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo
|
|||||||
#define PRICES_MMD (KOMODO_MAXPRICES * 6) // 0011 0000 0000 0000
|
#define PRICES_MMD (KOMODO_MAXPRICES * 6) // 0011 0000 0000 0000
|
||||||
#define PRICES_MMM (KOMODO_MAXPRICES * 7) // 0011 1000 0000 0000
|
#define PRICES_MMM (KOMODO_MAXPRICES * 7) // 0011 1000 0000 0000
|
||||||
#define PRICES_DDD (KOMODO_MAXPRICES * 8) // 0100 0000 0000 0000
|
#define PRICES_DDD (KOMODO_MAXPRICES * 8) // 0100 0000 0000 0000
|
||||||
#define PRICES_NORMFACTOR 10000
|
|
||||||
|
#define PRICES_NORMFACTOR (int64_t)(SATOSHIDEN)
|
||||||
|
#define PRICES_POINTFACTOR (int64_t)10000
|
||||||
|
|
||||||
bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn);
|
bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn);
|
||||||
|
|
||||||
|
|||||||
@@ -640,7 +640,7 @@ int64_t prices_syntheticprice(std::vector<uint16_t> vec, int32_t height, int32_t
|
|||||||
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) / PRICES_NORMFACTOR;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
errcode = -3;
|
errcode = -3;
|
||||||
@@ -650,7 +650,7 @@ int64_t prices_syntheticprice(std::vector<uint16_t> vec, int32_t height, int32_t
|
|||||||
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 * PRICES_NORMFACTOR) / b;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
errcode = -4;
|
errcode = -4;
|
||||||
@@ -659,7 +659,7 @@ int64_t prices_syntheticprice(std::vector<uint16_t> vec, int32_t height, int32_t
|
|||||||
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++] = (PRICES_NORMFACTOR * PRICES_NORMFACTOR) / a;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
errcode = -5;
|
errcode = -5;
|
||||||
@@ -670,7 +670,7 @@ int64_t prices_syntheticprice(std::vector<uint16_t> vec, int32_t height, int32_t
|
|||||||
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 * PRICES_NORMFACTOR) / b) * PRICES_NORMFACTOR) / c;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
errcode = -6;
|
errcode = -6;
|
||||||
@@ -692,7 +692,7 @@ int64_t prices_syntheticprice(std::vector<uint16_t> vec, int32_t height, int32_t
|
|||||||
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) / PRICES_NORMFACTOR) * c;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
errcode = -8;
|
errcode = -8;
|
||||||
@@ -703,7 +703,7 @@ int64_t prices_syntheticprice(std::vector<uint16_t> vec, int32_t height, int32_t
|
|||||||
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++] = (((((PRICES_NORMFACTOR * PRICES_NORMFACTOR) / a) * PRICES_NORMFACTOR) / b) * PRICES_NORMFACTOR) / c;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
errcode = -9;
|
errcode = -9;
|
||||||
@@ -716,7 +716,7 @@ int64_t prices_syntheticprice(std::vector<uint16_t> vec, int32_t height, int32_t
|
|||||||
if (errcode != 0)
|
if (errcode != 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
std::cerr << "pricestack[depth=" << depth << "]=" << pricestack[depth] << std::endl;
|
std::cerr << "top pricestack[depth-1=" << depth-1 << "]=" << pricestack[depth-1] << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
free(pricedata);
|
free(pricedata);
|
||||||
@@ -759,8 +759,8 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
// clear lowest positions:
|
// clear lowest positions:
|
||||||
price /= PRICES_NORMFACTOR;
|
price /= PRICES_POINTFACTOR;
|
||||||
price *= PRICES_NORMFACTOR;
|
price *= PRICES_POINTFACTOR;
|
||||||
outprice = price;
|
outprice = price;
|
||||||
|
|
||||||
if (minmax) { // if we are within day window, set temp costbasis to max (or min) price value
|
if (minmax) { // if we are within day window, set temp costbasis to max (or min) price value
|
||||||
@@ -787,17 +787,17 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
// normalize to 10,000,000 to prevent underflow
|
// normalize to 10,000,000 to prevent underflow
|
||||||
profits = costbasis > 0 ? (((price / PRICES_NORMFACTOR * SATOSHIDEN) / costbasis) - SATOSHIDEN / PRICES_NORMFACTOR) * PRICES_NORMFACTOR : 0;
|
profits = costbasis > 0 ? (((price / PRICES_POINTFACTOR * PRICES_NORMFACTOR) / costbasis) - PRICES_NORMFACTOR / PRICES_POINTFACTOR) * PRICES_POINTFACTOR : 0;
|
||||||
|
|
||||||
//std::cerr << "prices_syntheticprofits() test value1 (price/PRICES_NORMFACTOR * SATOSHIDEN)=" << (price / PRICES_NORMFACTOR * SATOSHIDEN) << std::endl;
|
//std::cerr << "prices_syntheticprofits() test value1 (price/PRICES_POINTFACTOR * PRICES_NORMFACTOR)=" << (price / PRICES_POINTFACTOR * PRICES_NORMFACTOR) << std::endl;
|
||||||
std::cerr << "prices_syntheticprofits() test value2 (price/PRICES_NORMFACTOR * SATOSHIDEN)/costbasis=" << (costbasis != 0 ? (price / PRICES_NORMFACTOR * SATOSHIDEN)/costbasis : 0) << std::endl;
|
std::cerr << "prices_syntheticprofits() test value2 (price/PRICES_POINTFACTOR * PRICES_NORMFACTOR)/costbasis=" << (costbasis != 0 ? (price / PRICES_POINTFACTOR * PRICES_NORMFACTOR)/costbasis : 0) << std::endl;
|
||||||
|
|
||||||
std::cerr << "prices_syntheticprofits() fractional profits=" << profits << std::endl;
|
std::cerr << "prices_syntheticprofits() fractional profits=" << profits << std::endl;
|
||||||
//std::cerr << "prices_syntheticprofits() profits double=" << (double)price / (double)costbasis -1.0 << std::endl;
|
//std::cerr << "prices_syntheticprofits() profits double=" << (double)price / (double)costbasis -1.0 << std::endl;
|
||||||
//double dprofits = (double)price / (double)costbasis - 1.0;
|
//double dprofits = (double)price / (double)costbasis - 1.0;
|
||||||
|
|
||||||
profits *= ((int64_t)leverage * (int64_t)positionsize);
|
profits *= ((int64_t)leverage * (int64_t)positionsize);
|
||||||
profits /= (int64_t)SATOSHIDEN; // de-normalize
|
profits /= (int64_t)PRICES_NORMFACTOR; // de-normalize
|
||||||
|
|
||||||
//dprofits *= leverage * positionsize;
|
//dprofits *= leverage * positionsize;
|
||||||
std::cerr << "prices_syntheticprofits() profits=" << profits << std::endl;
|
std::cerr << "prices_syntheticprofits() profits=" << profits << std::endl;
|
||||||
@@ -892,6 +892,7 @@ int64_t prices_enumaddedbets(uint256 &batontxid, std::vector<BetInfo> &bets, uin
|
|||||||
EvalRef eval;
|
EvalRef eval;
|
||||||
|
|
||||||
if ((isLoaded = eval->GetTxConfirmed(batontxid, txBaton, blockIdx)) &&
|
if ((isLoaded = eval->GetTxConfirmed(batontxid, txBaton, blockIdx)) &&
|
||||||
|
blockIdx.IsValid() &&
|
||||||
txBaton.vout.size() > 0 &&
|
txBaton.vout.size() > 0 &&
|
||||||
(funcId = prices_addopretdecode(txBaton.vout.back().scriptPubKey, bettxidInOpret, pk, amount)) != 0)
|
(funcId = prices_addopretdecode(txBaton.vout.back().scriptPubKey, bettxidInOpret, pk, amount)) != 0)
|
||||||
{
|
{
|
||||||
@@ -1334,22 +1335,22 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight)
|
|||||||
for (auto b : bets) {
|
for (auto b : bets) {
|
||||||
totalbets += b.amount;
|
totalbets += b.amount;
|
||||||
totalprofits += b.profits;
|
totalprofits += b.profits;
|
||||||
costbasis += b.amount * (b.costbasis / PRICES_NORMFACTOR); // prevent int64 overflow
|
costbasis += b.amount * (b.costbasis / PRICES_POINTFACTOR); // prevent int64 overflow
|
||||||
std::cerr << "PricesInfo() acc costbasis=" << costbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_NORMFACTOR=" << (b.costbasis / PRICES_NORMFACTOR) << std::endl;
|
std::cerr << "PricesInfo() acc costbasis=" << costbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_POINTFACTOR=" << (b.costbasis / PRICES_POINTFACTOR) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t equity = totalbets + totalprofits;
|
int64_t equity = totalbets + totalprofits;
|
||||||
if (totalbets != 0) { //prevent zero div
|
if (totalbets != 0) { //prevent zero div
|
||||||
costbasis /= totalbets;
|
costbasis /= totalbets;
|
||||||
costbasis *= PRICES_NORMFACTOR; //denormalization, last posiitons should be == 0000
|
costbasis *= PRICES_POINTFACTOR; //denormalization, last posiitons should be == 0000
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
costbasis = 0;
|
costbasis = 0;
|
||||||
int64_t liqprice;
|
int64_t liqprice;
|
||||||
if (leverage != 0) {// prevent zero div
|
if (leverage != 0) {// prevent zero div
|
||||||
liqprice = costbasis - costbasis / leverage;
|
liqprice = costbasis - costbasis / leverage;
|
||||||
liqprice /= PRICES_NORMFACTOR;
|
liqprice /= PRICES_POINTFACTOR;
|
||||||
liqprice *= PRICES_NORMFACTOR; // last posiitons should be == 0000
|
liqprice *= PRICES_POINTFACTOR; // last posiitons should be == 0000
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
liqprice = 0;
|
liqprice = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user