Browse Source

Test

etomic
jl777 8 years ago
parent
commit
d42ef22396
  1. 2
      iguana/exchanges/LP_commands.c
  2. 1
      iguana/exchanges/LP_include.h
  3. 2
      iguana/exchanges/LP_prices.c
  4. 30
      iguana/exchanges/LP_quotes.c
  5. 3
      iguana/exchanges/LP_utxos.c

2
iguana/exchanges/LP_commands.c

@ -309,7 +309,7 @@ getprice(base, rel)\n\
if ( (utxo= LP_utxofind(txid,vout)) == 0 )
return(clonestr("{\"error\":\"txid/vout not found\"}"));
if ( strcmp(method,"candidates") == 0 )
return(jprint(LP_tradecandidates(utxo,coin),1));
return(jprint(LP_tradecandidates(coin),1));
else return(jprint(LP_autotrade(utxo,coin,jdouble(argjson,"maxprice")),1));
}
}

1
iguana/exchanges/LP_include.h

@ -205,5 +205,6 @@ char *bitcoind_passthru(char *coinstr,char *serverport,char *userpass,char *meth
uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t maxlen,struct basilisk_rawtx *rawtx,uint32_t nextbits,int32_t suppress_swapsend);
double LP_query(char *method,struct LP_quoteinfo *qp,char *ipaddr,uint16_t port,char *base,char *rel,bits256 mypub);
int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct basilisk_rawtx *rawtx,int32_t v,uint8_t *recvbuf,int32_t recvlen,int32_t suppress_pubkeys);
void LP_quotesinit(char *base,char *rel);
#endif

2
iguana/exchanges/LP_prices.c

@ -356,6 +356,8 @@ char *LP_orderbook(char *base,char *rel)
jaddstr(retjson,"base",base);
jaddstr(retjson,"rel",rel);
jaddnum(retjson,"timestamp",now);
if ( numbids == 0 && numasks == 0 )
LP_quotesinit(base,rel);
return(jprint(retjson,1));
}

30
iguana/exchanges/LP_quotes.c

@ -196,14 +196,14 @@ int32_t LP_arrayfind(cJSON *array,bits256 txid,int32_t vout)
return(-1);
}
cJSON *LP_tradecandidates(struct LP_utxoinfo *myutxo,char *base)
cJSON *LP_tradecandidates(char *base)
{
struct LP_peerinfo *peer,*tmp; struct LP_quoteinfo Q; char *utxostr,coinstr[16]; cJSON *array,*retarray=0,*item; int32_t i,n,totaladded,added; double price;
if ( (price= LP_price(base,myutxo->coin)) == .0 )
/*if ( (price= LP_price(base,myutxo->coin)) == .0 )
{
printf("no LP_price (%s -> %s)\n",base,myutxo->coin);
return(0);
}
}*/
totaladded = 0;
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
@ -248,6 +248,30 @@ cJSON *LP_tradecandidates(struct LP_utxoinfo *myutxo,char *base)
return(retarray);
}
void LP_quotesinit(char *base,char *rel)
{
cJSON *array,*item; struct LP_quoteinfo Q; bits256 zero; int32_t i,n,iter;
memset(&zero,0,sizeof(zero));
for (iter=0; iter<2; iter++)
if ( (array= LP_tradecandidates(iter == 0 ? base : rel)) != 0 )
{
//printf("candidates.(%s)\nn.%d\n",jprint(array,0),cJSON_GetArraySize(array));
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
memset(&Q,0,sizeof(Q));
for (i=0; i<n; i++)
{
item = jitem(array,i);
LP_quoteparse(&Q,item);
if ( iter == 0 )
LP_query("price",&Q,jstr(item,"ipaddr"),jint(item,"port"),base,rel,zero);
else LP_query("price",&Q,jstr(item,"ipaddr"),jint(item,"port"),rel,base,zero);
}
}
free_json(array);
}
}
cJSON *LP_autotrade(struct LP_utxoinfo *myutxo,char *base,double maxprice)
{
static bits256 zero;

3
iguana/exchanges/LP_utxos.c

@ -282,10 +282,7 @@ int32_t LP_utxosparse(int32_t amclient,struct LP_peerinfo *mypeer,int32_t mypubs
utxo = LP_addutxo(amclient,mypeer,mypubsock,jstr(item,"coin"),txid,jint(item,"vout"),j64bits(item,"value"),jbits256(item,"txid2"),jint(item,"vout2"),j64bits(item,"value2"),jstr(item,"script"),jstr(item,"address"),argipaddr,argport,jdouble(item,"profit"));
if ( utxo != 0 )
{
struct LP_quoteinfo Q;
memset(&Q,0,sizeof(Q));
utxo->lasttime = now;
LP_query("price",&Q,utxo->ipaddr,utxo->port,utxo->coin,"KMD",utxo->mypub);
}
}
} // else printf("skip.(%s)\n",jprint(item,0));

Loading…
Cancel
Save