shakeitdown Posted September 29, 2007 Share Posted September 29, 2007 hi, i posted a script below which is nearly identical to the one i use. the problem i'm having is that once i load up a few thousand orders: $myvenue = new VENUE("example"); $myvenue->order("1001", "B", "1000", "21.05", "1215"); $myvenue->order("1002", "B", "1000", "21.09", "1218"); $myvenue->order("1003", "B", "1000", "21.20", "1223"); $myvenue->order("1004", "S", "1000", "21.52", "1249"); I get the problem that when I remove orders, sometimes more than one disappears!!! // completes successfully but might unpredictably remove orders 1001, 1003, or 1004!! $myvenue->removeorder("B", "1002"); I think this might only happen when I have several hundred order objects, but I'm not entirely sure! The glitch is hard to reproduce but I think it only happens when I try to remove and order. It's driving me nuts. Maybe I am not using the unset method correctly? I store my order objects in an array and I'm not sure whether removing the appropriate row from the array will destruct the object, so I went with the unset method. PLEASE PLEASE HELP! PLEASE! ??? ??? ??? class ORDER { private $orderid =0; private $shares = 0; private $price = 0; private $timestamp = 0; public function __construct($orderid, $shares, $price, $time) { $this->orderid = $orderid; $this->shares = $shares; $this->price = $price; $this->time = $time; } public function getOrderid() { return $this->orderid; } public function getShares() { return $this->shares; } public function getPrice() { return $this->price; } public function getTime() { return $this->time; } public function setShares($value) { $this->shares = $value; return $this->shares; } public function setPrice($value) { $this->price = $value; return $this->price; } public function setTime($value) { $this->time = $value; return $this->time; } public function update($shares, $price, $time) { $this->shares = $shares; $this->price = $price; $this->time = $time; } public function __destruct() { echo "\t\tDESTROYING ".$this->orderid."\r\n"; } } class VENUE { private $bidorders = array(); private $askorders = array(); private $isready = FALSE; private $name = null; private $bidprice = 0; private $bidsize = 0; private $askprice = 99999; private $asksize = 0; public function __construct($venuename) { $this->name = $venuename; } public function executeorder($side, $orderid, $shares) { if ($side == "B") { if (!$this->bidorders[$orderid]->setShares($this->bidorders[$orderid]->getShares()-$shares)) { $this->removeorder($side, $orderid); } } if ($side == "S") { if (!$this->askorders[$orderid]->setShares($this->askorders[$orderid]->getShares()-$shares)) { $this->removeorder($side, $orderid); } } } public function removeorder($side, $orderid) { echo "\t\tREMOVING ".$side." ".$orderid."\r\n"; if ($side == "B") { unset($this->bidorders[$orderid]); } if ($side == "S") { unset($this->askorders[$orderid]); } } public function order($orderid, $bidask, $shares, $price, $time) { if ($bidask == "B") { if (!$this->bidorders[$orderid]) { $this->bidorders[$orderid] = new ORDER($orderid, $shares, $price, $time); } else { $this->bidorders[$orderid]->update($shares, $price, $time); print_r($this->bidorders[$orderid]); } } if ($bidask == "S") { if (!$this->askorders[$orderid]) { $this->askorders[$orderid] = new ORDER($orderid, $shares, $price, $time); } else { $this->askorders[$orderid]->update($shares, $price, $time); print_r($this->askorders[$orderid]); } } } } Quote Link to comment Share on other sites More sharing options...
emehrkay Posted September 29, 2007 Share Posted September 29, 2007 Works fine for me. The only change that i made was to make the bidorders array public so that i could access it <?php class ORDER { private $orderid =0; private $shares = 0; private $price = 0; private $timestamp = 0; public function __construct($orderid, $shares, $price, $time) { $this->orderid = $orderid; $this->shares = $shares; $this->price = $price; $this->time = $time; } public function getOrderid() { return $this->orderid; } public function getShares() { return $this->shares; } public function getPrice() { return $this->price; } public function getTime() { return $this->time; } public function setShares($value) { $this->shares = $value; return $this->shares; } public function setPrice($value) { $this->price = $value; return $this->price; } public function setTime($value) { $this->time = $value; return $this->time; } public function update($shares, $price, $time) { $this->shares = $shares; $this->price = $price; $this->time = $time; } public function __destruct() { echo "\t\tDESTROYING ".$this->orderid."\r\n"; } } class VENUE { public $bidorders = array(); private $askorders = array(); private $isready = FALSE; private $name = null; private $bidprice = 0; private $bidsize = 0; private $askprice = 99999; private $asksize = 0; public function __construct($venuename) { $this->name = $venuename; } public function executeorder($side, $orderid, $shares) { if ($side == "B") { if (!$this->bidorders[$orderid]->setShares($this->bidorders[$orderid]->getShares()-$shares)) { $this->removeorder($side, $orderid); } } if ($side == "S") { if (!$this->askorders[$orderid]->setShares($this->askorders[$orderid]->getShares()-$shares)) { $this->removeorder($side, $orderid); } } } public function removeorder($side, $orderid) { echo "\t\tREMOVING ".$side." ".$orderid."\r\n"; if ($side == "B") { unset($this->bidorders[$orderid]); } if ($side == "S") { unset($this->askorders[$orderid]); } } public function order($orderid, $bidask, $shares, $price, $time) { if ($bidask == "B") { if (!$this->bidorders[$orderid]) { $this->bidorders[$orderid] = new ORDER($orderid, $shares, $price, $time); } else { $this->bidorders[$orderid]->update($shares, $price, $time); print_r($this->bidorders[$orderid]); } } if ($bidask == "S") { if (!$this->askorders[$orderid]) { $this->askorders[$orderid] = new ORDER($orderid, $shares, $price, $time); } else { $this->askorders[$orderid]->update($shares, $price, $time); print_r($this->askorders[$orderid]); } } } } $myvenue = new VENUE("example"); $myvenue->order("1001", "B", "1000", "21.05", "1215"); $myvenue->order("1002", "B", "1000", "21.09", "1218"); $myvenue->order("1003", "B", "1000", "21.20", "1223"); $myvenue->order("1004", "S", "1000", "21.52", "1249"); print_r($myvenue->bidorders); $myvenue->removeorder("B", "1002"); print_r($myvenue->bidorders); ?> Quote Link to comment Share on other sites More sharing options...
shakeitdown Posted September 29, 2007 Author Share Posted September 29, 2007 hi, yes, the way your code is it works. the problem is once there are thousands of "B" type orders mixed with thousands of "S" type orders. thanks for lookin at it! Quote Link to comment Share on other sites More sharing options...
emehrkay Posted September 29, 2007 Share Posted September 29, 2007 same result. there must be some errors in the way you're indexing the array. your remove method works fine <?php class ORDER { private $orderid =0; private $shares = 0; private $price = 0; private $timestamp = 0; public function __construct($orderid, $shares, $price, $time) { $this->orderid = $orderid; $this->shares = $shares; $this->price = $price; $this->time = $time; } public function getOrderid() { return $this->orderid; } public function getShares() { return $this->shares; } public function getPrice() { return $this->price; } public function getTime() { return $this->time; } public function setShares($value) { $this->shares = $value; return $this->shares; } public function setPrice($value) { $this->price = $value; return $this->price; } public function setTime($value) { $this->time = $value; return $this->time; } public function update($shares, $price, $time) { $this->shares = $shares; $this->price = $price; $this->time = $time; } public function __destruct() { //echo "\t\tDESTROYING ".$this->orderid."\r\n"; } } class VENUE { public $bidorders = array(); private $askorders = array(); private $isready = FALSE; private $name = null; private $bidprice = 0; private $bidsize = 0; private $askprice = 99999; private $asksize = 0; public function __construct($venuename) { $this->name = $venuename; } public function executeorder($side, $orderid, $shares) { if ($side == "B") { if (!$this->bidorders[$orderid]->setShares($this->bidorders[$orderid]->getShares()-$shares)) { $this->removeorder($side, $orderid); } } if ($side == "S") { if (!$this->askorders[$orderid]->setShares($this->askorders[$orderid]->getShares()-$shares)) { $this->removeorder($side, $orderid); } } } public function removeorder($side, $orderid) { echo "\t\tREMOVING ".$side." ".$orderid."\r\n"; if ($side == "B") { unset($this->bidorders[$orderid]); } if ($side == "S") { unset($this->askorders[$orderid]); } } public function order($orderid, $bidask, $shares, $price, $time) { if ($bidask == "B") { if (!$this->bidorders[$orderid]) { $this->bidorders[$orderid] = new ORDER($orderid, $shares, $price, $time); } else { $this->bidorders[$orderid]->update($shares, $price, $time); print_r($this->bidorders[$orderid]); } } if ($bidask == "S") { if (!$this->askorders[$orderid]) { $this->askorders[$orderid] = new ORDER($orderid, $shares, $price, $time); } else { $this->askorders[$orderid]->update($shares, $price, $time); print_r($this->askorders[$orderid]); } } } } $myvenue = new VENUE("example"); for($i = 0; $i < 2000; $i++){ $myvenue->order($i, "B", $i + 3, "21.05", 1215 + $i); } for($i = 0; $i < 1140; $i++){ $myvenue->order($i, "S", $i + 3, "21.05", 1215 + $i); } echo count($myvenue->bidorders), '<br />'; $myvenue->removeorder("B", "1002"); echo count($myvenue->bidorders); ?> Quote Link to comment Share on other sites More sharing options...
emehrkay Posted September 29, 2007 Share Posted September 29, 2007 the problem has to be with indexing somehow. Even when i do this i get the correct ans $myvenue = new VENUE("example"); for($i = 0; $i < 2000; $i++){ $myvenue->order($i, "B", $i + 3, "21.05", 1215 + $i); if($i > 0) $myvenue->order(($i-1), "B", $i + 3, "21.05", 1215 + $i); } for($i = 0; $i < 1140; $i++){ $myvenue->order($i, "S", $i + 3, "21.05", 1215 + $i); } echo count($myvenue->bidorders), '<br />'; $myvenue->removeorder("B", "1002"); echo '<br />'; echo count($myvenue->bidorders), '<br />'; $myvenue->removeorder("B", "1003"); echo '<br />'; echo count($myvenue->bidorders), '<br />'; $myvenue->removeorder("B", "1005"); echo '<br />'; echo count($myvenue->bidorders), '<br />'; $myvenue->removeorder("B", "1007"); echo '<br />'; echo count($myvenue->bidorders), '<br />'; Quote Link to comment Share on other sites More sharing options...
shakeitdown Posted September 29, 2007 Author Share Posted September 29, 2007 i was thinking maybe that there is a problem with the php.ini, indexing, and memory allocation? maybe php removes some objects when it gets overloaded. the code does seem to be good, right?1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.