Developer's Guide - Api

Overview

Fibercoin Exchange provides a simple and powerful REST API to allow you to programatically perform nearly all actions you can from our web interface. All requests use the application/json content type and go over https. The base url is https://fiberchange.com/api/{version}/. All requests are GET requests and all responses come in a default response object with the result in the result field. Always check the success flag to ensure that your API call succeeded.

We are currently restricting orders to 500 open orders and 200,000 orders a day. We reserve the right to change these settings as we tune the system.

If you have any questions, feedback or recommendation for API support you can post a question in our support center.


Getting Started

  • General
  • Authentication
  • API Reference
  • Client Libraries

General

We provide a simple RESTful API. All calls are GETs and should be called via https. We will support n-1 versions of the API. Our current stable API is v1. The endpoints have a standard format as follows:

https://fiberchange.com/api/{version}/{method}?param=value

Authentication

In the spirit of keeping things simple, we offer an easy to manage API Key authentication method. You can have multiple API keys, each with their own level of rights. To manage your API keys please goto Settings->Manage API Keys. API Rights

  • Read Info - You can only view the balances, orders, and other details of the account
  • Trade Limit - This allows the API key to place LIMIT buy and sell orders
  • Withdraw - We allow you to programatically withdraw any currency to an address you provide. This can be used to quick arbitrage exchanges or move money into cold storage after thresholds.
For this version, we use a standard HMAC-SHA512 signing. Append apikey and nonce to your request and calculate the HMAC hash and include it under an apisign header. Note: the nonce is not respected right now but will be enforced later.

<?php

$request = '/account/getbalance';
$currency = 'FBC';

$apikey='__API_KEY__';
$apisecret='__API_SECRET__';
$nonce=time();

$uri='https://fiberchange.com/api/v1'.$request .'?apikey='.$apikey.'&nonce='.$nonce.'&market='.$market.'&currency='.$currency;
$sign=hash_hmac('sha512',$uri,$apisecret);
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
$execResult = curl_exec($ch);
$obj = json_decode($execResult);   
?>                    
                


'use strict';

const API_PUB_KEY = "__YOUR_API_PUBLIC_KEY__";
const API_PRIV_KEY = "__YOUR_API_PRIVATE_KEY__";

GetOpenOrders('FBC-DOGE', data => { console.log(JSON.stringify(data.result || data)); });

function GetOpenOrders(market, callback)
{
    const nonce = Date.now()+Math.floor(Math.random() * (1000)) + 1;
    const uri = 'https://fiberchange.com/api/v1/market/getopenorders?apikey='+API_PUB_KEY+'&nonce='+nonce+'&market='+market;
    const parsed = require('url').parse(uri, true);
    const signature = require('crypto').createHmac('sha512', API_PRIV_KEY).update(new Buffer(uri, 'utf-8')).digest('hex');
    
    const options = {
        host: parsed.host,
        path: parsed.path,
        headers: { 'apisign': signature }
    };
    
    require("https").request(options, res => {
        let output = '';
        res.on('data', chunk => { output += chunk; });
        res.on('end', () => { return callback(JSON.parse(output)); }); }).end();
};
                

API Reference

Our APIs are broken into distinct groups
  • Public - Public information available without an API key
  • Market - For programatic trading of crypto currencies
  • Account - For managing your account

Public Api

/public/getmarkets

Used to get the open and available trading markets at OpenTrade along with other meta data.

Parameters

None

Request:
https://fiberchange.com/api/v1/public/getmarkets
Response:
    {
	"success" : true,
	"message" : "",
	"result" : [{
			"MarketCurrency" : "LTC",
			"BaseCurrency" : "FBC",
			"MarketCurrencyLong" : "Litecoin",
			"BaseCurrencyLong" : "Fibercoin",
			"MinTradeSize" : "0",
			"MarketName" : "FBC-LTC",
			"IsActive" : true,
			"Created" : "2014-02-13T00:00:00"
		}, {
			"MarketCurrency" : "DOGE",
			"BaseCurrency" : "FBC",
			"MarketCurrencyLong" : "Dogecoin",
			"BaseCurrencyLong" : "Fibercoin",
			"MinTradeSize" : "0",
			"MarketName" : "FBC-DOGE",
			"IsActive" : true,
			"Created" : "2014-02-13T00:00:00"
		}
        ]
    }

                    
/public/getorderbook

Used to get retrieve the orderbook for a given market

Parameters
parameter required description
market required a string literal for the market (ex: FBC-LTC)
type optional buy, sell or both to identify the type of orderbook to return. By default type='both'
Request:
https://fiberchange.com/api/v1/public/getorderbook?market=FBC-LTC&type=both 
Response:
    {
	"success" : true,
	"message" : "",
	"result" : {
		"buy" : [{
				"Quantity" : 12.37000000,
				"Rate" : 0.02525000
			}
		],
		"sell" : [{
				"Quantity" : 32.55412402,
				"Rate" : 0.02540000
			}, {
				"Quantity" : 60.00000000,
				"Rate" : 0.02550000
			}, {
				"Quantity" : 60.00000000,
				"Rate" : 0.02575000
			}, {
				"Quantity" : 84.00000000,
				"Rate" : 0.02600000
			}
		]
	}
    }

                    

/public/getlastmarketdata

Used to get the last summary of all coins

Request:
https://fiberchange.com/api/v1/public/getlastmarketdata
Response:
{
"success":true,
"message":"",
"result":{
    "coins":[
    {"id":1,"name":"Fibercoin","ticker":"FBC","icon":"https%3A//fiberchange.com/logos/fbc.png","info":{"active":true,"minconf":3,"hold":0.002,"page":"1","withdraw":"Enabled","orders":"Enabled"},"volume":0,"price":0,"fromBuyerToSeller":0,"buysell":"buy","prev_price":0,"prev_frombuyertoseller":0,"prev_buysell":"buy"},
    {"id":2,"name":"Meison","ticker":"MTXC","icon":"https%3A//raw.githubusercontent.com/bitcoin/bitcoin/master/src/qt/res/icons/bitcoin.png","info":{"active":true,"minconf":3,"hold":0.0002,"page":"https://bitcointalk.org/index.php?topic=5.0","withdraw":"Enabled","orders":"Enabled"},"volume":"0.000014000000","price":"1441881.0","fromBuyerToSeller":"20.186334","buysell":"buy","prev_price":"1437854.0","prev_frombuyertoseller":1437854,"prev_buysell":"buy"},
    {"id":3,"name":"Dogecoin","ticker":"DOGE","icon":"https%3A//raw.githubusercontent.com/dogecoin/dogecoin/master/src/qt/res/icons/bitcoin.png","info":{"minconf":3,"hold":2,"active":true,"page":"https://bitcointalk.org/index.php?topic=361813.0"},"volume":"8.8580000","price":"0.71999990","fromBuyerToSeller":"6.3777591","buysell":"sell","prev_price":"0.71999990","prev_frombuyertoseller":0.7199999034455098,"prev_buysell":"sell"},
    ***]
    }
}                    
                    
/public/getmarketsummary

Used to get the last 24 hour summary of one active exchange

Parameters
parameter required description
market required a string literal for the market (ex: FBC-LTC)
period optional period in hours. Can be: 24, 250, 1000 or 6000. By default period=24
Request:
https://fiberchange.com/api/v1/public/getmarketsummary?market=FBC-LTC&period=250
Response:
    {
	"success" : true,
	"message" : "",
	"result" : {
			"MarketName" : "FBC-LTC",
			"High" : 0.01350000,
			"Low" : 0.01200000,
			"Volume" : 3833.97619253,
			"Last" : 0.01349998,
			"Bid" : 0.01271001,
			"Ask" : 0.01291100,
			"OpenBuyOrders" : 45,
			"OpenSellOrders" : 45
		}
    }
                    
/public/getmarkets24

Used to get the last 24 hour summary of all active exchanges

