Home Funciones Mercados Blog
Ayuda & FAQ Contacto
 
Twitter icon Facebook icon
El siguiente contenido no está disponible en Español. Si tienes dificultades de entenderlo, simplemente póngase en contacto con nosotros. Con mucho gusto te ayudaremos.

API Documentation - Version 2.1

Basics

User

Order

Position

Market

Social



Basics

HTTPS

Our trading API is based on simple HTTPS GET requests; we do not accept requests over the unencrypted HTTP protocol. Data is returned as a JSON encoded object. Virtually all programming environments offer the required libraries to access our HTTPS API. Currently you can:
  • Get basic account data
  • Create/cancel and list open orders
  • Edit/cancel and list open positions
  • List position/transaction history
  • Get market data

Authentication

All API requests require authentication with an API token. You can generate up to 5 API tokens in your Account Settings. An API token consists of 32 random characters (Letters and numbers).

Base URL

https://1broker.com/api/v2/


Example Request

https://1broker.com/api/v2/type/method.php?&pretty=1&token=%APITOKEN%
	&parameter1=123
	&parameter2=false


Example JSON Response

{
	"server_time": "2014-11-06T10:34:47.123Z",
	"error": false,
	"warning": false,
	//Response Object for the API request
	"response": {
		...
	}
}


Errors and Warnings

Each request comes with an "error" and "warning" field (boolean). Always check against the "error" field to see if the API request was successful. Make sure to log or display warnings and errors in your application. (e.g. API deprecation warning)

If an error occurs, a numeric "error_code" is returned. For warnings and errors, a "_message" post-fixed field exists, which contains a description of the problem.

Example Warning

{
	"server_time": "2016-11-04T10:12:27.631Z",
	"error": false,
	"warning": true,
	"warning_message": "API version 1 is deprecated and will be disabled on January 9th, 2017. Please switch to version 2 and create a new API token.",
	//Response Object for API request
	"response": {
		...
	}
}

Example Error

{
	"server_time": "2016-11-04T10:12:27.631Z",
	"error": true,
	"error_code": "301",
	"error_message": "Invalid input format for symbol.",
	"warning": false,
	"response": null
}


Data types

Numeric Types

All integer and float values are returned as quoted strings. This makes sure that no precision is lost across platforms.
"1000315", "102.65557", "-10.98765"

Bitcoin Amounts

Warning: Using 32 bit integers/floats will lead to errors in your application. More information
Bitcoin amounts are returned as strings (see above) and in Bitcoin (1 Bitcoin = 100,000,000 satoshis). (List of Bitcoin Units) Internally we use integer representation for all amounts, so you can safely multiply amounts by 100.000.000 (1e8) and will always receive a valid (64-bit) integer.
"1", "0.01", "-3.56216842"

Timestamps

Timestamps are returned as ISO 8601 strings with up to millisecond precision. Most modern languages and libraries will handle these without any issues.
The letter 'T' is a separator between the date and time. The letter 'Z' at the end indicates that the timestamp is, like all returned timestamps, in UTC time.
"server_time": "2014-11-06T10:34:47.123Z"


Paging

Certain API requests like logs have too many elements to request them all at once. Across our API, paging works with a limit and an offset parameter. Here is an example of how to use them:
1st pagelimit 10, offset 0
2nd pagelimit 10, offset 10
3rd pagelimit 10, offset 20
...
n-th pagelimit 10, offset 10*(n-1)

Example API request with offset 20 and limit 10:

.../type/method.php?token=%APITOKEN%
&offset=20
&limit=10

Response

The response object contains the requested elements for the current page.

Deprecation policy

If an API version is deprecated, a warning message is appended to every response. (see example above) We will support deprecated APIs for at least two months after a new API version is available. In order to get informed about a deprecated API version in time, please log or display warning messages in your application

SSL certificate verification

We strongly recommend that all API requests validate the SSL certificate presented to prevent MITM attacks. Usually this is turned on by default in most libraries, but if you see a setting to 'verify SSL' you should always ensure it is set to 'true'.

