Author

Topic: [Need Quick Help] Bittrex API: Jquery (Read 3498 times)

newbie
Activity: 1
Merit: 0
December 23, 2017, 07:57:50 PM
#14
When using js, you can avoid all header issue headache by learning a little node.js. Cors-Anywhere is a pre-fab package I found to be quite useful. That way you can have your own proxy to sort out all cors issues on API calls. If you haven't messed around with node, I highly recommend it in general.
newbie
Activity: 2
Merit: 0
June 05, 2017, 10:43:48 AM
#13
Hi,
i did also have trouble getting this to work but after installing the needed "php5-curl" package and restarting apache everything was running just fine on my bananapi.
thought id share this if someone has the same problem.
member
Activity: 73
Merit: 10
March 14, 2017, 04:22:47 PM
#12
could someone be kind enough to renew the code?
perhaps leave your btc address for tips Smiley
ty!
newbie
Activity: 191
Merit: 0
January 07, 2015, 12:46:10 PM
#11
You can also use YQL as a proxy:

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%20%3D%20'https%3A%2F%2Fbittrex.com%2Fapi%2Fv1.1%2Fpublic%2Fgetticker%3Fmarket%3DBTC-DOGE'&format=json&callback=
legendary
Activity: 868
Merit: 1058
Creator of Nexus http://nexus.io
January 07, 2015, 12:13:43 PM
#10
Okay, thanks again! I just hate not knowing how my own code works... I like closure Wink

I'm the same way - it's a good habit to have  Smiley

Take Care,
Viz.
sr. member
Activity: 448
Merit: 250
I'm a Web Developer: HTML, CSS, PHP, JS.
January 07, 2015, 11:58:20 AM
#9
Okay, thanks again! I just hate not knowing how my own code works... I like closure Wink
legendary
Activity: 868
Merit: 1058
Creator of Nexus http://nexus.io
January 07, 2015, 11:34:04 AM
#8
Code:
document.getElementById("status").innerHTML = "Updating Ticker....";

This is how you dynamically update the DOM from Javascript. You can change anything from the innerHTML to the styles, ect.
Useful for dynamic pages.

Code:
function()
{
if(ajax_http.readyState != 4)
return;

if (ajax_http.status == 200)
{
document.getElementById("price").innerHTML = ajax_http.responseText;
document.getElementById("status").innerHTML = "Waiting...";
}
else
document.getElementById("status").innerHTML = "Failed to Update....";

}

This is the Async function that sets the div innerHTML from the AJAX Request.

Let me know if you need anything else,
Viz.
sr. member
Activity: 448
Merit: 250
I'm a Web Developer: HTML, CSS, PHP, JS.
January 07, 2015, 09:49:40 AM
#7
Not a problem: There is always a way my friend  Smiley

Take Care,
Viz.
Okay, I hate not understanding the code that I use...

Where in the javascript does it set the code that displays in here?:
Code:

+Thanks, I got it working...
legendary
Activity: 868
Merit: 1058
Creator of Nexus http://nexus.io
January 06, 2015, 08:18:06 PM
#6
Not a problem: There is always a way my friend  Smiley

Take Care,
Viz.
sr. member
Activity: 448
Merit: 250
I'm a Web Developer: HTML, CSS, PHP, JS.
January 06, 2015, 08:13:57 PM
#5
Not bad, I'll try it out as soon as possible. Thank you!
legendary
Activity: 868
Merit: 1058
Creator of Nexus http://nexus.io
January 06, 2015, 07:53:28 PM
#4
Same origin policies are there for a reason, so you'll run into a lot of headaches.

Manually you can have this in your curl.php to your server to accept cross domain requests:

To allow specific Domains:
Code:
header("Access-Control-Allow-Origin: http://coinshield.io");

To allow any Domain:
Code:
header("Access-Control-Allow-Origin: *");

You can also add this to your .htaccess file on the server hosting curl.php:

For any Domain:
Code:

    Header set Access-Control-Allow-Origin: *


Or for specific domains:
Code:

    Header set Access-Control-Allow-Origin: coinshield.io


And then test.php from coinshield.io: http://coinshield.io/test.php

Code:


Michael









User would be able to include your javascript file to view on their site.


Last choice is use an iframe: http://coinshield.io/iframe.html

Code:


This will maintain your security with same origin policies.

Regards,
Viz.

edit: added a couple more options
sr. member
Activity: 448
Merit: 250
I'm a Web Developer: HTML, CSS, PHP, JS.
January 06, 2015, 07:32:57 PM
#3
It helps, but the problem is I'm wanting to make a ticket that people can use on their websites... would this still work? Or would it be too hard on the hosting?
legendary
Activity: 868
Merit: 1058
Creator of Nexus http://nexus.io
January 06, 2015, 07:30:08 PM
#2
No need for jQuery - you'll run into a lot of obstacles trying to make cross domain requests with AJAX. This is from old tricks with XSS creating same origin policies which will subject you to the mercy of the web browser.

Try this with php and curl to get the ticker data. Name it curl.php on your server:

Code:
$ch curl_init();
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_URL,"https://bittrex.com/api/v1.1/public/getticker?market=BTC-DOGE");
$result curl_exec($ch);
curl_close($ch);

$json json_decode($result);

echo "ASK: ".number_format($json->result->Ask8);
echo "
BID: "
.number_format($json->result->Bid8);
echo "
PRICE: "
.number_format($json->result->Last8); 
?>


Then for your main page, name it whatever you would like. This will make an AJAX request on an interval loop to your domain to keep domain origin policies for all web browsers:

Code:


Michael









Here it is running on my server: http://videlicet.io/test.php

Hope this helps!
Viz.

sr. member
Activity: 448
Merit: 250
I'm a Web Developer: HTML, CSS, PHP, JS.
January 06, 2015, 06:03:54 PM
#1
I have no clue why this code is not working...
the same basic style works on Blockchain.info api.

Any ideas?
Code:


Michael






Jump to: