//Function to take current market values and add them to asset instance public static void store(asset a, IWebDriver b, double inc, int inc2) { try { double tempmarket = Convert.ToDouble(b.FindElement(By.XPath("//*[@id='graphs_area']/form[" + a.position + "]/div[2]/div[1]/div[1]/p")).Text); a.Xpoints.Add(inc); a.Ypoints.Add(tempmarket); if (a.Xpoints.Count > 301) { a.Xpoints.RemoveAt(0); a.Ypoints.RemoveAt(0); } Console.WriteLine(a.name + " ( " + inc + ", " + a.Ypoints[inc2] + " )"); Debug.WriteLine(inc + " " + a.Xpoints[inc2]); ++inc; ++inc2; } catch { }; }
public static void bet(asset a, bool dir, int amount, IWebDriver b) { //type in current_bet into input box IWebElement curass = b.FindElement(By.XPath("//*[@id='graphs_area']/form[" + a.position + "]/div[2]/div[1]/div[2]/div/p[3]/input")); curass.Clear(); curass.SendKeys(amount.ToString()); //click wich direction we want to bet if (dir == true) { b.FindElement(By.XPath("//*[@id='graphs_area']/form[" + a.position + "]/div[2]/div[1]/div[1]/a[1]")).Click(); } else if (dir == false) { b.FindElement(By.XPath("//*[@id='graphs_area']/form[" + a.position + "]/div[2]/div[1]/div[1]/a[2]")).Click(); } //click the buy button b.FindElement(By.XPath("//*[@id='graphs_area']/form[" + a.position + "]/div[2]/div[1]/div[2]/input")).Click(); }
static void Main(string[] args) { //all essential values needed to run the program asset first = new asset(); asset chosen_one = new asset(); string username = "******"; string password = "******"; string previous; int openedForex = 0; double inc = 1; int inc2 = 0; int time = 0; int current_bet = 1; bool ready = false; bool running = false; bool higher = false; bool firstbet = true; IWebElement readyelem; IWebElement win; IWebElement closed; List <zone> Zones = new List <zone>(); // Open browser and navigate to Marketsworld IWebDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl("http://www.marketsworld.com"); System.Threading.Thread.Sleep(10000); driver.FindElement(By.Name("user[email]")).SendKeys(username); driver.FindElement(By.Name("user[password]")).SendKeys(password); driver.FindElement(By.Name("submit")).Click(); IWebElement query = driver.FindElement(By.XPath("//*[@id='navi']/li[2]/a")); query.Click(); driver.FindElement(By.XPath("//*[@id='graphs_area']/form/div[1]/a/i")).Click(); //initialize array of zones for (int i = 0; i < 89; ++i) { zone a = new zone(); a.name = i; Zones.Add(a); } //// Open all Forex's who are currently open for (int i = 1; i < 12; ++i) { driver.FindElement(By.XPath("//*[@id='content_header']/div/div/div[1]/a")).Click(); System.Threading.Thread.Sleep(500); Boolean isPresent = driver.FindElement(By.XPath("//*[@id='add_asset']/ul/li[2]")).Displayed; if (isPresent == true) { driver.FindElement(By.XPath("//*[@id='add_asset']/ul/li[2]")).Click(); } System.Threading.Thread.Sleep(200); String kk = driver.FindElement(By.XPath("//*[@id='Forex']/ul/li[" + i + "]/a/span[2]")).Text; Console.WriteLine(kk); if (kk != "closed") { try { driver.FindElement(By.XPath("//*[@id='Forex']/ul/li[" + i + "]")).Click(); //driver.FindElement(By.CssSelector("# Forex > ul > li:nth-child(" + i + ") > a")).Click(); ++openedForex; } catch { } } System.Threading.Thread.Sleep(500); } //create list of open assets and initialize them by name and position on webpage List <asset> assets = new List <asset>(); for (int i = 1; i <= openedForex; ++i) { asset a = new asset(); a.name = driver.FindElement(By.XPath("//*[@id='graphs_area']/form[" + i + "]/div[1]/h3")).Text; a.position = i; assets.Add(a); } //Loop that scrapes data and uses it to calculate information on assets every five seconds while (1 == 1) { for (int i = 0; i < assets.Count(); ++i) { //adds current market price value to asset_price list store(assets[i], driver, inc, inc2); //add all data to zones array about previous zones if (assets[i].previousState != 0) { ++Zones[assets[i].previousState].total; if (assets[i].current >= assets[i].previous) { ++Zones[assets[i].previousState].higher; } else if (assets[i].current < assets[i].previous) { ++Zones[assets[i].previousState].lower; } } //calculate slopes of each asset if (assets[i].Xpoints.Count() > 60) { assets[i].fill(); } //calculate priority of each asset if (assets[i].Xpoints.Count() > 600) { running = true; } if (assets[i].fiveslope != 0) { Console.WriteLine(assets[i].name + " state = " + assets[i].state); } } //see if bet is still running if (running == true) { //bet is still running try { readyelem = driver.FindElement(By.XPath("//*[@id='active_investments']/tbody/tr/td[2]")); ready = false; } //bet is not running catch { ready = true; } } //decide value of current_bet //if the program has been started up, and no bet is current underway, makes a bet if (running == true && ready == true) { //see if any forexs have closed since the begining, if so, close their boxes for (int i = 1; i <= assets.Count(); ++i) { try { closed = driver.FindElement(By.XPath("//*[@id='graphs_area']/form[" + i + "]/div[2]/div[1]/p")); if (closed.Text == "Closed") { driver.FindElement(By.XPath("//*[@id='graphs_area']/form[" + i + "]/div[1]/a/i")).Click(); assets.RemoveAt(i - 1); } } catch { } } chosen_one = choose(assets, Zones); //choose asset to bet on higher = chosen_one.nextDir; //choose which direction to bet //see if previous bet won or lost try { win = driver.FindElement(By.XPath("//*[@id='completed_investments']/tbody/tr[1]/td[10]/i")); } catch { driver.Navigate().Refresh(); System.Threading.Thread.Sleep(5000); win = driver.FindElement(By.XPath("//*[@id='completed_investments']/tbody/tr[1]/td[10]/i")); } previous = win.GetAttribute("title"); //change bet accordingly if (previous == "Lost: Out-of-the-Money") //if the previous bet lost { current_bet = Convert.ToInt32(Math.Floor(2.5 * Convert.ToDouble(current_bet))); } else if (previous == "Won: In-the-Money") { //if the previous bet won current_bet = 1; } //disregard first bet scenario if (firstbet == true) { current_bet = 1; firstbet = false; } //see if bet exceeds maximum bet size if (current_bet > 500) { current_bet = 1; } //OBSOLETE //if (current_bet == 12) //{ // if(higher == true) // { // higher = false; // } // else if(higher == false) // { // higher = true; // } //} //make bet try { bet(chosen_one, higher, current_bet, driver); ready = false; } catch { driver.Navigate().Refresh(); System.Threading.Thread.Sleep(5000); } } ++inc; ++inc2; ++time; System.Threading.Thread.Sleep(5000); } Console.ReadKey(); }