Parameters Request:
https://fiberchange.com/api/v1/public/getmarkets24
Response:
    {
    "success":true,
    "message":"",
    "result":{
        "TotalMarkets":22,
        "v24":30545.55264574,
        "data":{
            "YTN":{"MarketName":"FBC-YTN","High":"1.10000000","Low":"1.10000000","Volume":"21.74889000","Last":"1.1000000","Bid":"1.10000000","Ask":"1.99990000","OpenBuyOrders":5,"OpenSellOrders":15,"coin_icon_src":"https%3A//raw.githubusercontent.com/conan-equal-newone/yenten/master/src/qt/res/icons/bitcoin.png","coin_info":{"minconf":6,"hold":0.002,"active":true,"page":"https://bitcointalk.org/index.php?topic=2329470.0"}},
            "WAVI":{"MarketName":"FBC-WAVI","High":"1.01000000","Low":"0.49999999","Volume":"890.04802700","Last":"1.0100000","Bid":"0.31000001","Ask":"1.01000000","OpenBuyOrders":8,"OpenSellOrders":104,"coin_icon_src":"https%3A//raw.githubusercontent.com/wavidev-the-man/wavi/master/src/qt/res/icons/bitcoin.png","coin_info":{"minconf":3,"hold":0.002,"active":true,"page":"https://bitcointalk.org/index.php?topic=3146751.0"}},
            ...
            }
        }
    }
                    
/public/getmarkethistory

Used to retrieve the latest trades that have occured for a specific market.

Parameters
parameter required description
market required a string literal for the market (ex: FBC-LTC)
Request:
https://fiberchange.com/api/v1/public/getmarkethistory?market=FBC-LTC
Response:
    {
	"success" : true,
	"message" : "",
	"result" : [{
			"Id" : 319435,
			"TimeStamp" : "2018-01-01T03:21:20.08",
			"Quantity" : 0.30802438,
			"Price" : 0.01263400,
			"Total" : 0.00389158,
			"FillType" : "FILL",
			"OrderType" : "BUY"
		}, {
			"Id" : 319433,
			"TimeStamp" : "2018-01-01T03:21:20.08",
			"Quantity" : 0.31820814,
			"Price" : 0.01262800,
			"Total" : 0.00401833,
			"FillType" : "FILL",
			"OrderType" : "BUY"
		}, {
			"Id" : 319379,
			"TimeStamp" : "2018-01-01T02:58:48.127",
			"Quantity" : 49.64643541,
			"Price" : 0.01263200,
			"Total" : 0.62713377,
			"FillType" : "FILL",
			"OrderType" : "SELL"
		}, {
			"Id" : 319378,
			"TimeStamp" : "2018-01-01T02:58:46.27",
			"Quantity" : 0.35356459,
			"Price" : 0.01263200,
			"Total" : 0.00446622,
			"FillType" : "FILL",
			"OrderType" : "SELL"
		}
	]
    }
                        
                    

Market Apis

/market/buylimit

Used to place a buy order in a specific market. Use buylimit to place limit orders. Make sure you have the proper permissions set on your API keys for this call to work

Parameters
parameter required description
market required a string literal for the market (ex: BTC-LTC)
quantity required the amount to purchase
rate required the rate at which to place the order.
Request:
https://fiberchange.com/api/v1/market/buylimit?apikey=API_KEY&nonce=NONCE&market=FBC-LTC&quantity=1.2&rate=1.3
Response - Returns you the order uuid:
    {
	"success" : true,
	"message" : "",
	"result" : {
		"uuid" : "e606d53c-8d70-11e3-94b5-425861b86ab6"
	}
    }                        
                    
'use strict';

const API_PUB_KEY = "__YOUR_API_PUBLIC_KEY__";
const API_PRIV_KEY = "__YOUR_API_PRIVATE_KEY__";

BuyLimit('FBC-BTC', 0.00001, 1135000, data => { console.log(JSON.stringify(data.result || data)); });