IP Restriction

If you make API requests via a static IP address, make sure to enable an IP restriction when generating the API token, for security reasons.

Pretty Printing

By appending ...&pretty=1 to a request the response becomes easier readable for humans. In production you should disable this option to save bandwidth and increase parsing times.

Monetizing your software

Monetizing trading software, that was built for other traders on top of our API, can be done in various ways and there are no specific restrictions. However, we strongly recommend to use the possibility of overwriting the trader's referral_id in the order/create method. Per the terms of our referral program, you will receive a profit share once the order gets executed. You can read more about our referral program at https://1broker.com/trade/#referral (login required).

Quotas

In order to keep our API responsive for all traders, we're using an IP address based quota system. The API is rate limited by a CPU allowance, rather than a fixed number of calls per time window. Some API requests take longer to fetch than others, so these cost more allowance. Currently, each client has an allowance of 100000 ms (100 seconds) of CPU time per hour. Once that quota is reached no further requests are possible until the start of the next hour.
You can check your remaining quota by calling user/quota_status.

Execution Time

By appending ...&execution_time=1 to a request the response will include the execution time for the API call. You can estimate the cpu time/hour cost of your application that way and stay within the quota limits. In production you should disable this option to save bandwidth and increase parsing times.

Example Response

{
	...,
	"execution_time_milliseconds": 2
}



User

user/details.php

Parameters

None

Returns

Basic account information.

Example Request

.../user/details.php?token=%APITOKEN%&pretty=1

Example Response

{
	...
	"response": {
		"username": "example_user",
		"email": "user@example.com",
		"balance": "9.1636",
		"deposit_unconfirmed": "0.0123",
		"date_created": "2014-11-06T10:34:47Z"
	}
}


user/overview.php

Parameters

None

Returns

Extended account information.

Example Request

.../user/overview.php?token=%APITOKEN%&pretty=1

Example Response

{
	...
	"response": {
		"username": "example_user",
		"email": "user@example.com",
		"balance": "9.1636",
		"deposit_unconfirmed": "0.0123",
		"date_created": "2014-11-06T10:34:47Z",
		"orders_worth": "405",
		"positions_worth": "424.5548",
		"net_worth": "2738.7184",
		"orders_open": [
			{
				"order_id": "1650",
				"symbol": "EURUSD",
				"margin": "1",
				"leverage": "200",
				"direction": "short",
				"order_type": "Market",
				"order_type_parameter": "-1",
				"stop_loss": "0",
				"take_profit": "0",
				"shared": true,
				"date_created": "2016-11-03T15:40:53Z"
			},
			...
		],
		"positions_open": [
			{
				"position_id": "16993",
				"order_id": "456",
				"symbol": "DOW",
				"margin": "1",
				"leverage": "1",
				"direction": "long",
				"entry_price": "18209.40514339",
				"profit_loss": "-0.0336556",
				"profit_loss_percent": "-3.37",
				"value": "0.9663444",
				"market_close": false,
				"stop_loss": "0",
				"take_profit": null,
				"trailing_stop_loss": false,
				"shared": true,
				"copy_of": null,
				"date_created": "2016-10-24T07:16:55Z"
			},
			...
		]
	}
}


user/bitcoin_deposit_address.php

Parameters

None

Returns

Address for Bitcoin deposits and whether or not any form of two factor authentication is enabled.

Example Request

.../user/bitcoin_deposit_address.php?token=%APITOKEN%&pretty=1

Example Response

{
	...
	"response": {
		"bitcoin_deposit_address": "1JArS6jzE3AJ9sZ3aFij1BmTcpFGgN86hA",
		"two_factor_authentication": true
	}
}

user/transaction_log.php

Parameters

offset positive Integer (optional) Offset from last transaction. (Default: 0)
limit positive Integer (optional) Maximum amount of transactions per page. (Default: 20)
date_start ISO8601 Date (optional) Only list transactions later than this date. (Default: 1.1.1970)
date_end ISO8601 Date (optional) Only list transactions earlier than this date. (Default: current date)

