-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.h
175 lines (169 loc) · 5.83 KB
/
test.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#ifndef __ACCOUNT__
#define __ACCOUNT__
#include "enum.h"
#include <cstring>
#include <iostream>
class _Account
{
public:
const int _index;
const int owner;
char apikey[(int)enum_Account::KEYLEN];
char secretkey[(int)enum_Account::KEYLEN];
const int brain;
const int deal;
double total_money;
double available_money;
double in_use_money;
double available_coin[(int)enum_Account::COIN_COUNT];
double total_coin[(int)enum_Account::COIN_COUNT]; //coin == total_coin
double in_use_coin[(int)enum_Account::COIN_COUNT];
double tradesum;
char name[20];
char d_basedir[100];
mutable int stack;
int dbindex;
const int * coinvalue;
_Account(const int _index, const int owner, const char * const apikey, const char * const secretkey, const int brain, const int deal);
_Account(const int _index, const char * const apikey, const char * const secretkey);
~_Account();
void init_coinvalue(const int * const coinvalue);
void set_dbindex(const int dbindex);
void show_Account(void);
void set_d_basedir(const char * d_basedir);
void set_total_coin(double * coin);
void set_available_coin(double * coin);
void set_in_use_coin(double * coin);
void set_all_coin_error(void);
void get_total_coin(double * coin);
void get_available_coin(double * coin);
void fwrite_log(const char * log) const;
void fwrite_log(const char * type, const char * order_id, const char * log) const;
int get_stack(void) const;
void set_stack_inc(void) const;
void set_stack_zero(void) const;
};
_Account::_Account(const int _index, const int owner, const char * const apikey, const char * const secretkey, const int brain, const int deal)
: _index(_index), owner(owner), brain(brain), deal(deal), total_money(0.0), available_money(0.0), tradesum(0.0), stack(0), dbindex(-1), coinvalue(NULL)
{
set_d_basedir(".");
memcpy((void*)this->apikey, apikey, sizeof(char)*(int)enum_Account::KEYLEN);
memcpy((void*)this->secretkey, secretkey, sizeof(char)*(int)enum_Account::KEYLEN);
//fprintf(fp, "account created! index : %d owner : %d, brain : %d, deal : %d\n", _index, owner, brain, deal);
};
_Account::_Account(const int _index, const char * const apikey, const char * const secretkey): _index(_index), owner(-1), brain(0), deal(0), stack(0), dbindex(-1), coinvalue(NULL)
{
set_d_basedir(".");
memcpy((void*)this->apikey, apikey, sizeof(char)*(int)enum_Account::KEYLEN);
memcpy((void*)this->secretkey, secretkey, sizeof(char)*(int)enum_Account::KEYLEN);
};
_Account::~_Account()
{
};
void _Account::set_dbindex(const int dbindex)
{
this->dbindex=dbindex;
}
void _Account::init_coinvalue(const int * const coinvalue)
{
this->coinvalue = coinvalue;
}
void _Account::show_Account(void)
{
if(strcmp(apikey, "test") == 0)
fprintf(fp, "TEST : ");
else
fprintf(fp, "REAL : ");
fprintf(fp, "_index : %d, brain : %d, deal :%d, tradesum : %.0f\n", _index, brain, deal, tradesum);
if(coinvalue==NULL){
fprintf(fp, "%30s %20s %20s\n", "total", "available", "in use");
fprintf(fp, "%25.0f %20.0f %20.0f\n", total_money, available_money, in_use_money);
for(int i=0; i<(int)enum_Account::COIN_COUNT; i++){
get_name(name, i);
fprintf(fp, "%7s : %20.4f %20.4f %20.4f\n", name, total_coin[i], available_coin[i], in_use_coin[i]);
}
}
else{
fprintf(fp, "%30s %20s %20s %20s\n", "total", "available", "in use", "total_value");
fprintf(fp, "%25.0f %20.0f %20.0f\n", total_money, available_money, in_use_money);
get_name(name, 0);
fprintf(fp, "%7s : %20.4f %20.4f %20.4f\n", name, total_coin[0], available_coin[0], in_use_coin[0]);
for(int i=1; i<(int)enum_Account::COIN_COUNT; i++){
get_name(name, i);
fprintf(fp, "%7s : %20.4f %20.4f %20.4f %20.0f\n", name, total_coin[i], available_coin[i], in_use_coin[i], total_coin[i] * coinvalue[i-1]);
}
}
//fprintf(fp, "_index : %d, apikey : %s, secretkey : %s, brain : %d, deal :%d, money : %f, tradesum : %f\n", _index, apikey, secretkey, brain, deal, money, tradesum);
}
void _Account::set_d_basedir(const char * d_basedir)
{
strcpy(this->d_basedir, d_basedir);
}
void _Account::set_total_coin(double * coin)
{
memcpy((void*)this->total_coin, coin, sizeof(double)*(int)enum_Account::COIN_COUNT);
}
void _Account::set_available_coin(double * coin)
{
memcpy((void*)this->available_coin, coin, sizeof(double)*(int)enum_Account::COIN_COUNT);
}
void _Account::set_in_use_coin(double * coin)
{
memcpy((void*)this->in_use_coin, coin, sizeof(double)*(int)enum_Account::COIN_COUNT);
}
void _Account::set_all_coin_error(void)
{
for(int i=0; i<(int)enum_Account::COIN_COUNT; i++)
{
total_coin[i]=-1;
available_coin[i]=-1;
in_use_coin[i]=-1;
}
}
void _Account::get_total_coin(double * coin)
{
for(int i=0;i<(int)enum_Account::COIN_COUNT;i++)
coin[i]=this->total_coin[i];
}
void _Account::get_available_coin(double * coin)
{
for(int i=0;i<(int)enum_Account::COIN_COUNT;i++)
coin[i]=this->available_coin[i];
}
void _Account::fwrite_log(const char * log) const
{
FILE * account_fp;
char path[100];
sprintf(path, "%s/../account/%d/log", d_basedir, _index);
account_fp = fopen(path, "a");
if(dbindex!=-1){
fprintf(account_fp, "%d ", dbindex);
}
fputs(log, account_fp);
fclose(account_fp);
}
void _Account::fwrite_log(const char * type, const char * order_id, const char * log) const
{
FILE * account_fp;
char path[100];
sprintf(path, "%s/../account/%d/pending/%s/%s", d_basedir, _index, type, order_id);
account_fp = fopen(path, "a");
if(dbindex!=-1){
fprintf(account_fp, "%d ", dbindex);
}
fputs(log, account_fp);
fclose(account_fp);
}
int _Account::get_stack(void) const
{
return stack;
}
void _Account::set_stack_inc(void) const
{
stack++;
}
void _Account::set_stack_zero(void) const
{
stack=0;
}
#endif