function BuyLimit(market, quantity, rate, callback)
{
    const nonce = Date.now()+Math.floor(Math.random() * (1000)) + 1;
    const uri = 'https://fiberchange.com/api/v1/market/buylimit?apikey='+API_PUB_KEY+'&nonce='+nonce+'&market='+market+'&quantity='+quantity+'&rate='+rate;
    const parsed = require('url').parse(uri, true);
    const signature = require('crypto').createHmac('sha512', API_PRIV_KEY).update(new Buffer(uri, 'utf-8')).digest('hex');
    
    const options = {
        host: parsed.host,
        path: parsed.path,
        headers: { 'apisign': signature }
    };
    
    require("https").request(options, res => {
        let output = '';
        res.on('data', chunk => { output += chunk; });
        res.on('end', () => { return callback(JSON.parse(output)); });
    }).end();
    
}
                


/market/selllimit

Used to place an sell order in a specific market. Use selllimit to place limit orders. Make sure you have the proper permissions set on your API keys for this call to work

Parameters
parameter required description
market required a string literal for the market (ex: BTC-LTC)
quantity required the amount to purchase
rate required the rate at which to place the order.
Request:
https://fiberchange.com/api/v1/market/selllimit?apikey=API_KEY&nonce=NONCE&market=FBC-LTC&quantity=1.2&rate=1.3
Response - Returns you the order uuid:
    {
	"success" : true,
	"message" : "",
	"result" : {
		"uuid" : "614c34e4-8d71-11e3-94b5-425861b86ab6"
	}
    }                        
                    
'use strict';

const API_PUB_KEY = "__YOUR_API_PUBLIC_KEY__";
const API_PRIV_KEY = "__YOUR_API_PRIVATE_KEY__";

SellLimit('FBC-BTC', 0.00001, 11350000, data => { console.log(JSON.stringify(data.result || data)); });

function SellLimit(market, quantity, rate, callback)
{
    const nonce = Date.now()+Math.floor(Math.random() * (1000)) + 1;
    const uri = 'https://fiberchange.com/api/v1/market/selllimit?apikey='+API_PUB_KEY+'&nonce='+nonce+'&market='+market+'&quantity='+quantity+'&rate='+rate;
    const parsed = require('url').parse(uri, true);
    const signature = require('crypto').createHmac('sha512', API_PRIV_KEY).update(new Buffer(uri, 'utf-8')).digest('hex');
    
    const options = {
        host: parsed.host,
        path: parsed.path,
        headers: { 'apisign': signature }
    };
    
    require("https").request(options, res => {
        let output = '';
        res.on('data', chunk => { output += chunk; });
        res.on('end', () => { return callback(JSON.parse(output)); });
    }).end();
    
}
                


/market/cancel

Used to cancel a buy or sell order.

Parameters
parameter required description
uuid required uuid of buy or sell order
Request:
https://fiberchange.com/api/v1/market/cancel?apikey=API_KEY&nonce=NONCE&uuid=ORDER_UUID 
Response - Returns you the order uuid:
    {
        "success" : true,
        "message" : "",
        "result" : null
    }
                    
'use strict';

const API_PUB_KEY = "__YOUR_API_PUBLIC_KEY__";
const API_PRIV_KEY = "__YOUR_API_PRIVATE_KEY__";

CancelOrder("1530078445865-2-0.6676880290983116", data => { console.log(JSON.stringify(data.result || data)); });

function CancelOrder(uuid, callback)
{
    const nonce = Date.now()+Math.floor(Math.random() * (1000)) + 1;
    const uri = 'https://fiberchange.com/api/v1/market/cancel?apikey='+API_PUB_KEY+'&nonce='+nonce+'&uuid='+uuid;
    const parsed = require('url').parse(uri, true);
    const signature = require('crypto').createHmac('sha512', API_PRIV_KEY).update(new Buffer(uri, 'utf-8')).digest('hex');
    
    const options = {
        host: parsed.host,
        path: parsed.path,
        headers: { 'apisign': signature }
    };
    
    require("https").request(options, res => {
        let output = '';
        res.on('data', chunk => { output += chunk; });
        res.on('end', () => { return callback(JSON.parse(output)); });
    }).end();
    
}
                


/market/getopenorders

Get all orders that you currently have opened.

Parameters
parameter required description
market required a string literal for the market (ie. FBC-LTC)
Request:
https://fiberchange.com/api/v1/market/getopenorders?apikey=API_KEY&nonce=NONCE&market=FBC-LTC  
Response - Returns you the order uuid:
    {
	"success" : true,
	"message" : "",
	"result" : [{
			"OrderUuid" : "09aa5bb6-8232-41aa-9b78-a5a1093e0211",
			"Exchange" : "FBC-LTC",
			"QuantityRemaining" : 5.00000000,
			"Price" : 2.00000000,
			"Opened" : "2018-01-01T03:55:48.77",
		}, {
			"OrderUuid" : "8925d746-bc9f-4684-b1aa-e507467aaa99",
			"Exchange" : "FBC-LTC",
			"QuantityRemaining" : 100000.00000000,
			"Price" : 0.00000001,
			"Opened" : "2018-01-01T03:55:48.583",
		}
	]
    }
                        
                    
'use strict';

const API_PUB_KEY = "__YOUR_API_PUBLIC_KEY__";
const API_PRIV_KEY = "__YOUR_API_PRIVATE_KEY__";

GetOpenOrders('FBC-BTC', data => { console.log(JSON.stringify(data.result || data)); });

function GetOpenOrders(market, callback)
{
    const nonce = Date.now()+Math.floor(Math.random() * (1000)) + 1;
    const uri = 'https://fiberchange.com/api/v1/market/getopenorders?apikey='+API_PUB_KEY+'&nonce='+nonce+'&market='+market;
    const parsed = require('url').parse(uri, true);
    const signature = require('crypto').createHmac('sha512', API_PRIV_KEY).update(new Buffer(uri, 'utf-8')).digest('hex');
    
    const options = {
        host: parsed.host,
        path: parsed.path,
        headers: { 'apisign': signature }
    };
    
    require("https").request(options, res => {
        let output = '';
        res.on('data', chunk => { output += chunk; });
        res.on('end', () => { return callback(JSON.parse(output)); });
    }).end();
};
                



Account Api

/account/getbalance

Used to retrieve the balance from your account for a specific currency.

Parameters
parameter required description
currency required a string literal for the currency (ex: BTC)
Request:
https://fiberchange.com/api/v1/account/getbalance?apikey=API_KEY&nonce=NONCE&currency=BTC
Response:
    {
	"success" : true,
	"message" : "",
	"result" : {
		"Currency" : "MTXC",
		"Balance" : 4.21549076,
		"Available" : 4.21549076,
		"Pending" : 0.00000000
	}
    }                        
                    
'use strict';

const API_PUB_KEY = "__YOUR_API_PUBLIC_KEY__";
const API_PRIV_KEY = "__YOUR_API_PRIVATE_KEY__";

GetBalance('FBC', data => { console.log(JSON.stringify(data.result || data)); });


function GetBalance(currency, callback)
{
    const nonce = Date.now()+Math.floor(Math.random() * (1000)) + 1;
    const uri = 'https://fiberchange.com/api/v1/account/getbalance?apikey='+API_PUB_KEY+'&nonce='+nonce+'&currency='+currency;
    const parsed = require('url').parse(uri, true);
    const signature = require('crypto').createHmac('sha512', API_PRIV_KEY).update(new Buffer(uri, 'utf-8')).digest('hex');
    
    const options = {
        host: parsed.host,
        path: parsed.path,
        headers: { 'apisign': signature }
    };
    
    require("https").request(options, res => {
        let output = '';
        res.on('data', chunk => { output += chunk; });
        res.on('end', () => { return callback(JSON.parse(output)); });
    }).end();
};
                


/account/getdepositaddress

Used to retrieve or generate an address for a specific currency.

Parameters
parameter required description
currency required a string literal for the currency (ie. BTC)
Request:
https://fiberchange.com/api/v1/account/getdepositaddress?apikey=API_KEY&nonce=NONCE&currency=LTC
Response:
    {
    	"success" : true,
    	"message" : "",
    	"result" : {
    		"Currency" : "MTXC",
    		"Address" : "1y5SKeKGXUHKS2WVpJ76HYuKAu3URastUo"
    	}
    }
                    
/account/getorder

Used to retrieve a single order by uuid.

Parameters
parameter required description
uuid required the uuid of the buy or sell order
Request:
https://fiberchange.com/api/v1/account/getorder?apikey=API_KEY&nonce=NONCE&uuid=ORDER_UUID
Response:
    {
    	"success" : true,
    	"message" : "",
    	"result" : {
    		"OrderUuid" : "0cb4c4e4-bdc7-4e13-8c13-430e587d2cc1",
    		"Exchange" : "FBC-BTC",
    		"QuantityRemaining" : 1000.00000000,
    		"Price" : 0.00000001,
    		"Opened" : "2018-01-01T07:45:46.27",
    		"IsOpen" : true
    	}
    }
                    
'use strict';

const API_PUB_KEY = "__YOUR_API_PUBLIC_KEY__";
const API_PRIV_KEY = "__YOUR_API_PRIVATE_KEY__";

GetOrder("1530077938662-2-0.04123927384759796", data => { console.log(JSON.stringify(data.result || data)); });

function GetOrder(uuid, callback)
{
    const nonce = Date.now()+Math.floor(Math.random() * (1000)) + 1;
    const uri = 'https://fiberchange.com/api/v1/account/getorder?apikey='+API_PUB_KEY+'&nonce='+nonce+'&uuid='+uuid;
    const parsed = require('url').parse(uri, true);
    const signature = require('crypto').createHmac('sha512', API_PRIV_KEY).update(new Buffer(uri, 'utf-8')).digest('hex');
    
    const options = {
        host: parsed.host,
        path: parsed.path,
        headers: { 'apisign': signature }
    };
    
    require("https").request(options, res => {
        let output = '';
        res.on('data', chunk => { output += chunk; });
        res.on('end', () => { return callback(JSON.parse(output)); });
    }).end();
    
}
                


/account/getorderhistory

Used to retrieve your order history.

Parameters
parameter required description
market required a string literal for the market (ie. FBC-LTC).
Request:
https://fiberchange.com/api/v1/account/getorderhistory?apikey=API_KEY&nonce=NONCE&market=FBC-LTC
Response:
    {
    	"success" : true,
    	"message" : "",
    	"result" : [{
    			"OrderUuid" : "fd97d393-e9b9-4dd1-9dbf-f288fc72a185",
    			"TimeStamp" : "2018-01-01T04:01:00.667",
    			"Price" : 0.00000001,
    			"QuantityRemaining" : 100000.00000000,
    		}, {
    			"OrderUuid" : "17fd64d1-f4bd-4fb6-adb9-42ec68b8697d",
    			"TimeStamp" : "2018-01-01T20:38:58.317",
    			"Price" : 0.00002950,
    			"QuantityRemaining" : 0.00000000,
    		}
    	]
    }
                    
/account/withdraw

Used to withdraw funds from your account.

Parameters
parameter required description
currency required a string literal for the market (ie. FBC-LTC).
quantity required the quantity of coins to withdraw
address required the address where to send the funds
Request:
https://fiberchange.com/api/v1/account/withdraw?apikey=API_KEY&nonce=NONCE&currency=FBC&quantity=20.40&address=FBC_ADDRESS
Response:
{
	"success" : true,
	"message" : "",
	"result" : {
			"uuid" : "68b5a16c-92de-11e3-ba3b-425861b86ab6"
	}
}
                    
'use strict';

const API_PUB_KEY = "__YOUR_API_PUBLIC_KEY__";
const API_PRIV_KEY = "__YOUR_API_PRIVATE_KEY__";

Withdraw('FBC', 5, 'MVe3eoMq7TeGMzPw9EpXGpKQzW2aMvJNAa', data => { console.log(JSON.stringify(data.result || data)); });

