Repository navigation
Expand file tree
/
Copy pathOrderBook.php
More file actions
executable file
·178 lines (153 loc) · 4.49 KB
/
Copy pathOrderBook.php
File metadata and controls
executable file
·178 lines (153 loc) · 4.49 KB
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
<?php
include_once 'dbConnect.php';
include_once 'Order.php';
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of orderBook
*
* @author Omega
*/
class OrderBook
{
private $pendingOrders;
private $activeOrders;
private $archiveOrders;
private $activeIndex;
private $activeId;
public function __construct()
{
$this->pendingOrders = null;
$this->activeOrders = null;
$this->archiveOrders = null;
}
/*load all pending orders */
public function loadPending()
{
$query = "Select * from order_book_pending";
$this->pendingOrders = mysql_query($query);
}
/*load all active orders*/
public function loadActive()
{
$query = "Select * from order_book_active";
$this->activeOrders = mysql_query($query);
}
public function getActiveOrdersToMatch(){
$orders=array();
$query = "Select * from order_book_active";
$result = mysql_query($query);
$i=0;
while ($row = mysql_fetch_array($result))
{
$order = new Order($row[1], $row[2],$row[3], $row[4], $row[5], $row[6],$row[9]);
$order->setId($row[0]);
$date=strtotime($row[7]);
$order->setTimestamp($date);
$order->setParent($row[8]);
$order->setHasChild($row[10]);
if($order->getId()==$this->activeId)
{
$this->activeIndex = $i;
}
$orders[$i]=$order;
// echo $orders[$i]->toString()."*****";
$i=$i+1;
}
return $orders;
}
/*load all archived orders */
public function loadArchive()
{
$query = "Select * from order_book_archive";
$this->archiveOrders = mysql_query($query);
}
/* move from pending table to actively processing table
* resetPending is a boolean that specifies whether or not
* to reload the pending orders table
*/
public function moveToActive($resetPending, $shift)
{
if ($resetPending || !isset($this->pendingOrders))
{
$this->loadPending();
}
$result = $this->pendingOrders;
//$labels = mysql_fetch_array($result);
$i = 0;
while ($row = mysql_fetch_array($result))
{
$order = new Order($row[1], $row[2],$row[3], $row[4], $row[5], $row[6],$row[9]);
$order->setId($row[0]*$shift);
$order->setTimestamp($row[7]);
$order->setParent($row[8]);
$order->setHasChild($row[10]);
if ($i ==0)
{
$this->activeId = $order->getId();
}
$order->insertActive();
if ($shift > 0)
{
$order->setId($order->getId()/10);
}
$order->removeFromPending();
$i++;
}
}
public function moveToArchive($resetActive)
{
if ($resetActive || !isset($this->activeOrders))
{
$this->loadActive();
}
$result = $this->activeOrders;
//$labels = mysql_fetch_array($result);
while ($row = mysql_fetch_array($result))
{
if($row[9]=='F')
{
$order = new Order($row[1], $row[2],$row[3], $row[4], $row[5], $row[6],$row[9]);
$order->setId($row[0]);
$order->setTimestamp($row[7]);
$order->setParent($row[8]);
$order->setHasChild($row[10]);
$order->insertArchive();
$order->removeFromActive();
}
}
}
public function loadAll()
{
}
public function snapshotJSON()
{
}
public function getPendingOrders()
{
return $this->pendingOrders;
}
public function getActiveOrders()
{
return $this->activeOrders;
}
public function getArchiveOrders()
{
return $this->archiveOrders;
}
public function setActiveIndex($activeIndex){
$this->activeIndex=$activeIndex;
}
public function getActiveIndex(){
return $this->activeIndex;
}
public function setActiveId($activeId){
$this->activeId=$activeId;
}
public function getActiveId(){
return $this->activeId;
}
}
?>