Returns

Pageable Transaction Log.

Example Request

.../user/transaction_log.php?token=%APITOKEN%&pretty=1
&offset=0
&limit=20
&date_start=2016-01-01T12:00:00Z
&date_end=2016-12-31T12:00:00Z

Example Response

{
	...
	"response": [
		{
			"date": "2016-10-25T10:55:46Z",
			"type": "POS_CLOSE",
			"balance_delta": "1.01643472",
			"balance_new": "4.6886883",
			"description": "Position was closed."
		},
		...
	]
}

user/quota_status.php

Parameters

None

Returns

Returns your remaining server CPU time for this hour (in ms).

Example Request

.../user/quota_status.php?token=%APITOKEN%&pretty=1

Example Response

{
	...
	"response": {
		"cpu_time_left": "2451"
	}
}



Orders

order/open.php

Parameters

None

Returns

List of open orders as a JSON array.

Example Request

.../order/open.php?token=%APITOKEN%&pretty=1

Example Response

{
	...
	"response": [
		{
			"order_id": "121532",
			"symbol": "EURUSD",
			"margin": "0.5",
			"leverage": "75",
			"direction": "long",
			"order_type": "market",
			"order_type_parameter": "-1",
			"stop_loss": "1.1005",
			"take_profit": "1.2000",
			"shared": false,
			"date_created": "2015-05-27T16:09:27Z"
		},
		...
	]
}


order/create.php

Parameters

symbol String Symbol for the market you want to place the order.
margin Float Amount you want to invest. (in Bitcoin)
direction String "long" or "short"
leverage Float Desired leverage. Remember that markets have different maximum leverages.
order_type String "market", "limit" or "stop_entry"
order_type_parameter Float Parameter for the specified ordertype. Not required for 'Market' orders.
stop_loss Float (Optional) Stop Loss for the position, once opened.
take_profit Float (Optional) Take Profit for the position, once opened.
referral_id Integer (Optional) Sets/Overwrites the trader's referral ID. (Referral ID is only changed for this particular order) You can find out your referral ID on the referral page.
shared Boolean (Optional) Indicates whether or not the trade will be visible to other traders.

Returns

Created order.

Example Request

.../order/create.php?token=%APITOKEN%&pretty=1
&symbol=GOLD
&margin=0.25
&direction=long
&leverage=3
&order_type=limit
&order_type_parameter=950
&referral_id=1337
&shared=true

Example Response

{
	...
	"response": {
		"order_id": "1658",
		"symbol": "GOLD",
		"margin": "0.25",
		"leverage": "3",
		"direction": "long",
		"order_type": "limit",
		"order_type_parameter": "950",
		"stop_loss": null,
		"take_profit": null,
		"shared": true,
		"date_created": "2016-11-07T13:44:32Z"
	}
}


order/cancel.php

Parameters

order_id Integer ID of the order which should be cancelled.

Returns

null

Example Request

.../order/cancel.php?&token=%APITOKEN%&pretty=1
&order_id=210123

Example Response

{
	...
	"response": null
}


Positions

position/open.php

Parameters

None

Returns

List of open positions as a JSON array.

Example Request

.../position/open.php?token=%APITOKEN%&pretty=1

Example Response

{
	...
	"response": [
		{
			"position_id": "16993",
			"order_id": "456",
			"symbol": "DOW",
			"margin": "1",
			"leverage": "1",
			"direction": "long",
			"entry_price": "18209.40514339",
			"profit_loss": "-0.0336556",
			"profit_loss_percent": "-3.37",
			"value": "0.9663444",
			"market_close": false,
			"stop_loss": "0",
			"take_profit": null,
			"trailing_stop_loss": false,
			"shared": false,
			"copy_of": null,
			"date_created": "2016-10-24T07:16:55Z"
		},
		...
	]
}


position/history.php

Parameters

