From 0174ea595255415ad06156e6c7ee5c1faffa17b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 1 Nov 2017 18:53:15 +0200 Subject: [PATCH] Test --- iguana/exchanges/LP_tradebots.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_tradebots.c b/iguana/exchanges/LP_tradebots.c index f6ede98e5..96d6d206c 100644 --- a/iguana/exchanges/LP_tradebots.c +++ b/iguana/exchanges/LP_tradebots.c @@ -399,11 +399,37 @@ char *LP_tradebot_list(void *ctx,int32_t pubsock,cJSON *argjson) char *LP_tradebot_buy(int32_t dispdir,char *base,char *rel,double maxprice,double relvolume) { - struct LP_tradebot *bot; struct iguana_info *basecoin,*relcoin; + struct LP_tradebot *bot; int32_t i,n; cJSON *array,*item,*retjson; uint64_t txfees,balance=0; struct iguana_info *basecoin,*relcoin; basecoin = LP_coinfind(base); relcoin = LP_coinfind(rel); if ( basecoin == 0 || relcoin == 0 || basecoin->inactive != 0 || relcoin->inactive != 0 ) return(clonestr("{\"error\":\"one or more coins inactive\"}")); + if ( (array= LP_inventory(rel)) != 0 ) + { + if ( (n= cJSON_GetArraySize(array)) > 0 && is_cJSON_Array(array) != 0 ) + { + for (i=0; itxfee; + if ( dstr(balance) < relvolume + dstr(txfees) ) + { + printf("%s inventory balance only %.8f, less than relvolume %.8f + txfees %.8f\n",rel,dstr(balance),relvolume,dstr(txfees)); + retjson = cJSON_CreateObject(); + jaddstr(retjson,"error","not enough funds"); + jaddstr(retjson,"coin",rel); + jaddnum(retjson,"balance",dstr(balance)); + jaddnum(retjson,"relvolume",relvolume); + jaddnum(retjson,"txfees",dstr(txfees)); + jaddnum(retjson,"shortfall",(relvolume + dstr(txfees)) - dstr(balance)); + return(jprint(retjson,1)); + } printf("disp.%d tradebot_buy(%s / %s) maxprice %.8f relvolume %.8f\n",dispdir,base,rel,maxprice,relvolume); if ( (bot= calloc(1,sizeof(*bot))) != 0 ) {