pricessetcostbasis added
This commit is contained in:
+1
-1
@@ -40,7 +40,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx
|
|||||||
// CCcustom
|
// CCcustom
|
||||||
UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector<std::string> synthetic);
|
UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector<std::string> synthetic);
|
||||||
UniValue PricesAddFunding(uint64_t txfee,uint256 bettxid,int64_t amount);
|
UniValue PricesAddFunding(uint64_t txfee,uint256 bettxid,int64_t amount);
|
||||||
UniValue PricesSetcostbasis(uint64_t txfee,uint256 bettxid);
|
UniValue PricesSetcostbasis(int64_t txfee,uint256 bettxid);
|
||||||
UniValue PricesRekt(uint64_t txfee,uint256 bettxid,int32_t rektheight);
|
UniValue PricesRekt(uint64_t txfee,uint256 bettxid,int32_t rektheight);
|
||||||
UniValue PricesCashout(uint64_t txfee,uint256 bettxid);
|
UniValue PricesCashout(uint64_t txfee,uint256 bettxid);
|
||||||
UniValue PricesInfo(uint256 bettxid,int32_t refheight);
|
UniValue PricesInfo(uint256 bettxid,int32_t refheight);
|
||||||
|
|||||||
+23
-12
@@ -362,11 +362,12 @@ int64_t prices_syntheticprice(std::vector<uint16_t> vec,int32_t height,int32_t m
|
|||||||
pricestack[depth] = 0;
|
pricestack[depth] = 0;
|
||||||
if ( prices_extract(pricedata,height,1,value) == 0 )
|
if ( prices_extract(pricedata,height,1,value) == 0 )
|
||||||
{
|
{
|
||||||
// push to the prices stack
|
// push price to the prices stack
|
||||||
if ( minmax == 0 )
|
if ( minmax == 0 )
|
||||||
pricestack[depth] = pricedata[2];
|
pricestack[depth] = pricedata[2]; // use smoothed value if we are over 24h
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// if we are within 24h use min or max price
|
||||||
if ( leverage > 0 )
|
if ( leverage > 0 )
|
||||||
pricestack[depth] = (pricedata[1] > pricedata[2]) ? pricedata[1] : pricedata[2]; // MAX
|
pricestack[depth] = (pricedata[1] > pricedata[2]) ? pricedata[1] : pricedata[2]; // MAX
|
||||||
else
|
else
|
||||||
@@ -495,20 +496,29 @@ int64_t prices_syntheticprice(std::vector<uint16_t> vec,int32_t height,int32_t m
|
|||||||
|
|
||||||
int64_t prices_syntheticprofits(int64_t &costbasis,int32_t firstheight,int32_t height,int16_t leverage,std::vector<uint16_t> vec,int64_t positionsize,int64_t addedbets)
|
int64_t prices_syntheticprofits(int64_t &costbasis,int32_t firstheight,int32_t height,int16_t leverage,std::vector<uint16_t> vec,int64_t positionsize,int64_t addedbets)
|
||||||
{
|
{
|
||||||
int64_t price,profits = 0; int32_t minmax;
|
int64_t price, profits = 0;
|
||||||
minmax = (height > firstheight+PRICES_DAYWINDOW);
|
|
||||||
|
if (firstheight >= 0) { // >=0 means request to find costbase
|
||||||
|
int32_t minmax = (height < firstheight + PRICES_DAYWINDOW); // use minmax value if we are within 24h
|
||||||
|
|
||||||
if ((price = prices_syntheticprice(vec, height, minmax, leverage)) < 0)
|
if ((price = prices_syntheticprice(vec, height, minmax, leverage)) < 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "unexpected zero synthetic price at height.%d\n", height);
|
fprintf(stderr, "unexpected zero synthetic price at height.%d\n", height);
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
if ( minmax != 0 )
|
if (minmax /*!= 0*/) // if we are within day window, use bigger or lesser value
|
||||||
{
|
{
|
||||||
if (leverage > 0 && price > costbasis)
|
if (leverage > 0 && price > costbasis)
|
||||||
costbasis = price;
|
costbasis = price; // set costbasis
|
||||||
else if (leverage < 0 && (costbasis == 0 || price < costbasis))
|
else if (leverage < 0 && (costbasis == 0 || price < costbasis))
|
||||||
costbasis = price;
|
costbasis = price;
|
||||||
|
// else -> use the previous value
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
costbasis = price; //??
|
||||||
|
}
|
||||||
|
// else < 0 then use the passed costbase
|
||||||
|
|
||||||
profits = costbasis > 0 ? ((price * SATOSHIDEN) / costbasis) - SATOSHIDEN : 0;
|
profits = costbasis > 0 ? ((price * SATOSHIDEN) / costbasis) - SATOSHIDEN : 0;
|
||||||
profits *= leverage * positionsize;
|
profits *= leverage * positionsize;
|
||||||
return(positionsize + addedbets + profits);
|
return(positionsize + addedbets + profits);
|
||||||
@@ -567,10 +577,10 @@ UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector<st
|
|||||||
if ( AddNormalinputs(mtx,mypk,amount+5*txfee,64) >= amount+5*txfee )
|
if ( AddNormalinputs(mtx,mypk,amount+5*txfee,64) >= amount+5*txfee )
|
||||||
{
|
{
|
||||||
betamount = (amount * 199) / 200;
|
betamount = (amount * 199) / 200;
|
||||||
mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // marker
|
|
||||||
mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); // baton for total funding
|
mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); // baton for total funding
|
||||||
mtx.vout.push_back(MakeCC1vout(cp->evalcode,(amount-betamount)+2*txfee,pricespk));
|
mtx.vout.push_back(MakeCC1vout(cp->evalcode,(amount-betamount)+2*txfee,pricespk));
|
||||||
mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,betamount,pricespk,mypk));
|
mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,betamount,pricespk,mypk));
|
||||||
|
mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // marker
|
||||||
rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,prices_betopret(mypk,nextheight-1,amount,leverage,firstprice,vec,zeroid));
|
rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,prices_betopret(mypk,nextheight-1,amount,leverage,firstprice,vec,zeroid));
|
||||||
return(prices_rawtxresult(result,rawtx,0));
|
return(prices_rawtxresult(result,rawtx,0));
|
||||||
}
|
}
|
||||||
@@ -612,7 +622,7 @@ UniValue PricesAddFunding(uint64_t txfee,uint256 bettxid,int64_t amount)
|
|||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue PricesSetcostbasis(uint64_t txfee,uint256 bettxid)
|
UniValue PricesSetcostbasis(int64_t txfee,uint256 bettxid)
|
||||||
{
|
{
|
||||||
int32_t nextheight = komodo_nextheight();
|
int32_t nextheight = komodo_nextheight();
|
||||||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ);
|
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ);
|
||||||
@@ -628,10 +638,10 @@ UniValue PricesSetcostbasis(uint64_t txfee,uint256 bettxid)
|
|||||||
{
|
{
|
||||||
addedbets = prices_batontxid(batontxid, bettx, bettxid);
|
addedbets = prices_batontxid(batontxid, bettx, bettxid);
|
||||||
mtx.vin.push_back(CTxIn(bettxid,1,CScript()));
|
mtx.vin.push_back(CTxIn(bettxid,1,CScript()));
|
||||||
for (i=0; i<PRICES_DAYWINDOW; i++)
|
for (i=0; i<PRICES_DAYWINDOW; i++) // we need a full day to check if there was a rekt
|
||||||
{
|
{
|
||||||
if ( (profits= prices_syntheticprofits(costbasis,firstheight,firstheight+i,leverage,vec,positionsize,addedbets)) < 0 )
|
if ( (profits= prices_syntheticprofits(costbasis,firstheight,firstheight+i,leverage,vec,positionsize,addedbets)) < 0 )
|
||||||
{
|
{ // we are in loss
|
||||||
result.push_back(Pair("rekt",(int64_t)1));
|
result.push_back(Pair("rekt",(int64_t)1));
|
||||||
result.push_back(Pair("rektheight",(int64_t)firstheight+i));
|
result.push_back(Pair("rektheight",(int64_t)firstheight+i));
|
||||||
break;
|
break;
|
||||||
@@ -639,8 +649,9 @@ UniValue PricesSetcostbasis(uint64_t txfee,uint256 bettxid)
|
|||||||
}
|
}
|
||||||
if ( i == PRICES_DAYWINDOW )
|
if ( i == PRICES_DAYWINDOW )
|
||||||
result.push_back(Pair("rekt",0));
|
result.push_back(Pair("rekt",0));
|
||||||
|
|
||||||
prices_betjson(result,profits,costbasis,positionsize,addedbets,leverage,firstheight,firstprice);
|
prices_betjson(result,profits,costbasis,positionsize,addedbets,leverage,firstheight,firstprice);
|
||||||
myfee = bettx.vout[1].nValue / 10;
|
myfee = bettx.vout[1].nValue / 10; // fee for setting costbasis
|
||||||
result.push_back(Pair("myfee",myfee));
|
result.push_back(Pair("myfee",myfee));
|
||||||
mtx.vout.push_back(CTxOut(myfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
|
mtx.vout.push_back(CTxOut(myfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
|
||||||
mtx.vout.push_back(MakeCC1vout(cp->evalcode,bettx.vout[1].nValue-myfee-txfee,pricespk));
|
mtx.vout.push_back(MakeCC1vout(cp->evalcode,bettx.vout[1].nValue-myfee-txfee,pricespk));
|
||||||
@@ -669,7 +680,7 @@ UniValue PricesRekt(uint64_t txfee,uint256 bettxid,int32_t rektheight)
|
|||||||
{
|
{
|
||||||
costbasis = prices_costbasis(bettx);
|
costbasis = prices_costbasis(bettx);
|
||||||
addedbets = prices_batontxid(batontxid,bettx,bettxid);
|
addedbets = prices_batontxid(batontxid,bettx,bettxid);
|
||||||
if ( (profits= prices_syntheticprofits(ignore,firstheight,rektheight,leverage,vec,positionsize,addedbets)) < 0 )
|
if ( (profits= prices_syntheticprofits(costbasis /*ignore*/, -1, rektheight, leverage, vec, positionsize, addedbets)) < 0 )
|
||||||
{
|
{
|
||||||
myfee = (positionsize + addedbets) / 500;
|
myfee = (positionsize + addedbets) / 500;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -465,6 +465,7 @@ static const CRPCCommand vRPCCommands[] =
|
|||||||
{ "prices", "priceslist", &priceslist, true },
|
{ "prices", "priceslist", &priceslist, true },
|
||||||
{ "prices", "pricesinfo", &pricesinfo, true },
|
{ "prices", "pricesinfo", &pricesinfo, true },
|
||||||
{ "prices", "pricesbet", &pricesbet, true },
|
{ "prices", "pricesbet", &pricesbet, true },
|
||||||
|
{ "prices", "pricesbet", &pricessetcostbasis, true },
|
||||||
|
|
||||||
// Pegs
|
// Pegs
|
||||||
{ "pegs", "pegsaddress", &pegsaddress, true },
|
{ "pegs", "pegsaddress", &pegsaddress, true },
|
||||||
|
|||||||
@@ -498,6 +498,7 @@ extern UniValue paxwithdraw(const UniValue& params, bool fHelp);
|
|||||||
|
|
||||||
extern UniValue prices(const UniValue& params, bool fHelp);
|
extern UniValue prices(const UniValue& params, bool fHelp);
|
||||||
extern UniValue pricesbet(const UniValue& params, bool fHelp);
|
extern UniValue pricesbet(const UniValue& params, bool fHelp);
|
||||||
|
extern UniValue pricessetcostbasis(const UniValue& params, bool fHelp);
|
||||||
|
|
||||||
// test rpc:
|
// test rpc:
|
||||||
extern UniValue test_ac(const UniValue& params, bool fHelp);
|
extern UniValue test_ac(const UniValue& params, bool fHelp);
|
||||||
|
|||||||
Reference in New Issue
Block a user