-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOrder.php
executable file
·212 lines (179 loc) · 5.44 KB
/
Order.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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
//include_once('dbConnect.php');
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of order
*
* @author Omega
*/
class Order {
private $id;
private $from;
private $bs;
private $shares;
private $stock;
private $price;
private $twilio;
private $timestamp;
private $parent;
private $state;
private $has_child;
/*
* Constructor for order object
*/
public function __construct($from, $bs, $shares, $stock, $price, $twilio, $state){
$this->from = $from;
$this->bs = $bs;
$this->shares = $shares;
$this->stock = $stock;
$this->price = $price;
$this->twilio = $twilio;
$this->state = $state;
$this->parent = 0;
}
/*
* destructor
*/
public function __destruct() {
;
}
/*
* getters and setters for all the variables and the id
*/
public function getFrom(){
return $this->from;
}
public function getShares(){
return $this->shares;
}
public function setShares($shares){
$this->shares=$shares;
}
public function getBS(){
return $this->bs;
}
public function setBS($bs){
$this->bs=$bs;
}
public function getPrice(){
return $this->price;
}
public function getStock(){
return $this->stock;
}
public function setId($id){
$this->id = $id;
}
public function getId(){
return $this->id;
}
public function setParent($parent){
$this->parent = $parent;
}
public function getParent(){
return $this->parent;
}
public function setTimestamp($timestamp){
$this->timestamp = $timestamp;
}
public function getTimestamp(){
return $this->timestamp;
}
public function setHasChild($has_child){
$this->has_child = $has_child;
}
public function getHasChild(){
return $this->has_child;
}
public function getTwilio(){
return $this->twilio;
}
public function getState(){
return $this->state;
}
/**
*loads an order into the pending table of the database
* @return type
*/
public function insertPending(){
$q="INSERT INTO order_book_pending (`from`, `bs`, `shares`, `stock`, `price`, `twilio`, `timestamp`,`state`)
VALUES ('$this->from', '$this->bs', '$this->shares', '$this->stock', '$this->price', '$this->twilio', NOW(), 'U');";
$query = mysql_query($q);
if($query){
$this->id = mysql_insert_id();
return 1;
}
else echo mysql_error();//return 0;
}
public function insertActive(){
$q="INSERT INTO order_book_active (`id`,`from`, `bs`, `shares`, `stock`, `price`, `twilio`, `timestamp`,`state`,`parent`, `has_child`)
VALUES ('$this->id', '$this->from', '$this->bs', '$this->shares', '$this->stock', '$this->price', '$this->twilio',
'$this->timestamp', '$this->state','$this->parent', '$this->has_child');";
//
// $fh = fopen("wtf.txt", "a");
// fwrite($fh, $q);
// fclose($fh);
$query = mysql_query($q);
if($query){
return 1;
}
else echo mysql_error();//return 0;
}
public function insertArchive()
{
$q="INSERT INTO order_book_archive (`id`,`from`, `bs`, `shares`, `stock`, `price`, `twilio`, `timestamp`,`state`,`parent`, `has_child`)
VALUES ('$this->id', '$this->from', '$this->bs', '$this->shares', '$this->stock', '$this->price', '$this->twilio',
'$this->timestamp', '$this->state', '$this->parent', '$this->has_child');";
$query = mysql_query($q);
if($query){
echo "went trough";
return 1;
}
else echo mysql_error();//return 0;
}
public function removeFromPending()
{
$q = "DELETE FROM order_book_pending WHERE id=$this->id";
$query = mysql_query($q);
}
public function removeFromActive()
{
$q = "DELETE FROM order_book_active WHERE id=$this->id";
$query = mysql_query($q);
}
public function toString(){
if($this->twilio==true) $twilioTemp="true";
else $twilioTemp="false";
return $this->from." ".$this->bs." ".$this->shares." ".$this->price." ".$twilioTemp." ".$this->state;
}
public function isValid()
{
return true;
}
public static function generateResponse($response)
{
$brokerResponse = '<?xml version="1.0" encoding="UTF-8"?>\n <Response>\n
<Exchange>';
$brokerResponse .= $response;
$brokerResponse .= '</Exchange>\n </Response>\n';
return $brokerResponse;
}
public static function generateRejectResponse($reason)
{
$response = '<Reject Reason="';
$response .= "$reason";
$response .= '"/>';
return Order::generateResponse($response);
}
public function generateAcceptResponse()
{
$response = '<Accept OrderRefId="';
$response .= $this->bs . ''. $this->id;
$response .= '"/>';
return Order::generateResponse($response);
}
}
?>