Browse Source

Merge pull request #716 from jl777/jl777

numutxos now means number above median
ave is the median value
max is the max value that can be traded for
patch-3
jl777 7 years ago
committed by GitHub
parent
commit
83b37a1fa7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      crypto777/iguana_utils.c
  2. 1
      iguana/exchanges/LP_include.h
  3. 5
      iguana/exchanges/LP_portfolio.c
  4. 6
      iguana/exchanges/LP_prices.c
  5. 25
      iguana/exchanges/LP_remember.c
  6. 9
      iguana/exchanges/LP_signatures.c
  7. 43
      iguana/exchanges/LP_utxo.c
  8. 2
      iguana/exchanges/client
  9. 2
      iguana/exchanges/coins

4
crypto777/iguana_utils.c

@ -557,7 +557,7 @@ int _increasing_uint64(const void *a,const void *b)
#undef uint64_b
}
static int _decreasing_uint64(const void *a,const void *b)
int _decreasing_uint64(const void *a,const void *b)
{
#define uint64_a (*(uint64_t *)a)
#define uint64_b (*(uint64_t *)b)
@ -570,7 +570,7 @@ static int _decreasing_uint64(const void *a,const void *b)
#undef uint64_b
}
static int _decreasing_uint32(const void *a,const void *b)
int _decreasing_uint32(const void *a,const void *b)
{
#define uint32_a (*(uint32_t *)a)
#define uint32_b (*(uint32_t *)b)

1
iguana/exchanges/LP_include.h

@ -572,6 +572,7 @@ int64_t LP_dynamictrust(int64_t credits,bits256 pubkey,int64_t kmdvalue);
struct LP_address *LP_addressfind(struct iguana_info *coin,char *coinaddr);
int64_t LP_outpoint_amount(char *symbol,bits256 txid,int32_t vout);
void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint16_t myport,uint16_t netid,char *seednode);
int _decreasing_uint64(const void *a,const void *b);
void LP_listunspent_query(char *symbol,char *coinaddr);
int32_t bitcoin_priv2wif(char *symbol,uint8_t wiftaddr,char *wifstr,bits256 privkey,uint8_t addrtype);

5
iguana/exchanges/LP_portfolio.c

