You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.6 KiB
82 lines
2.6 KiB
7 years ago
|
|
||
|
/******************************************************************************
|
||
|
* 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_stats.c
|
||
|
// marketmaker
|
||
|
//
|
||
|
|
||
|
#define LP_STATSLOG_FNAME "stats.log"
|
||
|
|
||
|
void LP_tradecommand_log(cJSON *argjson)
|
||
|
{
|
||
|
static FILE *logfp; char *jsonstr;
|
||
|
if ( logfp == 0 )
|
||
|
{
|
||
|
if ( (logfp= fopen(LP_STATSLOG_FNAME,"rb+")) != 0 )
|
||
|
fseek(logfp,0,SEEK_END);
|
||
|
else logfp = fopen(LP_STATSLOG_FNAME,"wb");
|
||
|
}
|
||
|
if ( logfp != 0 )
|
||
|
{
|
||
|
jsonstr = jprint(argjson,0);
|
||
|
fprintf(logfp,"%s\n",jsonstr);
|
||
|
free(jsonstr);
|
||
|
fflush(logfp);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
char *LP_statslog_disp(int32_t n)
|
||
|
{
|
||
|
cJSON *retjson;
|
||
|
retjson = cJSON_CreateObject();
|
||
|
jaddstr(retjson,"result","success");
|
||
|
jaddnum(retjson,"newlines",n);
|
||
|
return(jprint(retjson,1));
|
||
|
}
|
||
|
|
||
|
char *LP_statslog_parse()
|
||
|
{
|
||
|
static long lastpos; FILE *fp; char line[8192]; cJSON *lineobj; int32_t n = 0;
|
||
|
if ( (fp= fopen(LP_STATSLOG_FNAME,"rb")) != 0 )
|
||
|
{
|
||
|
if ( lastpos > 0 )
|
||
|
{
|
||
|
fseek(fp,0,SEEK_END);
|
||
|
if ( ftell(fp) > lastpos )
|
||
|
fseek(fp,lastpos,SEEK_SET);
|
||
|
else
|
||
|
{
|
||
|
fclose(fp);
|
||
|
return(clonestr("{\"result\":\"success\"}"));
|
||
|
}
|
||
|
}
|
||
|
while ( fgets(line,sizeof(line),fp) > 0 )
|
||
|
{
|
||
|
lastpos = ftell(fp);
|
||
|
if ( (lineobj= cJSON_Parse(line)) != 0 )
|
||
|
{
|
||
|
n++;
|
||
|
printf("%s\n",jprint(lineobj,0));
|
||
|
free_json(lineobj);
|
||
|
}
|
||
|
}
|
||
|
fclose(fp);
|
||
|
}
|
||
|
return(LP_statslog_disp(n));
|
||
|
}
|
||
|
|
||
|
|