NAV Navbar
ruby python
  • API
  • Authentication
  • Private
  • Public
  • API

    Welcome to the CoinFalcon API documentation.

    Here you will find everything you need to working with the CoinFalcon API. To get started, go to your applications page in your account settings to generate your key and secret.

    Status codes

    Status code Reason
    200 Successful response
    400 Bad Request – Invalid request format
    401 Unauthorized – Authentication error
    403 Forbidden – You do not have access to the requested resource
    404 Not Found
    429 Too Many Requests
    500 Internal Server Error – We had a problem with our server

    Limits

    When a rate limit is exceeded, a status of 429 API rate limit exceeded for IP will be returned.

    PUBLIC ENDPOINTS

    We throttle public endpoints by IP: 3 requests per second.

    PRIVATE ENDPOINTS

    We throttle private endpoints by user ID: 3 requests per second.

    Authentication

    Headers

    All REST requests must contain the following headers:

    CF-API-KEY The api key as a string.

    CF-API-TIMESTAMP A timestamp for your request, 10 digital.

    CF-API-SIGNATURE The signature for your request (see Signing a Message).

    All request bodies should have content type application/json and be valid JSON.

    Signing a message

    To generate a signature, use this code, the get_signature method:

    require 'awesome_print'
    require 'rest-client'
    require 'json'
    require 'pry'
    
    class CoinfalconExchange
      def initialize(key, secret)
        @key = key
        @secret = secret
        @end_point = 'https://coinfalcon.com/api/v1/'
      end
    
      def headers(request_path, body, method)
        timestamp = Time.now.to_i
        signature = get_signature(timestamp, request_path, body, method)
        ap signature
        {
            "CF-API-KEY" => @key,
            "CF-API-TIMESTAMP" => timestamp,
            "CF-API-SIGNATURE" => signature
        }
      end
    
      def get_signature(timestamp, request_path='', body={}, method='GET')
        # Example for get
        # request_path = '/api/v1/user/orders'
        # timestamp = 1513411769
        # method = 'GET'
        # payload = '1513411769|GET|/api/v1/user/orders'
    
        # Example for post
        # request_path = '/api/v1/user/orders'
        # timestamp = 1513411657
        # method = 'POST'
        # body {market: 'IOT-BTC', operation_type: 'market_order', order_type: 'buy', size: '1'}
        # payload = '1513411657|POST|/api/v1/user/orders|{"market":"IOT-BTC","operation_type":"market_order","order_type":"buy","size":"1"}'
    
        if method == 'GET'
          payload = [timestamp, method, request_path].join("|")
        else
          body = URI.unescape(body.to_json) if body.is_a?(Hash)
          payload = [timestamp, method, request_path, body].join("|")
        end
    
        puts payload
        # create a sha256 hmac with the secret
        OpenSSL::HMAC.hexdigest('sha256', @secret, payload)
      end
    
      def accounts
        url = @end_point + "user/accounts"
        result = RestClient.get(url, headers(URI(url).request_uri, {}, 'GET'))
        JSON.parse(result.body)
      end
    
      def orderbook(market)
        url = @end_point + "markets/#{market}/orders"
        JSON.parse(RestClient.get(url).body)
      end
    
      def my_orders
        url = @end_point + "user/orders"
        result = RestClient.get(url, headers(URI(url).request_uri, {}, 'GET'))
        JSON.parse(result.body)
      end
    
      def my_trades
    
      end
    
      def create_order(body)
        url = @end_point + "user/orders"
        result = RestClient.post(url, body,headers(URI(url).request_uri, body, 'POST'))
        JSON.parse(result.body)
      end
    
      def order(id)
        url = @end_point + "user/orders/#{id}"
        result = RestClient.get(url, headers(URI(url).request_uri, {}, 'GET'))
        JSON.parse(result.body)
      end
    
      def cancel_order(id)
        url = @end_point + "user/orders/#{id}"
        begin
          result = RestClient.delete(url, headers(URI(url).request_uri, {}, 'DELETE'))
          JSON.parse(result.body)
        rescue RestClient::ExceptionWithResponse => e
          JSON.parse(e.response.body)
        end
      end
    
      def deposit_address(currency)
        url = @end_point + "account/deposit_address?currency=#{currency}"
        result = RestClient.get(url, headers(URI(url).request_uri, {}, 'GET'))
        JSON.parse(result.body)
      end
    
      def deposits(query = {})
        url = @end_point + "account/deposits?#{URI.encode_www_form(query)}".chomp('?')
        result = RestClient.get(url, headers(URI(url).request_uri, {}, 'GET'))
        JSON.parse(result.body)
      end
    
      def deposit(id)
        url = @end_point + "account/deposit/#{id}"
        result = RestClient.get(url, headers(URI(url).request_uri, {}, 'GET'))
        JSON.parse(result.body)
      end
    
      def create_withdrawal(body)
        url = @end_point + "account/withdraw"
        result = RestClient.post(url, body,headers(URI(url).request_uri, body, 'POST'))
        JSON.parse(result.body)
      end
    
      def withdrawals(query = {})
        url = @end_point + "account/withdrawals?#{URI.encode_www_form(query)}".chomp('?')
        result = RestClient.get(url, headers(URI(url).request_uri, {}, 'GET'))
        JSON.parse(result.body)
      end
    
      def withdrawal(id)
        url = @end_point + "account/withdrawal?id=#{id}"
        result = RestClient.get(url, headers(URI(url).request_uri, {}, 'GET'))
        JSON.parse(result.body)
      end
    
      def cancel_withdrawal(id)
        url = @end_point + "account/withdrawals/#{id}"
        result = RestClient.delete(url, headers(URI(url).request_uri, {}, 'DELETE'))
        JSON.parse(result.body)
      end
    
    end
    
    #staging
    #client = CoinfalconExchange.new('70b23c92-51df-413d-8d2d-73504d85e2df', '0b63546f-983e-48ac-bed7-10e4d4a0dfed')
    
    #development
    client = CoinfalconExchange.new('3b47b2f1-059f-4091-8cd6-50c7d7a3413d', 'cbac30d1-f014-4758-8250-699659f13772')
    
    # ap client.orderbook('IOT-BTC')
    # ap client.my_orders
    # ap client.accounts
    #result = client.create_order({market: 'BTC-EUR', operation_type: 'market_order', order_type: 'sell', size: '0.01'})
    #ap result
    #ap client.order(result['data']['id'])
    #ap client.cancel_order(result['data']['id'])
    # ap client.deposit_address('btc')
    #result = client.create_withdrawal({amount: '0.001', address: 'mszGuGEdvkRsnFaTymW9LHiMan1qcPH4wn', currency: 'btc'})
    # ap client.withdrawal('9b25877a-35ae-4812-8d89-953ed4c55094')
    # ap client.withdrawals(currency: 'btc', status: 'completed')
    #ap result
    #ap client.cancel_withdrawal(result['data']['id'])
    # ap client.deposits(currency: 'btc', status: 'completed')
    # ap client.deposit('e30a3ac8-33b1-46ed-8f54-1112417de581')
    
    # -*- coding: utf-8 -*-
    
    import hashlib
    import requests
    import urllib
    import urllib.parse
    import json
    import hmac
    import time
    
    class Coinfalcon():
    
        def __init__(self, key, secret):
            self.key = key
            self.secret = secret
            #self.endpoint = 'https://coinfalcon.com/api/v1'
            self.endpoint = 'http://localhost:3000/api/v1'
    
        def request_path(self, url):
            query = urllib.parse.urlparse(url).query
            if query == '':
                return urllib.parse.urlparse(url).path
            return urllib.parse.urlparse(url).path + '?' + query
    
        def get_headers(self, method, request_path, body={}):
            timestamp = str(int(time.time()))
    
            if method == 'GET':
                payload = '|'.join([timestamp, method, request_path])
            else:
                payload = '|'.join([timestamp, method, request_path, json.dumps(body, separators=(',', ':'))])
    
            print(payload)
            message = bytes(payload, 'utf-8')
            secret = bytes(self.secret, 'utf-8')
    
            signature = hmac.new(secret, message, hashlib.sha256).hexdigest()
            return {
                "CF-API-KEY": self.key,
                "CF-API-TIMESTAMP": timestamp,
                "CF-API-SIGNATURE": signature
            }
    
        def create_order(self, body):
            url = self.endpoint + "/user/orders"
            headers = self.get_headers('POST', urllib.parse.urlparse(url).path, body)
            return requests.post(url, headers=headers, data=body).json()
    
        def cancel_order(self, id):
            url = self.endpoint + "/user/orders/{}".format(id)
            print(url)
            headers = self.get_headers('DELETE', urllib.parse.urlparse(url).path, {})
            return requests.delete(url, headers=headers).json()
    
        def my_orders(self):
            url = self.endpoint + "/user/orders"
            headers = self.get_headers('GET', urllib.parse.urlparse(url).path)
            return requests.get(url, headers=headers).json()
    
        def deposit_address(self, currency):
            url = self.endpoint + "/account/deposit_address?currency={}".format(currency)
            headers = self.get_headers('GET', self.request_path(url))
            return requests.get(url, headers=headers).json()
    
        def orderbook(self, market):
            url = self.endpoint + "/markets/{}/orders".format(market)
            print(url)
            print(requests.get(url).text)
            return requests.get(url).json()
    
    #need use your own key && secret
    client = Coinfalcon('3b47b2f1-059f-4091-8cd6-50c7d7a3413d', 'cbac30d1-f014-4758-8250-699659f13772')
    #print(client.orderbook('IOT-BTC'))
    #print(client.my_orders())
    #result = client.create_order({'market': 'BTC-EUR', 'operation_type': 'market_order', 'order_type': 'sell', 'size': '0.1'})
    #print(result)
    #print(client.cancel_order(result['data']['id']))
    print(client.deposit_address('btc'))
    

    The CF-API-SIGNATURE header is generated by creating a sha256 HMAC using the secret key on the prehash string. If get, use timestamp|method|requestPath. If post, use timestamp|method|requestPath|body.to_json.

    Private

    Accounts

    The above command returns JSON structured like this:

    {
        "data": [
            {
                "currency": "IOT",
                "balance": "0.0",
                "available": "0.0",
                "hold": "0.0"
            },
            {
                "currency": "BTG",
                "balance": "0.0",
                "available": "0.0",
                "hold": "0.0"
            },
            {
                "currency": "LTC",
                "balance": "0.0",
                "available": "0.0",
                "hold": "0.0"
            }
        ]
    }
    
    

    Get a list of your trading accounts.

    HTTP Request

    GET https://coinfalcon.com/api/v1/user/accounts

    FUNDS ON HOLD

    When you place an order, the funds for the order are placed on hold. They cannot be used for other orders or withdrawn. Funds will remain on hold until the order is filled or canceled.

    Create order

    The above command returns JSON structured like this:

    {
        "data": {
            "id": "4cc9835d-3aad-4e3b-aa76-538e6f18247a",
            "market": "ETH-BTC",
            "price": "0.03993",
            "size": "1.0",
            "size_filled": "0.0",
            "status": "pending",
            "order_type": "buy",
            "operation_type": "limit_order",
            "created_at": "2017-11-03T08:46:14.354945Z"
        }
    }
    

    You can place different types of orders: limit, market. Orders can only be placed if your account has sufficient funds. Once an order is placed, your account funds will be put on hold for the duration of the order. How much and which funds are put on hold depends on the order type and parameters specified.

    HTTP Request

    POST https://coinfalcon.com/api/v1/user/orders

    Query Parameters

    Parameter Default Description
    market required Create order for specific market e.g. BTC-EUR
    operation_type required market_order or limit_order
    order_type required buy or sell left currency of market
    size required Set the size of the order
    price optional Set the price for limit_order

    Cancel order

    The above command returns JSON structured like this:

    {
        "data": {
                        "id": "a7ed361d-bf39-4b70-a456-e18eadc1b494",
                    "market": "BTC-EUR",
                     "price": "7263.0",
                      "size": "0.01",
               "size_filled": "0.0",
                    "status": "canceled",
                "order_type": "sell",
            "operation_type": "market_order",
                "created_at": "2018-02-04T05:07:59.801504Z"
        }
    }
    

    Cancel a previously placed order.

    HTTP Request

    DELETE https://coinfalcon.com/api/v1/user/orders/:id

    Path Parameters

    Parameter Default Description
    id required Order id

    List orders

    The above command returns JSON structured like this:

    {
        "data": [
            {
                "id": "a7ed361d-bf39-4b70-a456-e18eadc1b494",
                "market_name": "BTC-EUR",
                "price": "6420.0",
                "size": "0.1",
                "size_filled": "0.1",
                "status": "fulfilled",
                "order_type": "buy",
                "operation_type": "market_order",
                "created_at": "2017-11-06T09:54:42.723945Z"
            },
            {
                "id": "de45bc37-7440-40a3-b5ba-a08dc463e387",
                "market_name": "BTC-EUR",
                "price": "6419.0",
                "size": "0.1",
                "size_filled": "0.1",
                "status": "fulfilled",
                "order_type": "buy",
                "operation_type": "market_order",
                "created_at": "2017-11-06T09:53:08.383210Z"
            }
        ]
    }
    

    List your current open orders. Only open or un-settled orders are returned. As soon as an order is no longer open and settled, it will no longer appear in the default request.

    HTTP Request

    GET https://coinfalcon.com/api/v1/user/orders

    Query Parameters

    Parameter Default Description
    market optional Get only orders from specific market e.g. BTC-EUR
    status [pending, open, partially_filled] Use all to get all types of statuses
    since_time optional Returns orders since the given datetime
    start_time optional Returns orders beginning with the given datetime
    end_time optional Returns orders ending with the given datetime

    List trades

    The above command returns JSON structured like this:

    {
        "data": [
            {
                "price": "6420.0",
                "size": "0.1",
                "created_at": "2017-11-06T09:54:42.789639Z"
            },
            {
                "price": "6419.0",
                "size": "0.1",
                "created_at": "2017-11-06T09:53:08.881138Z"
            }
        ]
    }
    

    Get a list of recent trades.

    HTTP Request

    GET https://coinfalcon.com/api/v1/user/trades

    Query Parameters

    Parameter Default Description
    since_time optional Returns orders since the given datetime
    start_time optional Returns orders beginning with the given datetime
    end_time optional Returns orders ending with the given datetime

    Get Deposit Address

    The above command returns JSON structured like this:

    {
        "data": {
            "address": "2MttMDBh8Qj6EL8Pv6eF6CeaEUzgiaQeoYQ"
        }
    }
    

    Get deposit address for currency

    HTTP Request

    GET https://coinfalcon.com/api/v1/account/deposit_address

    Query Parameters

    Parameter Default Description
    currency required currency code e.g. BTC

    Get Deposit History

    The above command returns JSON structured like this:

    {
        "data": [
            {
                           "id": "030c7377-32e5-4078-a1ca-18322250bfd5",
                       "amount": "0.01",
                       "status": "completed",
                "currency_code": "btc",
                         "txid": "3caa72cc139505f7e20f17f825c323c6e5888553098df2efe296362d79b7dcd8"
            },
            {
                           "id": "2ee9a009-4c3c-4942-a73b-bbe893199beb",
                       "amount": "0.01",
                       "status": "completed",
                "currency_code": "btc",
                         "txid": "6f230aa0493b46d54ab82125ff50ff77bde419c0986660dc175060e367ca0a5a"
            }
        ]
    }
    

    Get deposit history

    HTTP Request

    GET https://coinfalcon.com/api/v1/account/deposits

    Query Parameters

    Parameter Default Description
    currency optional currency code e.g. BTC
    status optional [pending, completed]
    since_time optional Returns deposits since the given datetime
    start_time optional Returns deposits beginning with the given datetime
    end_time optional Returns deposits ending with the given datetime

    Get Deposit Detail

    The above command returns JSON structured like this:

    {
        "data": {
                       "id": "e30a3ac8-33b1-46ed-8f54-1112417de581",
                   "amount": "0.01",
                   "status": "completed",
            "currency_code": "btc",
                     "txid": "782c9be82488e791a93facf7dff2809a8e32e8ec02ee723f0da7d4f72558d82e"
        }
    }
    

    Get Deposit Detail

    HTTP Request

    GET https://coinfalcon.com/api/v1/account/deposit

    Path Parameters

    Parameter Default Description
    id required deposit id

    Create withdrawal

    The above command returns JSON structured like this:

    {
        "data": {
                       "id": "641e12db-699e-410e-8b3d-6fff4669119c",
                   "amount": "0.001",
                   "status": "pending",
                      "fee": "0.000441",
            "currency_code": "btc",
                     "txid": "nil"
        }
    }
    

    when create withdrawal through api, won't require 2fa code and email confirmation.

    HTTP Request

    POST https://coinfalcon.com/api/v1/account/withdraw

    Query Parameters

    Parameter Default Description
    currency required currency code like btc
    address required withdraw address
    amount required withdraw amount

    Get Withdrawal Detail

    The above command returns JSON structured like this:

    {
        "data": {
                       "id": "9b25877a-35ae-4812-8d89-953ed4c55094",
                   "amount": "0.01",
                   "status": "completed",
                      "fee": "0.00000662",
            "currency_code": "btc",
                     "txid": "af88900ee9b99b468bf3159be757d6d1be6ef4c2e0fb993e80acb8a2b733742d"
        }
    }
    

    Get Withdrawal Detail

    HTTP Request

    GET https://coinfalcon.com/api/v1/account/withdrawal

    Query Parameters

    Parameter Default Description
    id required withdrawal id

    Get Withdrawal History

    The above command returns JSON structured like this:

    {
        "data": [
            {
                           "id": "4f408bea-abf0-46f7-9ae3-c19edbbd38e9",
                       "amount": "1.0",
                       "status": "completed",
                          "fee": "0.000441",
                "currency_code": "btc",
                         "txid": "15d0ea80886ed8518373475bd621db5a04d05645bad13bf785b3032830cdb5f5"
            },
            {
                           "id": "7db1dd7e-bcdd-4b6d-b31c-3699d1ef4a95",
                       "amount": "0.01",
                       "status": "completed",
                          "fee": "0.000441",
                "currency_code": "btc",
                         "txid": "5c569352ae4d55c5f31a4087329bf4e38d57129f8522dd0e6ecccda355bbd570"
            }
        ]
    }
    

    Get withdrawal history

    HTTP Request

    GET https://coinfalcon.com/api/v1/account/withdrawals

    Query Parameters

    Parameter Default Description
    currency optional currency code e.g. BTC
    status optional [pending, completed]
    since_time optional Returns deposits since the given datetime
    start_time optional Returns deposits beginning with the given datetime
    end_time optional Returns deposits ending with the given datetime

    Cancel withdrawal

    The above command returns JSON structured like this:

    {
        "data": {
                       "id": "8b591a8a-6c4f-4ab6-bef4-f156c0311346",
                   "amount": "0.001",
                   "status": "canceled",
                      "fee": "0.000441",
            "currency_code": "btc",
                     "txid": nil
        }
    }
    

    Cancel a previously placed withdrawal.

    HTTP Request

    DELETE https://coinfalcon.com/api/v1/account/withdrawals/:id

    Path Parameters

    Parameter Default Description
    id required withdrawal id

    Public

    List trades

    The above command returns JSON structured like this:

    {
        "data": [
            {
                "price": "6226.08",
                "size": "0.09958032",
                "market_name": "BTC-EUR",
                "created_at": "2017-11-15T10:10:03.042605Z"
            },
            {
                "price": "6226.09",
                "size": "0.00041968",
                "market_name": "BTC-EUR",
                "created_at": "2017-11-15T10:09:59.949840Z"
            }
        ]
    }
    

    List the latest trades for a market.

    HTTP Request

    GET https://coinfalcon.com/api/v1/markets/:market/trades

    Query Parameters

    Parameter Default Description
    market required Get only orders from specific market e.g. BTC-EUR
    since_time optional Returns orders since the given datetime
    start_time optional Returns orders beginning with the given datetime
    end_time optional Returns orders ending with the given datetime

    List orderbook

    The above command returns JSON structured like this:

    {
        "data": {
            "bids": [
                {
                    "price": "6225.0",
                    "size": "0.01"
                },
                {
                    "price": "6220.14",
                    "size": "1.31"
                }
            ],
            "asks": [
                {
                    "price": "6400.0",
                    "size": "0.38493686"
                },
                {
                    "price": "6400.07",
                    "size": "0.0303693"
                }
            ]
        }
    }
    

    Get a list of open orders for a market. The amount of detail shown can be customized with the level parameter.

    HTTP Request

    GET https://coinfalcon.com/api/v1/markets/:market/orders

    Query Parameters

    Parameter Default Description
    market required Get only orders from specific market e.g. BTC-EUR
    level 1 Defines the level of the request

    Level Parameter

    Level Description
    1 Only the best bid and ask
    2 Top 50 bids and asks (aggregated)
    3 Full order book (non aggregated)