Bitfinex api c example


Welcome to the CoinAPI developer documentation. This document should contain all the information required to properly implement applications using our API. If possible then we are strongly recommending using our tested libraries available on GitHub, rather than creating new ones.

However, if you decide to create your own implementation or to change existing one, then we encourage you to create Pull Request to our main repository with proposed changes, then we will able to include your code in our official repository for use by bitfinex api c example users, effectively creating collaboration.

Bitfinex api c example in CoinAPI is not optional. All communication to us is always encrypted using protocols that are considered best security practices.

ISO currency code standard is used for fiat money identifications. Cryptocurrency assets are identified using codes used by the general public or adopted by the majority of exchanges.

Numbers in our platform can have maximum 19 digits overall, but no more than 9 decimal places. In cases when number representing aggregate value then we allowing 38 digits overall, but still no more than 9 decimal places. Production endpoint, requires API key for authentication and providing real data: You can authorize by providing an additional parameter named apikey with a value equal to your API key in the query string of your HTTP request.

This will indicate to us that we can deliver compressed data to you which on your side should be decompressed transparently.

Successful HTTP responses have the status code and the body in a format according to documentation of the requested resource.

All HTTP requests with response status codes different to must be considered as failed and you should expect additional JSON inside the body bitfinex api c example the response with the error message encapsulated inside it as shown in the example.

We use the following error codes:. Each data point of this timeseries represents several indicators calculated from transactions activity inside a time range period. This section describes calls related to executed transactions data, also known as matched orders data or active data. If exchange has not reported who was aggressor side of transaction, we will classify who most probably was based on current market view. To get current last trade for all symbols, use Quotes current data as it includes last trade information.

Get latest trades from all symbols up to 1 minute ago or get latest trades from a specific symbol without time limitation.

Latest data is always returned in time descending order. This section describes calls related to quotes data, bitfinex api c example known as quotes or passive level 1 data. Get latest quote updates up to 1 minute ago or get updates for a specific symbol without bitfinex api c example limit. This section describes calls related to order book data, also known as books or passive level 2 data. Get historical order book snapshots for a specific symbol within time range, returned in time ascending order.

WebSocket endpoint provides real-time market data streaming which works in Subscribe-Publish communication model.

After establishing a WebSocket connection with us, you will need to send a Hello message in accordance with this documentation. If everything is correct, we will provide you with a continuous stream of real-time market data updates.

Another example of a hello message for subscription of all data types from all exchanges and symbols:.

If your message will be incorrect, we will send you error message and disconnect connection afterwards. Hello message can be repeated, each one will cause subscription scope override without interruption of your WebSocket connection. You need to be prepared to receive an error message from us when you send something wrong; all errors are permanent and you should expect that the underlying WebSocket bitfinex api c example will be closed by us after sending an error message.

If exchange has not reported who the aggressor side of the transaction was, then we will classify who it most probably was based bitfinex api c example current market view. A Book message is sent for each snapshot or update of the order book.

After subscription to bitfinex api c example data type is initialized, we immediately start delivering updates to the order book and at least one snapshot will be provided as soon as possible with the nearest update of the book. Heartbeat message is sent to you every time there is one second of silence in communication between us, if you agreed on this feature in Hello message.

Financial Information eXchange FIX protocol is an electronic communications protocol initiated in for international real-time exchange of information related to the securities transactions and markets.

If your FIX protocol implementation does not support establishing a connection over a secure channel, you must use a proxy between your client and our FIX gateway to unbundle encryption. After successful authorization, server will respond with same message type and start delivering market data messages to you. Message sent by any side to close established session.

If received, should be sent back unchanged to confirm session termination. If exchange has not reported who the aggressor side of the transaction was, we will classify who it most probably was based on current market view. There are 3 main interfaces that can be used to access CoinAPI: In repository you can find libraries or examples for languages or enviroments like: Asset codes ISO currency code standard is used for fiat money identifications.

