Bitcoin Forum
November 11, 2024, 05:57:48 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Coins-e.com PHP sample  (Read 1937 times)
citboin (OP)
Newbie
*
Offline Offline

Activity: 58
Merit: 0


View Profile
July 23, 2013, 03:42:13 AM
 #1

Hey everyone,

I am looking at getting trading on coins-e.com however with my limited of knowledge of python, I would much rather use PHP to write my bot. Does anyone have some sort of coins-e.com PHP sample I could peruse? Or perhaps someone who knows both PHP and python? Smiley I have tried to convert the cryptsy sample (PHP), however I have yet to be successful! I would appreciate any help very much.

coins-e.com (python sample): https://www.coins-e.com/exchange/api/documentation/

cryptsy.com (PHP sample): https://www.cryptsy.com/pages/api

Thank you!

The Lysdexic Citboin
daybyter
Legendary
*
Offline Offline

Activity: 965
Merit: 1000


View Profile
July 23, 2013, 05:10:36 PM
 #2

I using java, but I think the API description is pretty straightforward? What exactly is your problem?

nitrous
Sr. Member
****
Offline Offline

Activity: 246
Merit: 250


View Profile
July 23, 2013, 08:50:54 PM
 #3

To figure out how to implement this API, you need to evaluate what you need to do. There are two types of methods, unauthenticated GET methods and authenticated POST methods. None of the GET methods need any query parameters. The POST methods take query parameters (only key and sign), and some POST parameters. The easiest way to do this would then seem to be to make two functions, one for GET methods and the other for POST methods.


1. The GET function simply needs to take the URL, and then use cURL to download it. You may need to substitute the pair yourself for those methods which need it. You then need to decode the JSON request into an array.

2. The POST functions need to take the URL and an array of POST parameters. You also need a way of providing your public and private key, which depends on your implementation. First, you need to set the nonce if not set in the parameter array. Then you need to encode the parameters in URL query string format (probably with http_build_query). This is your post data. Now you need to generate the HMAC sign. Make sure you use SHA-512 for your hash function, use your private key for the key, and post data for the message. Then use the HMAC algorithm to get the hexadecimal digest.

Code:
$sign = hash_hmac("sha512", $post_data, $PRIVATE_KEY, false);

Now, build your query string as "key=$PUBLIC_KEY&sign=$sign", and append it to the end of the url with a ?, e.g. "https://www.coins-e.com/api/v2/market/WDC_BTC/?key=547189fad79e08&sign=709ed89b0ac". Finally, use cURL to post post_data to the URL you just constructed and decode the JSON request into an array again.


Hopefully this should make it relatively straightforward and give you some pointers to start. I haven't programmed in PHP for a while but if you need some help on a specific part I could look into it for you.

Donations: 1Q2EN7TzJ6z82xvmQrRoQoMf3Tf4rMCyvL
MtGox API v2 Unofficial Documentation: https://bitbucket.org/nitrous/mtgox-api/overview
MtGox API v2 Unofficial Documentation Forum Thread: https://bitcointalk.org/index.php?topic=164404.0
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!