Browse Source

Test

etomic
jl777 7 years ago
parent
commit
684cc6c64d
  1. 65
      iguana/exchanges/LP_RTmetrics.c
  2. 1
      iguana/exchanges/LP_nativeDEX.c
  3. 51
      iguana/exchanges/LP_network.c
  4. 8
      iguana/exchanges/LP_ordermatch.c
  5. 6
      iguana/exchanges/Makefile
  6. 16
      iguana/exchanges/nodeinstall

65
iguana/exchanges/LP_RTmetrics.c

@ -0,0 +1,65 @@
/******************************************************************************
* Copyright © 2014-2017 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
//
// LP_RTmetrics.c
// marketmaker
//
cJSON *LP_RTmetrics_sort(cJSON *rawasks,int32_t numasks,double maxprice,double relvolume)
{
cJSON *array,*item,*statsjson,*swaps=0; int32_t i,numswaps=0; bits256 zero; uint32_t futuretime; double price; char *retstr;
futuretime = (uint32_t)time(NULL) + 3600*100;
memset(zero.bytes,0,sizeof(zero));
if ( (retstr= LP_statslog_disp(100,futuretime,futuretime,"",zero)) != 0 )
{
if ( (statsjson= cJSON_Parse(retstr)) != 0 )
{
if ( (swaps= jarray(&numswaps,statsjson,"swaps")) != 0 )
{
if ( numswaps > 0 )
swaps = jduplicate(swaps);
else swaps = 0;
}
free_json(statsjson);
}
free(retstr);
}
//if ( numswaps == 0 || swaps == 0 )
return(0);
printf("calc RTmetrics for (%s)\n",jprint(swaps,0));
/*jadd64bits(item,"aliceid",sp->aliceid);
jaddbits256(item,"src",sp->Q.srchash);
jaddstr(item,"base",sp->Q.srccoin);
jaddnum(item,"basevol",dstr(sp->Q.satoshis));
jaddbits256(item,"dest",sp->Q.desthash);
jaddstr(item,"rel",sp->Q.destcoin);
jaddnum(item,"relvol",dstr(sp->Q.destsatoshis));
jaddnum(item,"price",sp->qprice);
jaddnum(item,"requestid",sp->Q.R.requestid);
jaddnum(item,"quoteid",sp->Q.R.quoteid);
*/
array = cJSON_CreateArray();
for (i=0; i<numasks; i++)
{
item = jitem(rawasks,i);
price = jdouble(item,"price");
if ( price > maxprice )
break;
jaddi(array,jduplicate(item));
}
free_json(swaps);
return(array);
}

1
iguana/exchanges/LP_nativeDEX.c

@ -107,6 +107,7 @@ char *blocktrail_listtransactions(char *symbol,char *coinaddr,int32_t num,int32_
#include "LP_utxos.c"
#include "LP_forwarding.c"
#include "LP_signatures.c"
#include "LP_RTmetrics.c"
#include "LP_ordermatch.c"
#include "LP_portfolio.c"
#include "LP_messages.c"

51
iguana/exchanges/LP_network.c

@ -28,6 +28,57 @@ struct psock
uint16_t Numpsocks,Psockport = MIN_PSOCK_PORT;
#ifdef FROM_JS
int32_t nn_socket(int domain, int protocol)
{
return(0);
}
int32_t nn_close(int s)
{
return(0);
}
int32_t nn_setsockopt(int s, int level, int option, const void *optval,size_t optvallen)
{
return(0);
}
int32_t nn_getsockopt(int s, int level, int option, void *optval,size_t *optvallen)
{
return(0);
}
int32_t nn_bind(int s, const char *addr)
{
return(0);
}
int32_t nn_connect(int s, const char *addr)
{
return(0);
}
int32_t nn_shutdown(int s, int how)
{
return(0);
}
int32_t nn_send(int s, const void *buf, size_t len, int flags)
{
return(0);
}
int32_t nn_recv(int s, void *buf, size_t len, int flags)
{
return(0);
}
#endif
char *nanomsg_transportname(int32_t bindflag,char *str,char *ipaddr,uint16_t port)
{
sprintf(str,"ws://%s:%u",bindflag == 0 ? ipaddr : "*",port);

8
iguana/exchanges/LP_ordermatch.c

@ -766,7 +766,7 @@ struct LP_utxoinfo *LP_ordermatch_iter(struct LP_address_utxo **utxos,int32_t ma
struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,char *gui,bits256 *avoids,int32_t numavoids,bits256 destpubkey)
{
bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*asks,*item; int32_t maxiters,i,j,numasks,max; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; uint64_t asatoshis; struct iguana_info *basecoin; struct LP_utxoinfo *bestutxo = 0;
bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*asks,*rawasks,*item; int32_t maxiters,i,j,numasks,max; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; uint64_t asatoshis; struct iguana_info *basecoin; struct LP_utxoinfo *bestutxo = 0;
maxiters = 100;
*ordermatchpricep = 0.;
*bestsatoshisp = *bestdestsatoshisp = 0;
@ -785,8 +785,10 @@ struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,i
{
if ( (orderbook= cJSON_Parse(obookstr)) != 0 )
{
if ( (asks= jarray(&numasks,orderbook,"asks")) != 0 )
if ( (rawasks= jarray(&numasks,orderbook,"asks")) != 0 )
{
if ( (asks= LP_RTmetrics_sort(rawasks,numasks,maxprice,dstr(autxo->S.satoshis))) == 0 )
asks = rawasks;
for (i=0; i<numasks; i++)
{
item = jitem(asks,i);
@ -832,6 +834,8 @@ struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,i
break;
}
}
if ( asks != 0 && asks != rawasks )
free_json(asks);
}
free_json(orderbook);
}

6
iguana/exchanges/Makefile

@ -1,10 +1,10 @@
#cd ..
#emcc -s ASSERTIONS=1 -s ASYNCIFY=1 -s TOTAL_MEMORY=134217728 --preload-file coins.json -DFROM_JS -O2 -I../includes -I../crypto777 -s PTHREAD_POOL_SIZE=8 -s USE_PTHREADS=1 -o /var/www/html/index.html exchanges/mm.c ../crypto777/*.c ../crypto777/jpeg/*.c ../crypto777/jpeg/unix/*.c mini-gmp.c secp256k1/src/secp256k1.c -lm ../OSlibs/js/libnanomsg.a -lc -lpthread
#emcc -s ASSERTIONS=1 -s ASYNCIFY=1 -s TOTAL_MEMORY=134217728 --preload-file coins.json -D__PNACL -DFROM_JS -O2 -I../includes -I../crypto777 -s PTHREAD_POOL_SIZE=8 -s USE_PTHREADS=1 -o /var/www/html/index.html exchanges/mm.c $(CRYPTO777_SRCS) mini-gmp.c secp256k1/src/secp256k1.c -lm -lc
include ../crypto777/crypto777.sources
#include ../crypto777/crypto777.sources
#emcc -s ASSERTIONS=1 -s ASYNCIFY=1 -s TOTAL_MEMORY=134217728 --preload-file coins.json -D__PNACL -DFROM_JS -O2 -I../includes -I../crypto777 -o /var/www/html/index.html exchanges/mm.c $(CRYPTO777_SRCS) mini-gmp.c secp256k1/src/secp256k1.c -lm -lc
all:
emcc -s ASSERTIONS=1 -s ASYNCIFY=1 -s TOTAL_MEMORY=134217728 --preload-file coins.json -D__PNACL -DFROM_JS -O2 -I../includes -I../crypto777 -o /var/www/html/index.html exchanges/mm.c $(CRYPTO777_SRCS) mini-gmp.c secp256k1/src/secp256k1.c -lm -lc
emcc -s ASSERTIONS=1 -s ASYNCIFY=1 -s TOTAL_MEMORY=134217728 --preload-file coins.json -DFROM_JS -O2 -I../includes -I../crypto777 -s PTHREAD_POOL_SIZE=8 -s USE_PTHREADS=1 -o /var/www/html/index.html exchanges/mm.c ../crypto777/*.c ../crypto777/jpeg/*.c ../crypto777/jpeg/unix/*.c mini-gmp.c secp256k1/src/secp256k1.c -lm

16
iguana/exchanges/nodeinstall

@ -0,0 +1,16 @@
cd /var/www/html/
node install http-server -g
#start http-server to start current directory serving via http://127.0.0.1:8080
http-server .
node install node-nanomsg
# test.js
#var nano = require('nanomsg');
#var sub = nano.socket('sub');
#var addr = 'ws://5.9.253.197:7785'
#sub.connect(addr);
#sub.on('data', function (buf) {
#console.log(String(buf));
#});
Loading…
Cancel
Save