-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapi.php
144 lines (117 loc) · 4.51 KB
/
api.php
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
<?php
ini_set('display_errors', 0);
error_reporting(0);
// localhost only
if($_SERVER['HTTP_HOST'] != "localhost"){echo "api v. 1.0"; die();}
//========================================================================
// functions
//========================================================================
// db connect
function Connect(){
$h = 'localhost';
$u = 'root';
$j = 'toor';
$db = 'db';
mysql_connect($h,$u,$j) or die('[DB_ERROR]');
mysql_select_db($db) or die('[DB_ERROR]');
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
}
// db close connection
function Close(){
mysql_close();
}
function userExist($user = "", $pass = "")
{
if($user != "" && $pass != ""){
$pass = md5($pass);
$user = htmlentities($user, ENT_QUOTES, "UTF-8");
$user = mysql_real_escape_string($user);
$pass = mysql_real_escape_string($pass);
$result = mysql_query("SELECT * FROM users where alias = '$user' AND pass = '$pass'");
$num_rows = mysql_num_rows($result);
return $num_rows;
}else{
return 0;
}
}
//========================================================================
// main
//========================================================================
Connect();
$open = htmlentities($_POST["positions"], ENT_QUOTES, 'UTF-8');
$close = htmlentities($_POST["historyall"], ENT_QUOTES, 'UTF-8');
$user = htmlentities($_POST["user"], ENT_QUOTES, 'UTF-8');
$pass = htmlentities($_POST["pass"], ENT_QUOTES, 'UTF-8');
$account = htmlentities($_POST["account"], ENT_QUOTES, 'UTF-8');
$balance = htmlentities($_POST["balance"], ENT_QUOTES, 'UTF-8');
$equity = htmlentities($_POST["equity"], ENT_QUOTES, 'UTF-8');
$time = time();
if(!userExist($user, $pass)){ /* echo "[ER_USER]"; */ }
// open and update positions in database
if(!empty($open)){
// split positions line
$openall = explode("|", substr($open, 0,-1));
foreach ($openall as $key => $posstr) {
//split position
$pos = explode(";", $posstr);
$id = $pos[1];
$symbol = $pos[3];
$volume = $pos[4];
$type = $pos[5];
if($type == '1'){$type = "sell";}
if($type == '0'){$type = "buy";}
$opent = $pos[0];
$openp = $pos[2];
$sl = $pos[6];
$tp = $pos[7];
$time = time(0);
$profit = $pos[8];
$account = $pos[9];
// save or update in database
// mysql_query("INSERT INTO orders VALUES('$id','$symbol','$volume','$type','$opent','$openp','$sl','$tp','$closet', '$closep', '$profit','$time','$account')");
$openadd = mysql_query("INSERT INTO orders VALUES('$id','$symbol','$volume','$type','$opent','$openp','$sl','$tp','0', '0', '$profit','$time','$account') ON DUPLICATE KEY UPDATE volume = '$volume', sl = '$sl', tp = '$tp', profit = '$profit'");
}
}
// update closed positions in database
if(!empty($close)){
// split history positions line
$closeall = explode("|", substr($close, 0,-1));
foreach ($closeall as $key => $poshstr) {
// split history position
$posh = explode(";", $poshstr);
//print_r($posh);
$id = $posh[1];
$symbol = $posh[3];
$volume = $posh[4];
$type = $posh[5];
if($type == '1'){$type = "sell";}
if($type == '0'){$type = "buy";}
$opent = $posh[0];
$openp = $posh[2];
$sl = $posh[6];
$tp = $posh[7];
$closet = $posh[8];
$closep = $posh[9];
$profit = $posh[10];
$time = time(0);
$account = $posh[11];
// save or update in database
// mysql_query("INSERT INTO orders VALUES('$id','$symbol','$volume','$type','$opent','$openp','$sl','$tp','$closet', '$closep', '$profit','$time','$account')");
$closeadd = mysql_query("INSERT INTO orders VALUES('$id','$symbol','$volume','$type','$opent','$openp','$sl','$tp','$closet', '$closep', '$profit' , '$time' , '$account') ON DUPLICATE KEY UPDATE volume = '$volume', sl = '$sl', tp = '$tp', closet = '$closet', closep = '$closep', profit = '$profit'");
}
}
// add balance to database
$result = mysql_query("SELECT `alias`,`linkmql` FROM users WHERE account = '$account'");
$row = mysql_fetch_row($result);
$alias = $row[0];
$linkmql = $row[1];
if(!empty($alias)){
$ok = mysql_query("INSERT INTO balance VALUES('$account','$balance','$equity','$alias','$linkmql','$time') ON DUPLICATE KEY UPDATE balance = '$balance', equity = '$equity', alias = '$alias', linkmql = '$linkmql', time = '$time'");
}
// db close connection
Close();
// end php code
//echo $close;
echo "[OK]";
die();
?>