ColdFusion API call to Poloniex
I've been doing a lot of crypto-coin trading lately and Poloniex, one of the trading platforms offers a nice API to retrieve my account information. This was a good chance to use the HMAC() function that became available in ColdFusion 10 to calculate signatures.
Whether you've been trading Bitcoin (BTC), Ethereum (ETH) or any of the hundreds or so other Cryptocurrencies, you'll know that the prices are constantly in flux. Poloniex's API makes it easy to code a way to track your balance on every coin.
Below is a code snippet that will demonstrate what is needed to make a successful Poloniex API call with ColdFusion 10 or above:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- Set the URL for Poloniex Trading API calls ---> | |
<cfset thisUrl = "https://poloniex.com/tradingApi"> | |
<cfset poloniexSecret = "[your secret key]"> | |
<cfset poloniexKey = "[your public key]"> | |
<!--- Here is the command we want to run ---> | |
<cfset thisCommand="returnBalances"> | |
<!--- use the tick count to get an incrementing integer---> | |
<cfset nonce = int(getTickCount()/1000)> | |
<!--- Build the string for signing, this is the post formfield values ---> | |
<!--- Note that the order here must match the order of the formfields in the cfhttp call ---> | |
<!--- or else the signature won't calculate correctly. Some APIs put them in Alpha ---> | |
<!--- order, Poloniex does not ---> | |
<cfset strForSignature = "command=#thisCommand#&nonce=#nonce#"> | |
<!--- Get the HMAC for this string, note that HMAC() returns a Hexidecimal string ---> | |
<cfset signature = hmac(strForSignature, poloniexSecret, "HmacSha512")> | |
<!--- Do a cfhttp and store the results in the apiResult variable ---> | |
<cfhttp url="#thisUrl#" method="post" result="apiResult"> | |
<cfhttpparam name="key" type="header" value="#poloniexKey#"/> | |
<cfhttpparam name="sign" type="header" value="#signature#"/> | |
<cfhttpparam name="Content-Type" type="header" value="application/x-www-form-urlencoded"/> | |
<cfhttpparam name="command" value="#thisCommand#" type="formfield"> | |
<cfhttpparam name="nonce" value="#nonce#" type="formfield"> | |
</cfhttp> | |
<cfset apiStruct = DeserializeJSON(apiResult.filecontent)> | |
<cfdump var="#apiStruct#"> | |
Ontology also wants to create the core protocols that enable instant multi-source authentication of people, institutions, digital assets and so on. With this, they envision different types of reputation systems that are based on the trustless environment distributed ledger technology provides.Explore more at: Neon Beginner
ReplyDelete