@ -459,6 +459,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp)
{
static cJSON *tickerjson; static uint32_t lasttime;
char *retstr,*base,*rel; cJSON *retjson,*bid,*ask,*fundjson,*argjson; uint64_t bidsatoshis,asksatoshis; int32_t i,changed; double bidprice,askprice,bch_usd,bch_btc,nxtkmd,price,factor,offset,newprice,buymargin,sellmargin,price_btc,price_usd,kmd_btc,kmd_usd; struct LP_priceinfo *kmdpp,*fiatpp,*nxtpp,*basepp,*relpp;
printf("AUTOPRICE numautorefs.%d\n",num_LP_autorefs);
if ( (retstr= issue_curlt("https://bittrex.com/api/v1.1/public/getmarketsummaries",LP_HTTP_TIMEOUT*10)) == 0 )
{
printf("trex error getting marketsummaries\n");
@ -570,7 +571,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp)
}
else if ( strcmp(LP_autorefs[i].refrel,"coinmarketcap") == 0 )
{
//printf("%s/%s for %s/%s margin %.8f/%.8f\n",base,rel,LP_autorefs[i].refbase,LP_autorefs[i].refrel,buymargin,sellmargin);
printf("%s/%s for %s/%s margin %.8f/%.8f\n",base,rel,LP_autorefs[i].refbase,LP_autorefs[i].refrel,buymargin,sellmargin);
if ( (price_btc= LP_CMCbtcprice(&price_usd,LP_autorefs[i].refbase)) > SMALLVAL )
{
if ( strcmp(rel,"KMD") == 0 && kmd_btc > SMALLVAL )
@ -677,7 +678,7 @@ int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson)
refrel = jstr(argjson,"refrel");
fundvalue_bid = jstr(argjson,"fundvalue_bid");
fundvalue_ask = jstr(argjson,"fundvalue_ask");
if ( fundvalue_bid != 0 || fundvalue_ask != 0 || fixedprice > SMALLVAL || (refbase != 0 && refrel != 0) )
if ( fundvalue_bid != 0 || fundvalue_ask != 0 || fixedprice > SMALLVAL || (refbase != 0 && refrel != 0 && strlen(refbase) > 0 && strlen(refrel) > 0) )
{
if ( fixedprice > SMALLVAL )
{

6
iguana/exchanges/LP_prices.c

@ -755,9 +755,9 @@ cJSON *LP_orderbookjson(char *symbol,struct LP_orderbookentry *op)
jaddstr(item,"address",op->coinaddr);
jaddnum(item,"price",op->price);
jaddnum(item,"numutxos",op->numutxos);
jaddnum(item,"avevolume",dstr(op->avesatoshis)*0.8);
jaddnum(item,"maxvolume",dstr(op->maxsatoshis)*0.8);
jaddnum(item,"depth",dstr(op->depth)*0.8);
jaddnum(item,"avevolume",dstr(op->avesatoshis));
jaddnum(item,"maxvolume",dstr(op->maxsatoshis));
jaddnum(item,"depth",dstr(op->depth));
jaddbits256(item,"pubkey",op->pubkey);
jaddnum(item,"age",time(NULL)-op->timestamp);
jaddnum(item,"zcredits",dstr(op->dynamictrust));

25
iguana/exchanges/LP_remember.c

@ -440,7 +440,7 @@ int32_t basilisk_isbobcoin(int32_t iambob,int32_t ind)
}
}
int32_t basilisk_swap_isfinished(uint32_t requestid,uint32_t quoteid,uint32_t expiration,int32_t iambob,bits256 *txids,int32_t *sentflags,bits256 paymentspent,bits256 Apaymentspent,bits256 depositspent)
int32_t basilisk_swap_isfinished(uint32_t requestid,uint32_t quoteid,uint32_t expiration,int32_t iambob,bits256 *txids,int32_t *sentflags,bits256 paymentspent,bits256 Apaymentspent,bits256 depositspent,uint32_t lockduration)
{
int32_t i,n = 0; uint32_t now = (uint32_t)time(NULL);
if ( bits256_nonz(paymentspent) != 0 && bits256_nonz(Apaymentspent) != 0 && bits256_nonz(depositspent) != 0 )
@ -460,7 +460,7 @@ int32_t basilisk_swap_isfinished(uint32_t requestid,uint32_t quoteid,uint32_t ex
} else return(1);
}
}
if ( now > expiration - INSTANTDEX_LOCKTIME )
if ( now > expiration - lockduration )
{
if ( bits256_nonz(paymentspent) != 0 )
n++;
@ -683,7 +683,7 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap)
int32_t LP_rswap_init(struct LP_swap_remember *rswap,uint32_t requestid,uint32_t quoteid,int32_t forceflag)
{
char fname[1024],*fstr,*secretstr,*srcstr,*deststr,*dest33,*txname; long fsize; cJSON *item,*txobj,*array; bits256 privkey; struct iguana_info *coin; uint32_t r,q; int32_t i,j,n; uint8_t other33[33];
char fname[1024],*fstr,*secretstr,*srcstr,*deststr,*dest33,*txname; long fsize; cJSON *item,*txobj,*array; bits256 privkey; struct iguana_info *coin; uint32_t r,q; int32_t i,j,n; uint8_t other33[33]; uint32_t lockduration;
memset(rswap,0,sizeof(*rswap));
rswap->requestid = requestid;
rswap->quoteid = quoteid;
@ -816,7 +816,8 @@ int32_t LP_rswap_init(struct LP_swap_remember *rswap,uint32_t requestid,uint32_t
}
free_json(txobj);
}
rswap->origfinishedflag = basilisk_swap_isfinished(requestid,quoteid,rswap->expiration,rswap->iambob,rswap->txids,rswap->sentflags,rswap->paymentspent,rswap->Apaymentspent,rswap->depositspent);
lockduration = LP_atomic_locktime(rswap->bobcoin,rswap->alicecoin);
rswap->origfinishedflag = basilisk_swap_isfinished(requestid,quoteid,rswap->expiration,rswap->iambob,rswap->txids,rswap->sentflags,rswap->paymentspent,rswap->Apaymentspent,rswap->depositspent,lockduration);
rswap->finishedflag = rswap->origfinishedflag;
if ( forceflag != 0 )
rswap->finishedflag = rswap->origfinishedflag = 0;
@ -1067,7 +1068,7 @@ int32_t LP_spends_set(struct LP_swap_remember *rswap)
cJSON *basilisk_remember(int32_t fastflag,int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requestid,uint32_t quoteid,int32_t forceflag,int32_t pendingonly)
{
static void *ctx;
struct LP_swap_remember rswap; int32_t i,j,flag,numspent,len,secretstart,redeemlen; char str[65],*srcAdest,*srcBdest,*destAdest,*destBdest,otheraddr[64],*fstr,fname[512],bobtomic[128],alicetomic[128],bobstr[65],alicestr[65]; cJSON *item,*txoutobj,*retjson; bits256 rev,revAm,signedtxid,zero,deadtxid; uint32_t claimtime; struct iguana_info *bob=0,*alice=0; uint8_t redeemscript[1024],userdata[1024]; long fsize;
struct LP_swap_remember rswap; int32_t i,j,flag,numspent,len,secretstart,redeemlen; char str[65],*srcAdest,*srcBdest,*destAdest,*destBdest,otheraddr[64],*fstr,fname[512],bobtomic[128],alicetomic[128],bobstr[65],alicestr[65]; cJSON *item,*txoutobj,*retjson; bits256 rev,revAm,signedtxid,zero,deadtxid; uint32_t claimtime,lockduration; struct iguana_info *bob=0,*alice=0; uint8_t redeemscript[1024],userdata[1024]; long fsize;
sprintf(fname,"%s/SWAPS/%u-%u.finished",GLOBAL_DBDIR,requestid,quoteid), OS_compatible_path(fname);
if ( (fstr= OS_filestr(&fsize,fname)) != 0 )
{
@ -1096,6 +1097,7 @@ cJSON *basilisk_remember(int32_t fastflag,int64_t *KMDtotals,int64_t *BTCtotals,
bob = LP_coinfind(rswap.bobcoin);
LP_etomicsymbol(bobstr,bobtomic,rswap.src);
LP_etomicsymbol(alicestr,alicetomic,rswap.dest);
lockduration = LP_atomic_locktime(rswap.bobcoin,rswap.alicecoin);
if ( rswap.bobcoin[0] == 0 || rswap.alicecoin[0] == 0 || strcmp(rswap.bobcoin,bobstr) != 0 || strcmp(rswap.alicecoin,alicestr) != 0 )
{
//printf("legacy r%u-q%u DB SWAPS.(%u %u) %llu files BOB.(%s) Alice.(%s) src.(%s) dest.(%s)\n",requestid,quoteid,rswap.requestid,rswap.quoteid,(long long)rswap.aliceid,rswap.bobcoin,rswap.alicecoin,rswap.src,rswap.dest);
@ -1216,7 +1218,7 @@ cJSON *basilisk_remember(int32_t fastflag,int64_t *KMDtotals,int64_t *BTCtotals,
rswap.paymentspent = basilisk_swap_spendupdate(rswap.iambob,rswap.bobcoin,rswap.bobpaymentaddr,rswap.sentflags,rswap.txids,BASILISK_BOBPAYMENT,BASILISK_ALICESPEND,BASILISK_BOBRECLAIM,0,srcAdest,srcBdest,rswap.Adestaddr,rswap.destaddr);
rswap.Apaymentspent = basilisk_swap_spendupdate(rswap.iambob,rswap.alicecoin,rswap.alicepaymentaddr,rswap.sentflags,rswap.txids,BASILISK_ALICEPAYMENT,BASILISK_ALICERECLAIM,BASILISK_BOBSPEND,0,destAdest,destBdest,rswap.Adestaddr,rswap.destaddr);
rswap.depositspent = basilisk_swap_spendupdate(rswap.iambob,rswap.bobcoin,rswap.bobdepositaddr,rswap.sentflags,rswap.txids,BASILISK_BOBDEPOSIT,BASILISK_ALICECLAIM,BASILISK_BOBREFUND,0,srcAdest,srcBdest,rswap.Adestaddr,rswap.destaddr);
rswap.finishedflag = basilisk_swap_isfinished(requestid,quoteid,rswap.expiration,rswap.iambob,rswap.txids,rswap.sentflags,rswap.paymentspent,rswap.Apaymentspent,rswap.depositspent);
rswap.finishedflag = basilisk_swap_isfinished(requestid,quoteid,rswap.expiration,rswap.iambob,rswap.txids,rswap.sentflags,rswap.paymentspent,rswap.Apaymentspent,rswap.depositspent,lockduration);
LP_spends_set(&rswap);
if ( rswap.iambob == 0 )
{
@ -1455,7 +1457,14 @@ cJSON *basilisk_remember(int32_t fastflag,int64_t *KMDtotals,int64_t *BTCtotals,
free_json(txoutobj), flag = 0;
else flag = -1, rswap.depositspent = deadtxid;
}
if ( flag == 0 && (bits256_nonz(rswap.Apaymentspent) != 0 || time(NULL) > rswap.dlocktime-777 || (bits256_nonz(rswap.txids[BASILISK_ALICEPAYMENT]) == 0 && time(NULL) > rswap.plocktime-777) || (bits256_nonz(rswap.txids[BASILISK_BOBPAYMENT]) == 0 && time(NULL) > rswap.dlocktime-3*INSTANTDEX_LOCKTIME/2)) )
//printf("lockduration.%d plocktime.%u lag.%d\n",lockduration,rswap.plocktime,(int32_t)(time(NULL) - (rswap.plocktime-lockduration+1800)));
if ( flag == 0 && (
bits256_nonz(rswap.Apaymentspent) != 0 ||
time(NULL) > rswap.dlocktime-777 ||
(bits256_nonz(rswap.txids[BASILISK_ALICEPAYMENT]) == 0 && time(NULL) > rswap.plocktime-777) ||
(bits256_nonz(rswap.txids[BASILISK_BOBPAYMENT]) != 0 && rswap.sentflags[BASILISK_BOBPAYMENT] == 0 && time(NULL) > rswap.plocktime-lockduration+1800) || // failed bobpayment
(bits256_nonz(rswap.txids[BASILISK_BOBPAYMENT]) == 0 && time(NULL) > rswap.dlocktime-3*lockduration/2)
) )
{
//printf("do the refund! paymentspent.%s now.%u vs expiration.%u\n",bits256_str(str,rswap.paymentspent),(uint32_t)time(NULL),rswap.expiration);
//if ( txbytes[BASILISK_BOBREFUND] == 0 )
@ -1508,7 +1517,7 @@ cJSON *basilisk_remember(int32_t fastflag,int64_t *KMDtotals,int64_t *BTCtotals,
LP_totals_update(rswap.iambob,rswap.alicecoin,rswap.bobcoin,KMDtotals,BTCtotals,rswap.sentflags,rswap.values);
if ( (numspent= LP_spends_set(&rswap)) == 3 )
rswap.finishedflag = 1;
else rswap.finishedflag = basilisk_swap_isfinished(requestid,quoteid,rswap.expiration,rswap.iambob,rswap.txids,rswap.sentflags,rswap.paymentspent,rswap.Apaymentspent,rswap.depositspent);
else rswap.finishedflag = basilisk_swap_isfinished(requestid,quoteid,rswap.expiration,rswap.iambob,rswap.txids,rswap.sentflags,rswap.paymentspent,rswap.Apaymentspent,rswap.depositspent,lockduration);
if ( rswap.origfinishedflag == 0 && rswap.finishedflag != 0 )
{
char fname[1024],*itemstr; FILE *fp;

9
iguana/exchanges/LP_signatures.c

@ -422,9 +422,8 @@ int32_t LP_price_sigadd(cJSON *item,uint32_t timestamp,bits256 priv,uint8_t *pub
char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price)
{
struct iguana_info *basecoin,*relcoin,*kmd; struct LP_address *ap; char pubsecpstr[67]; uint32_t numutxos,timestamp; uint64_t price64,balance,minsize,maxsize; bits256 zero; cJSON *reqjson;
struct iguana_info *basecoin,*relcoin,*kmd; struct LP_address *ap; char pubsecpstr[67]; uint32_t numutxos,timestamp; uint64_t price64,median,minsize,maxsize; bits256 zero; cJSON *reqjson;
reqjson = cJSON_CreateObject();
// LP_addsig
if ( (basecoin= LP_coinfind(base)) != 0 && (relcoin= LP_coinfind(rel)) != 0 )//&& basecoin->electrum == 0 )//&& relcoin->electrum == 0 )
{
memset(zero.bytes,0,sizeof(zero));
@ -441,12 +440,12 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re
jaddstr(reqjson,"pubsecp",pubsecpstr);
if ( (kmd= LP_coinfind("KMD")) != 0 && (ap= LP_address(kmd,kmd->smartaddr)) != 0 && ap->instantdex_credits != 0 )
jaddnum(reqjson,"credits",dstr(ap->instantdex_credits));
if ( (numutxos= LP_address_minmax(&balance,&minsize,&maxsize,basecoin,basecoin->smartaddr)) != 0 )
if ( (numutxos= LP_address_minmax(&median,&minsize,&maxsize,basecoin,basecoin->smartaddr)) != 0 )
{
//printf("send %s numutxos.%d balance %.8f min %.8f max %.8f\n",base,numutxos,dstr(balance),dstr(minsize),dstr(maxsize));
//printf("send %s numutxos.%d median %.8f min %.8f max %.8f\n",base,numutxos,dstr(median),dstr(minsize),dstr(maxsize));
jaddstr(reqjson,"utxocoin",base);
jaddnum(reqjson,"n",numutxos);
jaddnum(reqjson,"bal",dstr(balance));
jaddnum(reqjson,"bal",dstr(median) * numutxos);
jaddnum(reqjson,"min",dstr(minsize));
jaddnum(reqjson,"max",dstr(maxsize));
}

43
iguana/exchanges/LP_utxo.c

@ -283,30 +283,57 @@ struct LP_address *LP_address(struct iguana_info *coin,char *coinaddr)
return(ap);
}
int32_t LP_address_minmax(uint64_t *balancep,uint64_t *minp,uint64_t *maxp,struct iguana_info *coin,char *coinaddr)
int32_t LP_address_minmax(uint64_t *medianp,uint64_t *minp,uint64_t *maxp,struct iguana_info *coin,char *coinaddr)
{
cJSON *array,*item; bits256 txid,zero; int64_t value; int32_t i,vout,height,n = 0;
*minp = *maxp = *balancep = 0;
cJSON *array,*item; bits256 txid,zero; int64_t max,max2,value,*buf; int32_t i,m=0,vout,height,n = 0;
*minp = *maxp = *medianp = max = max2 = 0;
memset(zero.bytes,0,sizeof(zero));
if ( (array= LP_listunspent(coin->symbol,coinaddr,zero,zero)) != 0 )
{
//printf("address minmax.(%s)\n",jprint(array,0));
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
for (i=0; i<n; i++)
buf = calloc(sizeof(*buf),n);
for (i=m=0; i<n; i++)
{
item = jitem(array,i);
value = LP_listunspent_parseitem(coin,&txid,&vout,&height,item);
if ( value > *maxp )
*maxp = value;
if ( LP_allocated(txid,vout) != 0 )
continue;
buf[m++] = value;
if ( value > max )
{
max2 = max;
max = value;
}
else if ( value > max2 )
max2 = value;
if ( *minp == 0 || value < *minp )
*minp = value;
*balancep += value;
}
if ( m > 1 )
{
revsort64s(buf,m,sizeof(*buf));
if ( max == buf[0] && max2 == buf[1] )
{
for (i=1; i<m; i++)
{
if ( max >= LP_DEPOSITSATOSHIS(buf[i]) )
{
*maxp = buf[i];
*medianp = buf[m/2];
break;
}
}
}
else printf("sort error? max %.8f != %.8f\n",dstr(max),dstr(buf[0]));
} else *minp = *maxp = *medianp = 0;
free(buf);
}
free_json(array);
}
return(n);
//printf("addressmin max %s %.8f %.8f %.8f num.%d\n",coin->symbol,dstr(*minp),dstr(*maxp),dstr(*medianp),m);
return(m/2);
}
int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_address_utxo **utxos,int32_t max,struct LP_address *ap,char *coinaddr)

2
iguana/exchanges/client

@ -3,7 +3,7 @@ source passphrase
source coins
./stop
git pull;
cp ../exchanges/updateprices;./updateprices
cp ../exchanges/updateprices .;./updateprices
cd ..;
./m_mm;
pkill -15 marketmaker;

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save