Numbers precision Numbers in our platform can have maximum 19 digits overall, but no more than 9 decimal places. Time For all input and output time values ISO standard is used. Format specifier Description yyyy The year as a four-digit number.

MM The month, from 01 through HH The hour, using a hour clock from 00 to Input time values are bitfinex api c example using the following formats as far as possible: Endpoints Production endpoint, requires API key for authentication and providing real data: There are 2 methods for passing the API key to us, you only need to use one: We use the following error codes: X-RateLimit-Remaining int The number of requests bitfinex api c example for the time window.

Bitfinex api c example of the ISO currency codes standard. List all symbols curl https: List all periods curl https: Latest data curl https: Current data curl https: Endpoint Production endpoint, requires API key for authentication and providing real data: Stream preferences Heartbeat and subscription details API key for authorization If your message will be incorrect, we will send you error message and disconnect connection afterwards.

Data type Description trade Executed transactions feed order book matches quote Quote updates feed order book level 1 book Order book snapshots and updates feed order book level 2, full order book snapshot and real-time updates book5 Order book snapshots feed order book level 2, 5 best levels from each side of book book20 Order book snapshots feed order book level 2, 20 best levels from each side of book book50 Order book snapshots feed order book level 2, 50 best levels from each side of book Error handling Example JSON error message is structured like this: Bitfinex api c example true then all bid and ask levels are listed, otherwise only changed since the last message.

FIX API General Financial Information eXchange FIX protocol is an electronic communications protocol initiated bitfinex api c example for international real-time exchange of information related to the securities transactions and markets. Endpoint FIX client configuration file: Parameter Value Hostname fix. Always the last field in a message, i. Stateful API providing streaming of realtime market data, widely adopted by the finance industry.

Output data format optional, default value is jsonpossible values are jsonxml or csv. Ignore header line in CSV output? Encapsulate strings with quotes in CSV output? Comma delimited list of column names to ignore in CSV output optional, by default all columns are included. Character that will be used as column delimiter in CSV output optional, default value is.

Character that will be used as decimal separator in CSV output optional, default value is. New line type optional, default value is unixpossible values winmacbitfinex api c example. Boolean value; true for cryptocurrency assets, false otherwise.

Comma or semicolon delimited parts of symbol identifier used to filter response. Type of symbol possible values are: FX Spot derivative contract where traders agree to trade right to require buy or sell of fx spot at agreed price on exercise date.

Boolean value representing option type. Requested exchange rate base asset identifier. Full list available here. Requested exchange rate quote asset identifier. Time at which exchange rate is calculated optional, if not supplied then current rate is returned.

Requested exchange rates base asset identifier. Symbol identifier of requested timeseries full list available here. Identifier of requested bitfinex api c example period required, e. Include items with no activity? Amount of items to return optional, mininum is 1, maximum isdefault value isif the parameter is used then every output items are counted as one request.

Timeseries ending time in ISO optional, if not supplied then the data is returned to the end or when count of result elements reaches the limit.

Symbol identifier for requested timeseries full list available here. Timeseries ending time in ISO optional, if not supplied then the data is returned bitfinex api c example the end or when result elements count reaches the limit. Timeseries ending time in ISO optional, if not supplied then the data is returned to the end or when result elements reaches count the limit. List of data types bitfinex api c example want to receive required, possible values listed in table below.

Filter data to symbols whose identifiers match at least one of the listed prefixes optional, if not provided then stream will not filtered by symbols. Filter data to symbols which are related to the at least one of the listed asset identifiers optional, if not provided then stream will not be filtered by assets. Order book snapshots and updates feed order book level 2, full order book snapshot and real-time updates.

The API is hosted at https: Please click here to inquire about getting access to it. Some API requests take longer to fetch bitfinex api c example others, so these cost more allowance.

Each client has an allowance of nanoseconds 8 seconds of CPU time per hour. The allowance is reset every hour on the hour. Each request returns information about your allowance in addition to the bitfinex api c example result: You can use this information, along with the current time, to have your application self-regulate its request rate. You can always request the root path https: Assets An asset can be a crypto or fiat currency. Index Returns all assets in no particular order.