function Withdraw(currency, quantity, address, callback) {
    const nonce = Date.now()+Math.floor(Math.random() * (1000)) + 1;
    const uri = 'https://fiberchange.com/api/v1/account/withdraw?apikey='+API_PUB_KEY+'&nonce='+nonce+'¤cy='+currency+'&quantity='+quantity+'&address='+address;
    const parsed = require('url').parse(uri, true);
    const signature = require('crypto').createHmac('sha512', API_PRIV_KEY).update(new Buffer(uri, 'utf-8')).digest('hex');
    
    const options = {
        host: parsed.host,
        path: parsed.path,
        headers: { 'apisign': signature }};
    
    require("https").request(options, res => {
        let output = '';
        res.on('data', chunk => { output += chunk; });
        res.on('end', () => { return callback(JSON.parse(output)); }); }).end();
}
                


/account/createcoupon

This method allows you to create Coupons.

Parameters
parameter required description
currency required a string literal for the market (ie. FBC-LTC).
quantity required the quantity of coins to withdraw
Request:
https://fiberchange.com/api/v1/account/createcoupon?apikey=API_KEY&nonce=NONCE&currency=FBC&quantity=20.40
Response:
{
    "result": true, 
    "success":1,
    "return":{
        "coupon":"OT-2-1-0.01-1532875173145-f4f1b216f09507d6d987bhvgfbfc85ef36d0ba236e0983gslkjn196dafa9648",
        "funds":{"FBC":430.4460447}
    }
}                    
                    
'use strict';

const API_PUB_KEY = "__YOUR_API_PUBLIC_KEY__";
const API_PRIV_KEY = "__YOUR_API_PRIVATE_KEY__";

Create('FBC', 0.01, ret => {console.log(JSON.stringify(ret))});

function Create(currency, quantity, callback) {
    const nonce = Date.now()+Math.floor(Math.random() * (1000)) + 1;
    const uri = 'https://fiberchange.com/api/v1/account/createcoupon?apikey='+API_PUB_KEY+'&nonce='+nonce+'¤cy='+currency+'&quantity='+quantity;
    const parsed = require('url').parse(uri, true);
    const signature = require('crypto').createHmac('sha512', API_PRIV_KEY).update(new Buffer(uri, 'utf-8')).digest('hex');
    
    const options = {
        host: parsed.host,
        path: parsed.path,
        headers: { 'apisign': signature }};
    
    require("https").request(options, res => {
        let output = '';
        res.on('data', chunk => { output += chunk; });
        res.on('end', () => { return callback(JSON.parse(output)); });
    }).end();
}

                


/account/redeemcoupon

This method is used to redeem coupons.

Parameters
parameter required description
coupon required a string literal for coupon
Request:
https://fiberchange.com/api/v1/account/redeemcoupon?apikey=API_KEY&nonce=NONCE&coupon=OT-2-1-0.01-1532875173145-f4f1b216f09507bsld587ygsek7fc88903tydfsjk36e7c8633196dafa9648
Response:
{
    "result":true,
    "success":1,
    "return": {
        "couponAmount":"1",
        "couponCurrency":"FBC",
        "funds":{"FBC":431.9670079}
    }
}                    
                    
'use strict';

const API_PUB_KEY = "__YOUR_API_PUBLIC_KEY__";
const API_PRIV_KEY = "__YOUR_API_PRIVATE_KEY__";

Close("OT-2-1-0.01-1532875173145-f4f1b216f09507bsld587ygsek7fc88903tydfsjk36e7c8633196dafa9648", ret => { console.log(JSON.stringify(ret));}

function Close(coupon, callback) {
    const nonce = Date.now()+Math.floor(Math.random() * (1000)) + 1;
    const uri = 'https://fiberchange.com/api/v1/account/redeemcoupon?apikey='+API_PUB_KEY+'&nonce='+nonce+'&coupon='+coupon;
    const parsed = require('url').parse(uri, true);
    const signature = require('crypto').createHmac('sha512', API_PRIV_KEY).update(new Buffer(uri, 'utf-8')).digest('hex');
    
    const options = {
        host: parsed.host,
        path: parsed.path,
        headers: { 'apisign': signature }};
    
    require("https").request(options, res => {
        let output = '';
        res.on('data', chunk => { output += chunk; });
        res.on('end', () => { return callback(JSON.parse(output)); });
    }).end();
}