offset positive Integer (optional) Offset from the most recently closed position. (Default: 0)
limit positive Integer (optional) Maximum amount of positions per page. (Default: 20)
date_start ISO8601 Date (optional) Only list positions closed after this date. (Default: 1.1.1970)
date_end ISO8601 Date (optional) Only list positions closed before this date.(Default: current date)

Returns

A pageable list of historic positions sorted by closing date (descending). Note: In the future we may delete entries for trades that were closed more than 90 days ago.

Example Request

.../position/history.php?token=%APITOKEN%&pretty=1
&offset=0
&limit=20
&date_start=2016-01-01T12:00:00Z
&date_end=2016-12-31T12:00:00Z

Example Response

{
	...
	"response": [
		{
			"position_id": "16073",
			"order_id": "375",
			"symbol": "USDCAD",
			"margin": "2",
			"leverage": "1",
			"direction": "short",
			"entry_price": "1.31342",
			"exit_price": "1.49269",
			"profit_loss": "-0.27298199",
			"profit_loss_percent": "-13.65",
			"value": "1.72701801",
			"stop_loss": "2.600572",
			"take_profit": null,
			"shared": false,
			"copy_of": null,
			"date_created": "2016-10-24T07:16:53Z",
			"date_closed": "2016-11-02T09:20:46Z"
		},
		...
	]
}


position/edit.php

Parameters

position_id Integer ID of the position which should be edited.
stop_loss Float (Optional) Stop Loss value for the position.
take_profit "null" or Float (Optional) Take Profit value for the position.
trailing_stop_loss Boolean (true or false) (Optional) Stop Loss will be set to trail the price (at the current distance) if true.

Returns

Position ID and the changed parameters.

Example Request

.../position/edit.php?token=%APITOKEN%&pretty=1
&position_id=1031546
&stop_loss=932
&take_profit=1000
&trailing_stop_loss=true

Example Response

{
	...
	"response":
	{
		"position_id": "1031546",
		"stop_loss": "932",
		"take_profit": "1000"
		"trailing_stop_loss": true
	}
}


position/close.php


Sets the market_close flag of the position to true and thereby marks it for closure at the next possible update.

Parameters

position_id Integer ID of the position that should be closed.

Returns

null.

Example Request

.../position/close.php?token=%APITOKEN%&pretty=1
&position_id=1031546

Example Response

{
	...
	"response": null
}


position/close_cancel.php

Parameters

position_id Integer ID of the position whose closure should be stopped.

Returns

null.

Example Request

.../position/close_cancel.php?token=%APITOKEN%&pretty=1
&position_id=1031546

Example Response

{
	...
	"response": null
}


position/shared/get.php

Parameters

position_id positive Integer Valid id for a shared position

Returns

Details and comments for a shared position.

Example Request

.../position/shared/get.php?token=%APITOKEN%&pretty=1
&position_id=1234567

Example Response

{
	...
	"response": {
		"symbol": "BTCUSD",
		"direction": "long",
		"position_id": "6",
		"username": "Patrick",
		"profile_image_url": "https://1broker.com/img/trade/profile_default_picture.svg",
		"user_id": "1",
		"leverage": "5",
		"date_created": "2017-04-06T08:05:53Z",
		"entry_price": "1000.22496",
		"is_open": true,
		"date_closed": null,
		"exit_price": null,
		"profit_loss_percent": "98.79",
		"stop_loss": "862.2629",
		"take_profit": null,
		"trailing_stop_loss": false,
		"comments": [
			{
				"comment_id": 1,
				"user_id": 1,
				"username": "Patrick",
				"content": "First public trade!",
				"upvotes": 0,
				"downvotes": 0,
				"deleted": null,
				"profile_image_url": "https://1broker.com/img/trade/profile_default_picture.svg"
			},
			...
		]
	}
}


Market Data

market/categories.php

Parameters

None

Returns

List of all available market categories.

Example Request

.../market/categories.php?token=%APITOKEN%&pretty=1

Example Response

