Browse Source

Price feed

jl777
jl777 7 years ago
parent
commit
00530e8afa
  1. 21
      iguana/exchanges/LP_network.c
  2. 7
      iguana/exchanges/LP_signatures.c
  3. 4
      iguana/exchanges/stats.c

21
iguana/exchanges/LP_network.c

@ -443,7 +443,22 @@ void LP_commandQ_loop(void *ctx)
portable_mutex_lock(&LP_commandQmutex); portable_mutex_lock(&LP_commandQmutex);
DL_DELETE(LP_commandQ,ptr); DL_DELETE(LP_commandQ,ptr);
portable_mutex_unlock(&LP_commandQmutex); portable_mutex_unlock(&LP_commandQmutex);
if ( (argjson= cJSON_Parse(ptr->msg)) != 0 ) if ( ptr->stats_JSONonly < 0 )
{
if ( ptr->responsesock >= 0 )
{
if ( (result= cJSON_Parse(ptr->msg)) != 0 )
{
retjson = cJSON_CreateObject();
jaddnum(retjson,"queueid",0);
jadd(retjson,"result",result);
retstr = jprint(retjson,1);
if ( (size= nn_send(ptr->responsesock,retstr,(int32_t)strlen(retstr)+1,0)) <= 0 )
printf("error sending event\n");
}
}
}
else if ( (argjson= cJSON_Parse(ptr->msg)) != 0 )
{ {
if ( (retstr= LP_command_process(ctx,"127.0.0.1",ptr->responsesock,argjson,(uint8_t *)ptr->msg,ptr->msglen,ptr->stats_JSONonly)) != 0 ) if ( (retstr= LP_command_process(ctx,"127.0.0.1",ptr->responsesock,argjson,(uint8_t *)ptr->msg,ptr->msglen,ptr->stats_JSONonly)) != 0 )
{ {
@ -489,9 +504,7 @@ void LP_queuecommand(char **retstrp,char *buf,int32_t responsesock,int32_t stats
if ( (ptr->retstrp= retstrp) != 0 ) if ( (ptr->retstrp= retstrp) != 0 )
*retstrp = 0; *retstrp = 0;
ptr->msglen = msglen; ptr->msglen = msglen;
if ( (ptr->queueid= queueid) != 0 && responsesock < 0 ) ptr->responsesock = responsesock;
ptr->responsesock = IPC_ENDPOINT;
else ptr->responsesock = responsesock;
ptr->stats_JSONonly = stats_JSONonly; ptr->stats_JSONonly = stats_JSONonly;
memcpy(ptr->msg,buf,msglen); memcpy(ptr->msg,buf,msglen);
DL_APPEND(LP_commandQ,ptr); DL_APPEND(LP_commandQ,ptr);

7
iguana/exchanges/LP_signatures.c

@ -458,7 +458,7 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re
char *LP_postprice_recv(cJSON *argjson) char *LP_postprice_recv(cJSON *argjson)
{ {
bits256 pubkey; double price; char *base,*rel; bits256 pubkey; double price; char *base,*rel,*argstr;
//printf("PRICE POSTED.(%s)\n",jprint(argjson,0)); //printf("PRICE POSTED.(%s)\n",jprint(argjson,0));
if ( (base= jstr(argjson,"base")) != 0 && (rel= jstr(argjson,"rel")) != 0 && (price= jdouble(argjson,"price")) > SMALLVAL ) if ( (base= jstr(argjson,"base")) != 0 && (rel= jstr(argjson,"rel")) != 0 && (price= jdouble(argjson,"price")) > SMALLVAL )
{ {
@ -467,6 +467,11 @@ char *LP_postprice_recv(cJSON *argjson)
{ {
if ( LP_price_sigcheck(juint(argjson,"timestamp"),jstr(argjson,"sig"),jstr(argjson,"pubsecp"),pubkey,base,rel,j64bits(argjson,"price64")) == 0 ) if ( LP_price_sigcheck(juint(argjson,"timestamp"),jstr(argjson,"sig"),jstr(argjson,"pubsecp"),pubkey,base,rel,j64bits(argjson,"price64")) == 0 )
{ {
if ( (argstr= jprint(argjson,0)) != 0 )
{
LP_queuecommand(0,argstr,IPC_ENDPOINT,-1,0);
free(argstr);
}
//printf("call pricefeed update\n"); //printf("call pricefeed update\n");
LP_pricefeedupdate(pubkey,base,rel,price,jstr(argjson,"utxocoin"),jint(argjson,"n"),jdouble(argjson,"bal")*SATOSHIDEN,jdouble(argjson,"min")*SATOSHIDEN,jdouble(argjson,"max")*SATOSHIDEN,jdouble(argjson,"credits")*SATOSHIDEN); LP_pricefeedupdate(pubkey,base,rel,price,jstr(argjson,"utxocoin"),jint(argjson,"n"),jdouble(argjson,"bal")*SATOSHIDEN,jdouble(argjson,"min")*SATOSHIDEN,jdouble(argjson,"max")*SATOSHIDEN,jdouble(argjson,"credits")*SATOSHIDEN);
return(clonestr("{\"result\":\"success\"}")); return(clonestr("{\"result\":\"success\"}"));

4
iguana/exchanges/stats.c

@ -573,7 +573,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
if ( IPC_ENDPOINT >= 0 && (queueid= juint(arg,"queueid")) > 0 ) if ( IPC_ENDPOINT >= 0 && (queueid= juint(arg,"queueid")) > 0 )
{ {
buf = jprint(arg,0); buf = jprint(arg,0);
LP_queuecommand(&retstr,buf,-1,1,queueid); LP_queuecommand(&retstr,buf,IPC_ENDPOINT,1,queueid);
free(buf); free(buf);
retstr = clonestr("{\"result\":\"success\",\"status\":\"queued\"}"); retstr = clonestr("{\"result\":\"success\",\"status\":\"queued\"}");
} else retstr = stats_JSON(ctx,"127.0.0.1",-1,arg,remoteaddr,port); } else retstr = stats_JSON(ctx,"127.0.0.1",-1,arg,remoteaddr,port);
@ -584,7 +584,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
if ( jobj(arg,"id") == 0 ) if ( jobj(arg,"id") == 0 )
jaddnum(arg,"id",rand()); jaddnum(arg,"id",rand());
buf = jprint(arg,0); buf = jprint(arg,0);
LP_queuecommand(&retstr,buf,-1,1,queueid); LP_queuecommand(&retstr,buf,IPC_ENDPOINT,1,queueid);
free(buf); free(buf);
} else retstr = stats_JSON(ctx,myipaddr,-1,arg,remoteaddr,port); } else retstr = stats_JSON(ctx,myipaddr,-1,arg,remoteaddr,port);
#endif #endif

Loading…
Cancel
Save