Twix mafia Posted May 11, 2013 Share Posted May 11, 2013 Hi I am having some problems with coding a part of my scar script after the newer changes (and that i have forgotten many things). I want scar to: copy (save) a tekst (number) from a website then say that number times 5 (lets call the new number a) then copy (save) another number from another website (lets call this b) then i want scar to calculate the difference between the numbers - and if the difference is over lets say 1 then it should proceed Quote Link to comment Share on other sites More sharing options...
Janilabo Posted May 11, 2013 Share Posted May 11, 2013 Not really sure what you are after... Can you show code that you wrote in the past? If you have written something.. Maybe we can convert that to new standards of SCAR Divi. Also, remember to check out SCAR Divi Wiki, because there is a high chance that you will find it pretty helpful: Category:Functions - SCAR Divi Manual Quote Link to comment Share on other sites More sharing options...
Twix mafia Posted May 11, 2013 Author Share Posted May 11, 2013 (edited) well... - i dont have any code that matches what i need to write right now - but i need scar to somehow regonize and use/interpret values found on a website. I've made scar highlight the number i need it to use - then i thought if i could say ctrl+C to copy it - maybe SCAR could import the data from the clipboard? anyways i need scar to import some numbers from a website - the way it accesses/imports the numbers dosen't matter edit: Yea i used a lot of time on the scar wiki - but all the changes in the programming language have completely confused me! Edited May 11, 2013 by Twix mafia Quote Link to comment Share on other sites More sharing options...
Janilabo Posted May 11, 2013 Share Posted May 11, 2013 Yes, SCAR can handle clipboard.. begin SetClipboard('Test!'); // This could be replaced with CTRL + C for copying.. WriteLn(GetClipboard); end. Quote Link to comment Share on other sites More sharing options...
Twix mafia Posted May 11, 2013 Author Share Posted May 11, 2013 (edited) Oh thank you - but how do i replace it with Ctrl + c?..... edit: well i have to define it as a variable, right? then i can set the variable as the clipboard - but how can i make scar copy something? - thats something i could make work before all this updates.. - i cant press ctrl + c anymore - it wont work with the things i try Edited May 11, 2013 by Twix mafia Quote Link to comment Share on other sites More sharing options...
Janilabo Posted May 11, 2013 Share Posted May 11, 2013 begin VKeyDown(VK_CONTROL); VKeyDown(CharToVKey('C')); VKeyUp(CharToVKey('C')); VKeyUp(VK_CONTROL); WriteLn(GetClipboard); end. - - - Updated - - - However... Using SCAR Divi's internet-related functions would be the smarter choice really. Clipboard works aswell I guess but... I am pretty sure it would be a lot more stable using those internet functions. What is the webpage you are using the script for? If you can't give it to public, you could always private message it to me. Also, if you give me nice details, maybe I could come up with something. -Jani Quote Link to comment Share on other sites More sharing options...
Twix mafia Posted May 11, 2013 Author Share Posted May 11, 2013 oh thank you The side is Bitcoinity EUR I want scar to read the exchange rate. - i see it godt the ID "last_price" Then i want it to calculate the exchange rate to USD (i think i will just give it the rate of the day manually) after that it has to go to Bitcoinity USD and read that exchange rate. after that i want scar to find the difference and then do different actions whether the difference is over/under eg. 1. Here i can use the "if" and "if not" i think? Quote Link to comment Share on other sites More sharing options...
Janilabo Posted May 11, 2013 Share Posted May 11, 2013 Is this value the exchange rate: 88.21 EUR / BTC? Quote Link to comment Share on other sites More sharing options...
Twix mafia Posted May 11, 2013 Author Share Posted May 11, 2013 Yes - that is correnct Quote Link to comment Share on other sites More sharing options...
Janilabo Posted May 11, 2013 Share Posted May 11, 2013 Here is a little function: function ExchangeRate(exchange: string): Extended; begin Result := StrToFloatDef(Between('<span id=''last_price''>', '</span>', GetPage('http://bitcoinity.org/markets/mtgox/' + Trim(exchange))), -1); end; begin ClearDebug; WriteLn('Last Price [EUR]: ' + FloatToStr(ExchangeRate('EUR'))); WriteLn('Last Price [uSD]: ' + FloatToStr(ExchangeRate('USD'))); end. Quote Link to comment Share on other sites More sharing options...
Twix mafia Posted May 11, 2013 Author Share Posted May 11, 2013 wow... nice didnt know you could use Scar for that! - thank you VERY much! Quote Link to comment Share on other sites More sharing options...
Janilabo Posted May 11, 2013 Share Posted May 11, 2013 NOTE: It returns -1, if for some reason it couldn't capture the rate correctly. So you can (well, need to) add failsafes for those cases. It might return -1 sometimes when the page is updating the rate... I think. Anyways, now it's pretty much math that you will need to plant in. - - - Updated - - - If you want version that wont ever return as -1, then you can do this: function ExchangeRate(exchange: string): Extended; begin repeat Result := StrToFloatDef(Between('<span id=''last_price''>', '</span>', GetPage('http://bitcoinity.org/markets/mtgox/' + Trim(exchange))), -1); until (Result > -1); end; begin ClearDebug; WriteLn('Last Price [EUR]: ' + FloatToStr(ExchangeRate('EUR'))); WriteLn('Last Price [uSD]: ' + FloatToStr(ExchangeRate('USD'))); end. Quote Link to comment Share on other sites More sharing options...
Twix mafia Posted May 11, 2013 Author Share Posted May 11, 2013 (edited) oh i see! thats smart! - but i think i will put in a wait before until - just so my computer wont crash if bitcoinity goes down edit: well, thats not that smart to do, is it? - then it will wait before et goes on - even if there is no error..? Edited May 11, 2013 by Twix mafia Quote Link to comment Share on other sites More sharing options...
Janilabo Posted May 11, 2013 Share Posted May 11, 2013 Here is also another way (method) that you can use to get the rate: var client: Integer; procedure ScriptTerminate; begin FreeHTTPClient(client); end; function ExchangeRate(exchange: string): Extended; begin repeat Result := StrToFloatDef(Between('<span id=''last_price''>', '</span>', GetHTTPPage(client, 'http://bitcoinity.org/markets/mtgox/' + exchange)), -1); until (Result > -1); end; var t, i: Integer; begin ClearDebug; client := InitializeHTTPClient(True, True); for i := 0 to 9 do begin t := GetSystemTime; WriteLn(FloatToStr(ExchangeRate('EUR')) + ' [' + IntToStr(GetSystemTime - t) + ' ms.]'); end; end. That requires the client variable, but it is a little faster than GetPage() most of the time. You can compare that to the GetPage() version, below: function ExchangeRate(exchange: string): Extended; begin repeat Result := StrToFloatDef(Between('<span id=''last_price''>', '</span>', GetPage('http://bitcoinity.org/markets/mtgox/' + Trim(exchange))), -1); until (Result > -1); end; var t, i: Integer; begin ClearDebug; for i := 0 to 9 do begin t := GetSystemTime; WriteLn(FloatToStr(ExchangeRate('EUR')) + ' [' + IntToStr(GetSystemTime - t) + ' ms.]'); end; end. Most of the time the GetHTTPPage() wins. -Jani Quote Link to comment Share on other sites More sharing options...
Twix mafia Posted May 11, 2013 Author Share Posted May 11, 2013 (edited) You are right - et seems like GetHTTPPage() is about 200 ms faster to get the Exhange rate EDIT: (FORGET THIS - YOU ALREDY ANSWERED) can you tell my why this does not work? var client: Integer; procedure ScriptTerminate; begin FreeHTTPClient(client); end; function ExchangeRate(exchange: string): Extended; begin repeat Result := StrToFloatDef(Between('<span class="bld">', ' USD</span>', GetHTTPPage(client, 'https://www.google.com/finance?q=' + exchange)), -1); wait(200); until (Result > -1); end; begin ClearDebug; client := InitializeHTTPClient(True, True); WriteLn(FloatToStr(ExchangeRate('EURUSD'))); end. Im trying to import the exchange rate for EUR to USD from: https://www.google.com/finance?q=EURUSD Edited May 11, 2013 by Twix mafia Quote Link to comment Share on other sites More sharing options...
Janilabo Posted May 11, 2013 Share Posted May 11, 2013 Also, here is with function that uses X-Rates.com page for currency rate: GetPage() version: function ExchangeRate(exchange: string): Extended; begin exchange := Trim(exchange); case (exchange <> '') of True: repeat Result := StrToFloatDef(Between('<span id=''last_price''>', '</span>', GetPage('http://bitcoinity.org/markets/mtgox/' + exchange)), -1); until (Result > -1); False: Result := -1; end; end; function CalculateCurrencyRate(amount: Extended; fromCurrency, toCurrency: string): Extended; var data: string; tmp: Extended; begin fromCurrency := Trim(fromCurrency); toCurrency := Trim(toCurrency); case ((fromCurrency <> '') and (toCurrency <> '')) of True: repeat data := GetPage('http://www.x-rates.com/calculator/?from=' + fromCurrency + '&to=' + toCurrency + '&amount=' + FloatToStr(amount)); Result := StrToFloatDef(Between('<span class="ccOutputRslt">', '<span class="ccOutputTrail">', data), -1); if (Result > -1) then begin tmp := StrToFloatDef(FloatToStr(Result) + Between('<span class="ccOutputTrail">', '</span><span class="ccOutputCode">', data), -1); if (tmp > -1) then Result := tmp; end; data := ''; until (Result > -1); False: Result := -1; end; end; var t: Integer; begin ClearDebug; t := GetSystemTime; WriteLn('USD => EUR: ' + FloatToStr(CalculateCurrencyRate(1, 'USD', 'EUR')) + ' [' + IntToStr(GetSystemTime - t) + ' ms.]'); t := GetSystemTime; WriteLn('EUR => USD: ' + FloatToStr(CalculateCurrencyRate(1, 'EUR', 'USD')) + ' [' + IntToStr(GetSystemTime - t) + ' ms.]'); t := GetSystemTime; WriteLn(FloatToStr(ExchangeRate('EUR')) + ' [' + IntToStr(GetSystemTime - t) + ' ms.]'); end. ..and GetHTTPPage() version: var client: Integer; procedure ScriptTerminate; begin FreeHTTPClient(client); end; function ExchangeRate(exchange: string): Extended; begin exchange := Trim(exchange); case (exchange <> '') of True: repeat Result := StrToFloatDef(Between('<span id=''last_price''>', '</span>', GetHTTPPage(client, 'http://bitcoinity.org/markets/mtgox/' + exchange)), -1); until (Result > -1); False: Result := -1; end; end; function CalculateCurrencyRate(amount: Extended; fromCurrency, toCurrency: string): Extended; var data: string; tmp: Extended; begin fromCurrency := Trim(fromCurrency); toCurrency := Trim(toCurrency); case ((fromCurrency <> '') and (toCurrency <> '')) of True: repeat data := GetHTTPPage(client, 'http://www.x-rates.com/calculator/?from=' + fromCurrency + '&to=' + toCurrency + '&amount=' + FloatToStr(amount)); Result := StrToFloatDef(Between('<span class="ccOutputRslt">', '<span class="ccOutputTrail">', data), -1); if (Result > -1) then begin tmp := StrToFloatDef(FloatToStr(Result) + Between('<span class="ccOutputTrail">', '</span><span class="ccOutputCode">', data), -1); if (tmp > -1) then Result := tmp; end; data := ''; until (Result > -1); False: Result := -1; end; end; var t: Integer; begin ClearDebug; client := InitializeHTTPClient(True, True); t := GetSystemTime; WriteLn('USD => EUR: ' + FloatToStr(CalculateCurrencyRate(1, 'USD', 'EUR')) + ' [' + IntToStr(GetSystemTime - t) + ' ms.]'); t := GetSystemTime; WriteLn('EUR => USD: ' + FloatToStr(CalculateCurrencyRate(1, 'EUR', 'USD')) + ' [' + IntToStr(GetSystemTime - t) + ' ms.]'); t := GetSystemTime; WriteLn(FloatToStr(ExchangeRate('EUR')) + ' [' + IntToStr(GetSystemTime - t) + ' ms.]'); end. -Jani Quote Link to comment Share on other sites More sharing options...
Twix mafia Posted May 11, 2013 Author Share Posted May 11, 2013 (edited) wow - i begin to do not understand what is going on anymore - but well... it works perfectly! but now i got all 3 things i need: EUR to USD USD/BTC EUR/BTC How do i then make it calculate how much the EUR rate is in USD? a := FloatToStr(ExchangeRate('EUR') b := FloatToStr(CalculateCurrencyRate(1, 'EUR', 'USD') c := a*b WriteLn(c); or something like that?? Edited May 11, 2013 by Twix mafia Quote Link to comment Share on other sites More sharing options...
Janilabo Posted May 11, 2013 Share Posted May 11, 2013 If you want to use that Google page for the currency rate, then here (NOTE: it's limited to amount as 1): GetPage() version: function ExchangeRate(exchange: string): Extended; begin exchange := Trim(exchange); case (exchange <> '') of True: repeat Result := StrToFloatDef(Between('<span id=''last_price''>', '</span>', GetPage('http://bitcoinity.org/markets/mtgox/' + exchange)), -1); until (Result > -1); False: Result := -1; end; end; function CalculateCurrencyRate(fromCurrency, toCurrency: string): Extended; var data: string; tmp: Extended; begin fromCurrency := Trim(fromCurrency); toCurrency := Trim(toCurrency); case ((fromCurrency <> '') and (toCurrency <> '')) of True: repeat data := GetPage('https://www.google.com/finance?q=' + fromCurrency + toCurrency); Result := StrToFloatDef(Between('1 ' + fromCurrency + ' = <span class=bld>', ' ' + toCurrency + '</span>', data), -1); data := ''; until (Result > -1); False: Result := -1; end; end; var t: Integer; begin ClearDebug; t := GetSystemTime; WriteLn('USD => EUR: ' + FloatToStr(CalculateCurrencyRate('USD', 'EUR')) + ' [' + IntToStr(GetSystemTime - t) + ' ms.]'); t := GetSystemTime; WriteLn('EUR => USD: ' + FloatToStr(CalculateCurrencyRate('EUR', 'USD')) + ' [' + IntToStr(GetSystemTime - t) + ' ms.]'); t := GetSystemTime; WriteLn(FloatToStr(ExchangeRate('EUR')) + ' [' + IntToStr(GetSystemTime - t) + ' ms.]'); end. For some reason Google doesn't work with GetHTTPPage() version - I have absolutely no idea why. :\ As to your question, not sure what you need? Which rate? Do remember, that the ExchangeRate() function grabs the information from the bitcoinity page, so this one: bitcoinity.org/markets Quote Link to comment Share on other sites More sharing options...
Twix mafia Posted May 11, 2013 Author Share Posted May 11, 2013 Its okay - i will just use the x-rates site its fast enough! oh yea i see i want this exchange rate bitcoinity.org/markets to be converted into USD with the x-rates EUR -> USD rate Because the mtgox EUR and USD market does not match up perfectly Quote Link to comment Share on other sites More sharing options...
Janilabo Posted May 11, 2013 Share Posted May 11, 2013 EDIT: I think we will need BTC / EUR & BTC / USD conversions to do the calculation(s) you are after.. Is there somewhere BTC => EUR and BTC USD => conversion at mtgox webpage? Hmm.. The reason why GetHTTPPage() doesn't work with that Google page, is because it doesn't support SSL, whereas GetPage() does - I got this information from SCAR Divi wiki. Quote Link to comment Share on other sites More sharing options...
Twix mafia Posted May 11, 2013 Author Share Posted May 11, 2013 (edited) Well if we say the EUR/BTC rate (about 90) * the USD/EUR rate (EUR => USD) rate then we have the price of one BTC on the EU market but in the USD currency. like: https://www.google.dk/search?safe=off&q=89.89+*+1.298448&oq=89.89+*+1.298448&gs_l=serp.3...1516.1765.0.1943.2.2.0.0.0.0.74.137.2.2.0.cappswebhl..0.0...1.1.12.serp.uQh7QqfNy1w You ask about mtgox... well its the same rates you see on mtgox as on bitcoinity... - so the BTC => EUR and BTC USD => conversion would be the same. Im interestet in seeing the difference on the two markets. Edited May 11, 2013 by Twix mafia Quote Link to comment Share on other sites More sharing options...
Janilabo Posted May 11, 2013 Share Posted May 11, 2013 With the calculation you added to your post here a little earlier, this would be the correct way to do it (so, I am using the way you did, because I am getting mindfucked atm, LOL!): var client: Integer; procedure ScriptTerminate; begin FreeHTTPClient(client); end; function ExchangeRate(exchange: string): Extended; begin exchange := Trim(exchange); case (exchange <> '') of True: repeat Result := StrToFloatDef(Between('<span id=''last_price''>', '</span>', GetHTTPPage(client, 'http://bitcoinity.org/markets/mtgox/' + exchange)), -1); until (Result > -1); False: Result := -1; end; end; function CalculateCurrencyRate(amount: Extended; fromCurrency, toCurrency: string): Extended; var data: string; tmp: Extended; begin fromCurrency := Trim(fromCurrency); toCurrency := Trim(toCurrency); case ((fromCurrency <> '') and (toCurrency <> '')) of True: repeat data := GetHTTPPage(client, 'http://www.x-rates.com/calculator/?from=' + fromCurrency + '&to=' + toCurrency + '&amount=' + FloatToStr(amount)); Result := StrToFloatDef(Between('<span class="ccOutputRslt">', '<span class="ccOutputTrail">', data), -1); if (Result > -1) then begin tmp := StrToFloatDef(FloatToStr(Result) + Between('<span class="ccOutputTrail">', '</span><span class="ccOutputCode">', data), -1); if (tmp > -1) then Result := tmp; end; data := ''; until (Result > -1); False: Result := -1; end; end; var t: Integer; a, b, c: Extended; begin ClearDebug; client := InitializeHTTPClient(True, True); t := GetSystemTime; a := ExchangeRate('EUR'); b := CalculateCurrencyRate(1, 'EUR', 'USD'); c := (a * b) WriteLn(c); end. Quote Link to comment Share on other sites More sharing options...
Twix mafia Posted May 11, 2013 Author Share Posted May 11, 2013 (edited) ooooh you are so nice! thank you! I edited the end a bit - so i will get the difference: var t: Integer; a, b, c, d, e: Extended; begin ClearDebug; client := InitializeHTTPClient(True, True); t := GetSystemTime; a := ExchangeRate('EUR'); b := CalculateCurrencyRate(1, 'EUR', 'USD'); c := (a * b); d := ExchangeRate('USD'); e := (d - c); WriteLn(e); end. I dont have time to make more right now - but maybe tomorrow or in next week i have to make mtgox make transactions according to the rate - i will probably need help for that too if you have time and desire? How can i thank you? By sending you something in LOL? - by giving you Dota 2? reddit gold? anything? Edited May 11, 2013 by Twix mafia Quote Link to comment Share on other sites More sharing options...
Janilabo Posted May 11, 2013 Share Posted May 11, 2013 ooooh you are so nice! thank you! I edited the end a bit - so i will get the difference: var t: Integer; a, b, c, d, e: Extended; begin ClearDebug; client := InitializeHTTPClient(True, True); t := GetSystemTime; a := ExchangeRate('EUR'); b := CalculateCurrencyRate(1, 'EUR', 'USD'); c := (a * b); d := ExchangeRate('USD'); e := (d - c); WriteLn(e); end. I dont have time to make more right now - but maybe tomorrow or in next week i have to make mtgox make transactions according to the rate - i will probably need help for that too if you have time and desire? How can i thank you? By sending you something in LOL? - by giving you Dota 2? anything? Glad to see/hear it works buddy!I will definitely try and help you (and others) here in future aswell, well, always when I am just able to help out, because there is sometimes cases which I can't solve, but sometimes someone else can solve those cases! Anyways, I wasn't after any goodies here, but thanks for the great offers anyways! Only trying to be helpful here. +I really enjoy challenges like these! I am just happy to see you appreciate my help here - thanks man. Positive feedback is always welcome, makes anyone feel good. -Jani Quote Link to comment Share on other sites More sharing options...
Twix mafia Posted May 14, 2013 Author Share Posted May 14, 2013 (edited) I've added a little more to the ending var t: Integer; a, b, c, d, e, f: Extended; begin ClearDebug; client := InitializeHTTPClient(True, True); t := GetSystemTime; a := ExchangeRate('EUR'); b := CalculateCurrencyRate(1, 'EUR', 'USD'); c := (a * b); //Mtgox EUR i USD d := ExchangeRate('USD'); e := (d - c); //difference. Skal være højre end f WriteLn(e); f := ((1/0.994)*(c-(0.994*c))); //Fees. Skal være mindre end e. WriteLn(f); if (e>f) then begin WriteLn('Forskellen er større end fees'); end; if not (e>f) then begin WriteLn('lort'); end; end. The two writelines just says go for it and do not go for it... Can you somehow make Scar buy you BTC automaticly from MTgox on the EUR market and instant after reciving the BTC sell it on the USD market? Its maybe not the smartest idéa do have the login informations stored in a scar script - so i thought, can you log in with your browser - and just leave it logged in. And then just send the information about buying and selling with scar? - og do i have to make scar send/have the login informations too ? Edited May 14, 2013 by Twix mafia Quote Link to comment Share on other sites More sharing options...