{
	...
	"response": [
		"INDEX",
		"STOCK",
		"COMMODITY",
		"FOREX",
		"CRYPTO"
	]
}

market/list.php

Parameters

category String Category for which markets should be listed

Returns

List of all available markets of this category.

Example Request

.../market/list.php?token=%APITOKEN%&pretty=1
&category=forex

Example Response

{
	...
	"response": [
		{
			"symbol": "AUDNZD",
			"name": "AUD/NZD",
			"category": "FOREX",
			"type": "CFD"
		},
		...
	]
}


market/details.php

Parameters

symbol String Symbol for the requested market.

Returns

Details of the market.

Example Request

.../market/details.php?token=%APITOKEN%&pretty=1
&symbol=GOLD

Example Response

{
	...
	"response": {
		"symbol": "GOLD",
		"name": "Gold 1 oz",
		"description": "Gold has been a valuable and highly sought-after...",
		"category": "COMMODITY",
		"type": "CFD",
		"maximum_leverage": "100",
		"maximum_amount": "500",
		"overnight_charge_long_percent": "0.0204",
		"overnight_charge_short_percent": "0.0077"
		"decimals": "2",
		"market_hours": {
			"timezone": "America/New_York",
			"open": "Sunday 18:00:00",
			"close": "Friday 17:00:00",
			"daily_break_start": "17:00:00",
			"daily_break_stop": "18:00:00"
		}
	}
}


market/quotes.php

Parameters

symbols String ',' separated list of symbols. Maximum is 20 symbols.

Returns

List of market prices.

Example Request

.../market/quotes.php?token=%APITOKEN%&pretty=1
&symbols=EURUSD,GOLD

Example Response

{
	...
	"response": [
		{
			"symbol": "EURUSD",
			"bid": "1.19588258",
			"ask": "1.19598258",
			"updated": "2016-11-02T11:19:00Z"
		},
		{
			"symbol": "GOLD",
			"bid": "1358.31771784",
			"ask": "1358.91771784",
			"updated": "2016-11-07T13:36:35Z"
		}
	]
}


market/bars.php (Historical market data)

Parameters

symbol String Symbol for the requested market.
resolution Integer
(60, 900, 3600 or 86400)
Resolution of one OHLC bar in seconds.
(1 minute, 15 minutes, 1 hour, 1 day)
date_start ISO8601 Date (optional) Leftmost (start-)point of the data. (Default: 1.1.1970)
date_end ISO8601 Date (optional) Rightmost (end-)point of the data. (Default: current date)
limit Integer (optional) Maximum number of returned bars. (Default: no limit)

Returns

Array of OHLC (Date, Open-, High-, Low-, Close-price) bars.

If there is no market data available for the specified range (see below), an empty array is returned.

Available resolution

Please expect that old historical data will be removed for performance reasons. However, you can safely assume that data is available for:
7 dayswith 60s (1 minute) resolution
105 dayswith 900s (15 minutes) resolution
366 dayswith 3600s (1 hour) resolution
foreverwith 86400s (1 day) resolution

Additional Information

OHLC bars are a commonly used data format to store historical market data. Instead of returning millions of price ticks, OHLC bars contain the most important market information in 1-minute, 1-day etc. (resolution) "blocks". This saves storage, bandwidth and computation power for applications.

Note: Inexperienced traders are often confused by OHLC charts and prefer line charts. You can simply use the "c" (close) price for plotting such line charts.


Example Request

.../market/bars.php?token=%APITOKEN%&pretty=1
&symbol=GOLD
&resolution=60
&date_start=2016-10-30T12:00:00Z
&date_end=2016-11-02T12:00:00Z

Example Response

{
	...
	"response": [
		...
		{
			"date": "2016-11-02T10:28:00Z",
			"o": "1235.142561",
			"h": "1238.721443",
			"l": "1203.329001",
			"c": "1224.582498"
		},
		...
	]
}

market/ticks.php

Parameters

symbol String Symbol for the requested market.
limit positive Integer (optional) Maximum amount of ticks. (Default: 100)

