public function Initialise()
 {
     $this->oContracts = new CMessageRTDContracts($this);
     // Pass a refernce of this to the trade object
     $this->oPrices = new CMessageRTDPrices($this);
     wLog(get_class($this), "--- Initialised ---");
 }
 public function Initialise()
 {
     // Loads last trade id
     $this->LoadLastTradeId();
     $this->oContracts = new CMessageRTDContracts($this);
     $this->oUsers = new CMessageRTDUsers();
     $this->oAccounts = new CMessageRTDAccounts();
     $this->oExchanges = new CMessageRTDExchanges();
     $this->oGroups = new CMessageRTDGroups();
     // Pass a refernce of this to the trade object
     $this->oTrades = new CMessageRTDTrades($this);
     wLog(get_class($this), "I --- Initialised ---");
 }
Ejemplo n.º 3
0
 /**
  * Logs in a user with the given username and password POSTed. Though true
  * REST doesn't believe in sessions, it is often desirable for an AJAX server.
  *
  * @url POST /login
  */
 public function login($data)
 {
     global $s, $a;
     if ($s->login($data->u, $data->p) > 0) {
         wLog('logLogin', $data->u . ' (HotMz) SUCCESS');
         $token = array();
         $token['id'] = $s->user->id;
         $token['email'] = $s->user->email;
         $wToken = JWT::encode($token, JWT_SECRET_SERVER_KEY);
         $company = $a->company->get($s->user->company_id);
         $u = array('name' => $s->user->name, 'position' => $s->user->position, 'email' => $s->user->email, 'phone' => $s->user->phone, 'userlevel' => $s->user->role2, 'company' => $company->name, 'pais' => $company->pais, 'address' => $company->address, 'cphone' => $company->phone, 'cif' => $company->cif, 'provincia' => $company->provincia, 'city' => $company->city, 'website' => $company->website, 'web_id' => $s->user->web_id, 'token' => $wToken);
         return array("success" => "Logged in " . $username, "user" => $u);
     } else {
         wLog('logLogin', $data->u . ' (HotMz) ERROR');
         return array("error" => "User name or password invalid" . $u . ' - ' . $p);
     }
 }
 public function InsertQuery($sTable, array $aData)
 {
     // remove null data
     foreach (array_keys($aData, NULL) as $key) {
         unset($aData[$key]);
     }
     $sQuery = "INSERT INTO {$sTable} ([";
     $sQuery .= implode("],[", array_keys($aData));
     $sQuery .= "]) VALUES ('";
     $sQuery .= implode("','", array_values($aData));
     $sQuery .= "')";
     $result = mssql_query($sQuery, $this->connection);
     if ($result === FALSE) {
         wLog(get_class($this), "E Couldn't execute query: {$sQuery}");
         wLog(get_class($this), "E Last message on server was: " . mssql_get_last_message());
         // email an alert to IT
         //$this->alertEmail("Query failed", $msg);
         die("E Couldn't execute query");
     }
 }
 public function closeApi()
 {
     wLog(get_class($this), "I Closing connection...");
     socket_close($this->socket);
 }
 private function InsertContractType1()
 {
     if (isset($this->oRequestRTD->aaSettings["ML"])) {
         // if manual trade then ignore it
         if ($this->aTrade["fid_trade_flags"] == 128 || $this->aTrade["fid_trade_flags"] == 129 || $this->aTrade["fid_trade_flags"] == 130) {
             wlog(get_class($this), "I Manual Trade Found : " . $trade["fid_trade_id"] . " (Ignoring)");
             break;
         }
         /* PROCESS FOR ML */
         // default - new trade
         $data["action"] = "N";
         // default
         $data["transactionType"] = "SC";
         // will display trade text stored in the RTD user profile
         $data["bookCode"] = $this->aTrade["fid_trade_text"];
         $data["bookCodeDescription"] = $this->oRequestRTD->oUsers->GetUserName($this->aTrade["fid_user_id"]);
         $data["tradeReference"] = $this->aTrade["fid_trade_id"];
         $data["securityCodePrefix"] = "SEDL";
         $data["securityCode"] = $this->oRequestRTD->oContracts->GetSEDOL($this->aTrade["fid_contract_id"]);
         $data["securityDescription"] = $this->oRequestRTD->oContracts->GetSymbol($this->aTrade["fid_contract_id"]);
         $data["currency"] = $this->oRequestRTD->oContracts->GetSymbol($this->aTrade["fid_currency_id"]);
         $data["brokerCode"] = $this->oRequestRTD->aaSettings["TRADE"]["BROKERCODE"];
         $data["operation"] = $this->aTrade["fid_contracts_long"] - $this->aTrade["fid_contracts_long"] > 0 ? "B" : "S";
         // Buy or sell?;
         $data["quantity"] = abs($this->aTrade["fid_contracts_long"] - $this->aTrade["fid_contracts_long"]);
         $data["price"] = (double) $this->aTrade["fid_price"];
         $data["netAmount"] = (double) abs((double) $this->aTrade["fid_value"]);
         $data["tradeDate"] = date("Ymd", strtotime($this->aTrade["fid_date"]));
         $data["tradeTime"] = date("H:i", strtotime($this->aTrade["fid_date"] . " " . $this->aTrade["fid_time"]));
         // get settlement date
         $data["settlementDate"] = date("Ymd", strtotime($this->SettlementCheckStock($this->aTrade["fid_date"], $this->oRequestRTD->oContracts->GetISIN($this->aTrade["fid_contract_id"]), $this->oRequestRTD->oExchanges->GetExchangeSymbol($this->aTrade["fid_exchange_id"]), $this->oRequestRTD->aaSettings["ML"]["SETTLEMENT_DEFAULT"])));
         $data["agentIndicator"] = $this->aTrade["fid_contracts_long"] - $this->aTrade["fid_contracts_long"] > 0 ? "P" : "S";
         $data["orderReference"] = $this->aTrade["fid_order_number"];
         $data["executionReference"] = $this->aTrade["fid_trade_number"];
         $data["marketClientIndicatorField"] = "M";
         $data["transactionReportMarker"] = "R";
         $data["transactionReportBIC"] = $this->oRequestRTD->oAccounts->GetAccountSpec2($this->aTrade["fid_member_id"]);
         $data["marketOfExecution"] = "LN";
         //print_r($data);
         //return;
         // select the ML database
         //$this->oRequestRTD->oDatabase->SelectDatabase($this->oRequestRTD->aaSettings["ML"]["ML_DB"]);
         // send to the database
         //$this->oRequestRTD->oDatabase->InsertQuery($this->oRequestRTD->aaSettings["ML"]["ML_TABLE"], $data);
         unset($data);
     }
     if (isset($this->oRequestRTD->aaSettings["TRADE"])) {
         /* PROCESS FOR P&L */
         $data["tradeDateTime"] = date("c", strtotime($this->aTrade["fid_date"] . " " . $this->aTrade["fid_time"]));
         $data["exchange"] = $this->oRequestRTD->oExchanges->GetExchangeSymbol($this->aTrade["fid_exchange_id"]);
         $data["isin"] = $this->oRequestRTD->oContracts->GetISIN($this->aTrade["fid_contract_id"]);
         $data["symbol"] = $this->oRequestRTD->oContracts->GetSymbol($this->aTrade["fid_contract_id"]);
         $data["currency"] = $this->oRequestRTD->oContracts->GetSymbol($this->aTrade["fid_currency_id"]);
         $data["quantity"] = $this->aTrade["fid_contracts_long"] - $this->aTrade["fid_contracts_long"];
         $data["price"] = (double) $this->aTrade["fid_price"];
         $data["account"] = $this->oRequestRTD->oAccounts->aaAccounts[$this->aTrade["fid_account_id"]]["fid_account_spec1"] . " " . $this->oRequestRTD->oAccounts->aaAccounts[$this->aTrade["fid_account_id"]]["fid_account_spec2"];
         $data["aggressor"] = $this->aTrade["fid_trade_flags"] == 4096 ? "Y" : "N";
         $data["exchangeOrderId"] = $this->aTrade["fid_order_number"];
         $data["exchangeTradeId"] = $this->aTrade["fid_trade_number"];
         $data["internalOrderId"] = $this->aTrade["fid_rtd_order_id"];
         $data["internalTradeId"] = $this->aTrade["fid_trade_id"];
         $data["internalSource"] = $this->oRequestRTD->aaSettings["TRADE"]["SOURCENAME"];
         // select the TRADE database
         //$this->oRequestRTD->oDatabase->SelectDatabase($this->oRequestRTD->aaSettings["ML"]["TRADE_DB"]);
         // send trade to the database
         //$this->oRequestRTD->oDatabase->InsertQuery($this->oRequestRTD->aaSettings["TRADE"]["TRADE_TABLE"], $data);
         unset($data);
     }
     if (isset($this->oRequestRTD->aaSettings["WEBPL"]["TRADE"])) {
         // give the trade a unique id, so it is only accepted if it is authorised on the other side.
         $aaUrl["id"] = md5(date("Ymd") . $this->aTrade["fid_trade_id"]);
         $aaUrl["t"] = date("c", strtotime($this->aTrade["fid_date"] . " " . $this->aTrade["fid_time"]));
         $aaUrl["e"] = $this->oRequestRTD->oExchanges->GetExchangeSymbol($this->aTrade["fid_exchange_id"]);
         $aaUrl["i"] = $this->oRequestRTD->oContracts->GetISIN($this->aTrade["fid_contract_id"]);
         $aaUrl["s"] = $this->oRequestRTD->oContracts->GetSymbol($this->aTrade["fid_contract_id"]);
         $aaUrl["c"] = $this->oRequestRTD->oContracts->GetSymbol($this->aTrade["fid_currency_id"]);
         $aaUrl["q"] = $this->aTrade["fid_contracts_long"] - $this->aTrade["fid_contracts_short"];
         $aaUrl["p"] = (double) $this->aTrade["fid_price"];
         $aaUrl["acc"] = $this->oRequestRTD->oAccounts->aaAccounts[$this->aTrade["fid_account_id"]]["fid_account_spec1"] . " " . $this->oRequestRTD->oAccounts->aaAccounts[$this->aTrade["fid_account_id"]]["fid_account_spec2"];
         $aaUrl["agg"] = $this->aTrade["fid_trade_flags"] == 4096 ? "Y" : "N";
         $aaUrl["eoi"] = $this->aTrade["fid_order_number"];
         $aaUrl["eti"] = $this->aTrade["fid_trade_number"];
         $aaUrl["ioi"] = $this->aTrade["fid_rtd_order_id"];
         $aaUrl["iti"] = $this->aTrade["fid_trade_id"];
         $aaUrl["is"] = $this->oRequestRTD->aaSettings["WEBPL"]["SOURCENAME"];
         foreach ($aaUrl as $key => $value) {
             $aUrl[] = $key . "=" . urlencode($value);
         }
         $url = implode("&", $aUrl);
         //print $this->oRequestRTD->aaSettings["WEBPL"]["TRADE"] . "?" . $url . "\n";
         $result = file_get_contents($this->oRequestRTD->aaSettings["WEBPL"]["TRADE"] . "?" . $url);
         if ($result === FALSE) {
             wLog(get_class($this), "E WEBPL Trade insert failed. Failed on {$this->oRequestRTD->aaSettings["WEBPL"]["SOURCENAME"]} trade id {$this->aTrade["fid_trade_id"]}");
         }
         unset($data, $aaUrl, $aUrl, $url);
     }
 }