Lists all markets which have this asset as a base or quote. Each pair has a base and a quote. Bitfinex api c example example, btceur has base btc and quote eur. Index Returns all pairs in no particular order. Lists all markets for this pair. Index Returns a list of all supported exchanges. For example, pair btceur on exchange kraken is a market. Index Returns a bitfinex api c example of all supported markets.

You can also get the supported markets for only a specific exchange. The result looks the same as bitfinex api c example. Param Description Format Example limit Limit amount of trades returned. Integer since Only return trades at or after this time.

UNIX timestamp Example: Returns data as lists of lists of numbers for each time period integer. Param Description Format Example before Only return candles opening before this time UNIX timestamp after Only return candles opening after this time UNIX timestamp periods Only return these time periods Comma-separated integers 60, All periods supported: Value Label 60 1m 3m 5m 15m 30m 1h 2h 4h 6h 12h 1d 3d 1w Example: The values are in this order: The open price for this candle is The volume for this candle was Aggregate Endpoints You can also retrieve the prices and summaries of all markets on the site in a single request.

These responses are cached and may be out of date by a few seconds. Markets are identified by a slugwhich is the exchange name and currency pair concatenated with a colon, like so: Some values may be out of date by a few seconds.

The most supported exchanges are as follows:. As Catalyst is currently in Alpha and in under active development, you are encouraged to throughly test any exchange in paper trading mode before trading live with it. Catalyst currently supports three different modes in which you can execute your trading algorithm. The first is backtestingwhich bitfinex api c example covered extensively in the tutorial, and uses historical bitfinex api c example to run your algorithm.

There is no interaction with the exchange in backtesting mode, and this is the first mode that you should test any new algorithm. Once you are confident with the simulations that you have obtained with your algorithm in backtesting, you may switch to live trading, where you have two different modes:. By convention, Catalyst uses an auth. This example illustrates the convention using the Bitfinex exchange.

Here is how to generate key and secret values for the Bitfinex bitfinex api c example Most exchanges follow a similar process. The file goes here: Attempting to run an algorithm where the targeted exchange is missing its auth.

Catalyst introduces a universal convention to reference trading pairs and individual currencies. This is required to ensure that the symbol api predictably returns the correct asset regardless of the targeted exchange.

Exchanges tend bitfinex api c example use their own convention to represent currencies e. Trading pairs are also inconsistent. For bitfinex api c example, Bitfinex puts the market currency before the base currency without a separator, Bittrex puts the base currency first and uses a dash seperator.

Note that the trading pairs are always referenced in the same manner. However, not all trading pairs are available on all exchanges. An error will occur if the specified trading pair is not trading on the exchange.

To check which currency pairs are available on each of the supported exchanges, see Catalyst Market Coverage. There is no special convention to follow when writing an algorithm for live trading. Bitfinex api c example same algorithm should work in backtest and live execution mode without modification. Here is the same example in both interfaces:. In live mode, bitfinex api c example call to handle data saves the state of the algorithm.

Any information bitfinex api c example to the context. During algorithm restart, the state is restored if exists in the initialization function. The catalyst live command offers additional parameters.

You can learn more by running the following from the command line:. Here is a complete algorithm for reference: Buy Low and Sell High. The most supported exchanges are as follows: The exchanges available for backtesting are fully supported in live mode: Once you are confident with the simulations that you have obtained with your algorithm in backtesting, you may switch to live trading, where you have two different modes: The bitfinex api c example algorithm runs in real time, and fetches pricing data in real time from the exchange, but the orders never reach the exchange, and are instead kept within Catalyst and simulated.

No real currency is bought or sold. Think of it as a backtesting happening in real time. This is the proper live trading mode in which an algorithm runs in real time, fetching pricing data from live exchanges and placing orders against the exchange.

Real currency is transacted on the exchange driven by the algorithm. These three modes are controlled by the following variables: Here is the Catalyst convention: Here are some examples: Here is the same example in both interfaces: Cleaning the state can be achieved by running: