<commit_before><?php

/*

Copyright 2014 <NAME>
<EMAIL>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*/

if (defined("TAVURTH_OANDAWRAP") == FALSE) {
	define("TAVURTH_OANDAWRAP", TRUE);
	
	//////////////////////////////////////////////////////////////////////////////////
	//
	//	OANDA FUNCTIONAL API WRAPPER
	//
	//	Written by <NAME> July 2014
	//	Questions, comments or bug reports?
	//
	//		<EMAIL>
	//
	//	I am in no way responsible for any of your losses incurred
	//	while trading forex. 
	//	I take my trades off the table if they become losers.
	//
	//
	//	Best,
	//
	//		Tavurth
	//
	//////////////////////////////////////////////////////////////////////////////////
	
	class OandaWrap {
	
		//////////////////////////////////////////////////////////////////////////////////
		//
		//	VARIABLE DECLARATION AND HELPER FUNCTIONS
		//
		//////////////////////////////////////////////////////////////////////////////////
		
		private static $account;
		private static $apiKey;
		private static $server;
		private static $baseUrl;
		
		private static function check_name($name, $printValue, $verbose=TRUE) {
		//Check if an argument was correctly passed.
			if (!isset($name) || $name === FALSE) {	//Failure
				if ($verbose)
					echo $printValue . "<br>";
				return FALSE;
			}
			else //Valid name
				return $name;
		}
		
		protected static function setup_account($baseUrl, $apiKey, $userName, $accountName, $serverType="The") {
		//Generic account setup program, prints out errors in the html if incomplete
			//Set the url
			self::$baseUrl = $baseUrl;
			//If we passed an accountName with a username (Precise login)
			if (self::check_name($userName, "Invalid $serverType account user name: $userName.")) {
				if (self::check_name($apiKey, "Must provide API key for $serverType server.")) {
					
					//Set the API key
					self::$apiKey = $apiKey;
				
					if (self::check_name($accountName, "Invalid $serverType account user name: $accountName.")) {
						//Find the account
						$account = self::account_named($accountName, $userName);
						//Check the account
						if (self::check_name($account, "Invalid $serverType account name: $accountName.<br>"));
							return FALSE;
						//Set our current account
						self::$account = $account;
					}
				}
			}
			//If we just passed in a username, then set the first account from the list (Sloppy login)
			else {
				$accounts = self::accounts($userName);
				//Check the account
				if (count($accounts) < 1) {
					echo "OandaWrap: Invalid $serverType account name: $userName.<br>";
					return FALSE;
				}
				//Set our current account
				self::$account = $accounts[0];
			}
			return TRUE;
		}
		
		public static function setup($server=FALSE, $apiKey=FALSE, $userName=FALSE, $accountName=FALSE) {
		//Setup our enviornment variables
			self::$apiKey = self::$account = self::$server = "";
			//User can send<commit_msg>Fixed invalid if statement in account setup<commit_after><?php

/*

Copyright 2014 <NAME>
<EMAIL>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*/

if (defined("TAVURTH_OANDAWRAP") == FALSE) {
	define("TAVURTH_OANDAWRAP", TRUE);
	
	//////////////////////////////////////////////////////////////////////////////////
	//
	//	OANDA FUNCTIONAL API WRAPPER
	//
	//	Written by <NAME> July 2014
	//	Questions, comments or bug reports?
	//
	//		<EMAIL>
	//
	//	I am in no way responsible for any of your losses incurred
	//	while trading forex. 
	//	I take my trades off the table if they become losers.
	//
	//
	//	Best,
	//
	//		Tavurth
	//
	//////////////////////////////////////////////////////////////////////////////////
	
	class OandaWrap {
	
		//////////////////////////////////////////////////////////////////////////////////
		//
		//	VARIABLE DECLARATION AND HELPER FUNCTIONS
		//
		//////////////////////////////////////////////////////////////////////////////////
		
		private static $account;
		private static $apiKey;
		private static $server;
		private static $baseUrl;
		
		private static function check_name($name, $printValue, $verbose=TRUE) {
		//Check if an argument was correctly passed.
			if (!isset($name) || $name === FALSE) {	//Failure
				if ($verbose)
					echo $printValue . "<br>";
				return FALSE;
			}
			else //Valid name
				return $name;
		}
		
		protected static function setup_account($baseUrl, $apiKey, $userName, $accountName, $serverType="The") {
		//Generic account setup program, prints out errors in the html if incomplete
			//Set the url
			self::$baseUrl = $baseUrl;
			//If we passed an accountName with a username (Precise login)
			if (self::check_name($userName, "Invalid $serverType account user name: $userName.")) {
				if (self::check_name($apiKey, "Must provide API key for $serverType server.")) {
					
					//Set the API key
					self::$apiKey = $apiKey;
				
					if (self::check_name($accountName, "Invalid $serverType account user name: $accountName.")) {
						//Find the account
						$account = self::account_named($accountName, $userName);
						//Check the account
						if (isset($account->accountId))
							//Set our current account
							self::$account = $account;
					}
				}
			}
			//If we just passed in a username, then set the first account from the list (Sloppy login)
			else {
				$accounts = self::accounts($userName);
				//Check the account
				if (count($accounts) < 1) {
					echo "OandaWrap: Invalid $serverType account name: $userName.";
					return FALSE;
				}
				//Set our current account
				self::$account = $accounts[0];
			}
			return TRUE;
		}
		
		public static function setup($server=FALSE, $apiKey=FALSE, $userName=FALSE, $accountName=FALSE) {
		//Setup our enviornment variables
			self::$apiKey = self::$account = self::$server = "";
			//User can send
{'fraction_non_alphanumeric': 0.2029828486204325, 'fraction_numerical': 0.004175988068605518, 'mean_word_length': 2.135109864422627, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1620696', 'n_tokens_mistral': 2218, 'n_tokens_neox': 1851, 'n_words': 658}