Returns

List of dates, price and spread for the last ticks.

Example Request

.../market/ticks.php?token=%APITOKEN%&pretty=1
&symbol=GOLD
&limit=100

Example Response

{
	...
	"response": [
		{
			"date": "2016-12-16T09:36:49Z",
			"price": "1282.31",
			"spread": "0.6"
		},
		{
			"date": "2016-12-16T09:36:50Z",
			"price": "1282.84",
			"spread": "0.6"
		},
		...
	]
}


Social

social/profile_statistics.php

Parameters

user_id positive Integer Valid user_id

Returns

Trading statistics for this user (if it is not set to private).

Example Request

.../social/profile_statistics.php?token=%APITOKEN%&pretty=1
&user_id=1

Example Response

{
	...
	"response": {
		"user_id": "1",
		"username": "Patrick",
		"profile_image_url": "https://www.1broker.com/img/trade/profile_default_picture.svg",
		"date_created": "2012-11-08T08:05:44Z",
		"profile_about_me_html": "<a href=\"http://lmgtfy.com\" target=\"_blank\">http://lmgtfy.com</a>",
		"profile_about_me_raw": "http://lmgtfy.com",
		"own_profile_hidden": false,
		"risk_score": "1",
		"maximum_profit_this_month": "0.13",
		"maximum_loss_this_month": "-0.26",
		"copy_trade_reward_total": "1.337",
		"copier_count": "420",
		"copy_margin_per_trade": "3.50",
		"performance": [
			[
				"2016-05-01T00:00:00Z",
				"-77.2"
			],
			...
		],
		"copier_count_history": [
			[
				"2016-04-21T00:00:00Z",
				"2"
			],
			...
		],
		"date_cached": "2017-04-21T09:23:13.221Z",
		"average_holding_time_seconds": "1944002",
		"trades_last_7_days": "0",
		"trades_last_12_months": "6",
		"market_category_share": {
			"CRYPTO": "33.33",
			"INDEX": "16.66",
			"STOCK": "16.66",
			"COMMODITY": "16.66",
			"FOREX": "16.66"
		}
	}
}

social/profile_trades.php

Parameters

user_id positive Integer Valid user_id
offset positive Integer (optional) Offset from last closed trade. (Default: 0)
limit positive Integer (optional) Maximum amount of closed trades per page. (Default: 20)

Returns

Open and historic public trades.

Example Request

.../social/profile_trades.php?token=%APITOKEN%&pretty=1
&user_id=1
&offset=0
&limit=20

Example Response

{
	...
	"response": {
		"user_id": "1",
		"username": "Patrick",
		"profile_image_url": "https://www.1broker.com/img/trade/profile_default_picture.svg",
		"date_created": "2012-11-08T08:05:44Z",
		"profile_about_me_html": "<a href=\"http://lmgtfy.com\" target=\"_blank\">http://lmgtfy.com</a>",
		"profile_about_me_raw": "http://lmgtfy.com",
		"own_profile_hidden": false,
		"risk_score": "1",
		"maximum_profit_this_month": "0.13",
		"maximum_loss_this_month": "-0.26",
		"trading_ideas_open": [
			{
				"position_id": "6",
				"symbol": "BTCUSD",
				"leverage": "5",
				"profit_loss_percent": "98.79",
				"comment_count": "8",
				"direction": "long",
				"date_created": "2017-04-03T00:13:37Z",
				"is_open": true,
				"date_closed": null
			},
			...
		],
		"trading_ideas_closed": [
			{
				"position_id": "8",
				"symbol": "BTCUSD",
				"leverage": "5",
				"profit_loss_percent": "-0.62",
				"comment_count": "3",
				"direction": "short",
				"date_created": "2017-04-01T04:20:00Z",
				"is_open": false,
				"date_closed": "2017-04-06T09:00:00Z"
			},
			...
		]
	}
}

¿Que estás esperando?

Crear cuenta Iniciar sesión

Take us with you

Get it on
Google Play