-
Notifications
You must be signed in to change notification settings - Fork 1
/
postorder.php
executable file
·90 lines (75 loc) · 2.08 KB
/
postorder.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
<?php
include_once('dbConnect.php');
include_once ('Order.php');
include_once('OrderBook.php');
include_once('post.php');
include_once('processor.php');
/*
* if message is not identified as an error, kill the
* process and return an error
*/
/*
* need to generate an XML respons
*/
/*$msgType = $_POST["MessageType"];
if(strcmp($msgType, "O")!=0 )
{
$response = Order::generateRejectResponse("M");
$r = new HttpRequest('http://localhost:40000/broker/endpoint', HttpRequest::METH_POST);
$r->addPostFields(array('xml' => $response));
$r->setContentType("Content-Type: text/xml");
try {
echo "<br/>";
echo $r->send()->getBody();
} catch (HttpException $ex) {
echo $ex;
}
die($response);
}*/
/*
* Load data from http post request
*/
$from = $_POST["From"];
$bs = $_POST["BS"];
$shares = $_POST["Shares"];
$stock = $_POST["Stock"];
$price= $_POST["Price"];
$twilio= $_POST["Twilio"];
$state = 'U';
$brokerAddress =$_POST["BrokerAddress"];
$brokerPort = $_POST["BrokerPort"];
$brokerEndPoint =$_POST["BrokerEndpoint"];
if($twilio=='N'){
$twilio=0;
}
else{
$twilio=1;
}
/*
* Create a new order
*/
$order =new Order($from, $bs, $shares, $stock, $price, $twilio, $state);
$order->isValid();
$result = $order->insertPending();
processTransactions();
$result=1;
//$fh = fopen("wow.txt", "a");
//fwrite($fh, $brokerAddress." ".$brokerEndPoint." ".$brokerPort);
//fclose($fh);
if($result == 1)
{ $aresponse = '<?xml version=”1.0” encoding=”UTF-8”?>\n <Response>\n
<Exchange><Accept OrderRefId = "POL345" /></Exchange>\n </Response>\n';
////$order->generateAcceptResponse();
echo $aresponse;
echo "<br/>";
echo "RESPONSE generated: ".$aresponse."<br/>";
$brokerAddress="127.0.0.1";
$brokerEndPoint="/broker";
$brokerEndPoint="40000127.0.0.1";
postToBroker($brokerAddress, $brokerPort, $brokerEndPoint, $aresponse);
}
else
{
Order::generateRejectResponse('invalid dataset');
}
?>