Giter Club home page Giter Club logo

restapi's Introduction

RestAPI

Our REST API is a web-based API using a Websocket connection and was developed with algorithmic trading in mind.

Developers and investors can create custom trading applications, integrate into our platform, back test strategies and build robot trading. Calls can be made in any language that supports a standard HTTP.

We utilize the new OAuth 2.0 specification for authentication via token. This allows for a more secure authorization to access your application and can easily be integrated with web applications, mobile devices, and desktop platforms

With the use of the socket.io library, the API has streaming capability and will push data notifications in a JSON format. Your application will have access to our real-time streaming market data, subscribe in real time access to trading tables and place live trades.

How to start:

  1. A FXCM account. You can apply for a demo account here
  2. A persistent access token. You can generate one from the Trading Station web. Click on User Account > Token Management on the upper right hand of the website. For Live account, please send your username to [email protected], we will need to enable Rest API access. For demo account, Rest API access was enabled by default.
  3. Download Rest API word documents at here
  4. Documents in Swagger format at here
  5. Start coding. You will need to reference the socket.io library in your code. a. Using Javascript, click here b. Using Python, click here
  6. Sample code for Python at here
  7. Sample code for Java Script at here
  8. Sample code in Netbeans Maven project at here

How to connect:

Clients should establish a persistent WebSocket connection using socket.io library. All non-solicited updates will be sent over this connection. Client requests are to be sent via normal HTTP messages. Every HTTP message must contain following parameters

Header Description Values Req’d
HTTP version Version of HTTP used HTTP/1.1 Y
User-Agent Identification of the client software xxxxxx_software Y
Accept Acceptable response MIME type application/json Y
Content-Type Media type of the request application/x-www-form-urlencoded Y
Authorization Authorization string containing “Bearer “, ID of socket.io connection and persistent token 'Bearer ' + socket_id + api_token Y
  Sample Request
  GET /socket.io/?access_token=cj5wedhq3007v61fe935ihqed&EIO=3&transport=polling&t=Lsd_lZY&b64=1 
  HTTP/1.1 
  User-Agent: node-XMLHttpRequest 
  Accept: */* 
  Host: api.fxcm.com 
  Connection: close

What 't' means

"t" is the table id:

t table ID
1 Open Position
2 Closed Position
3 Order
5 Summary
6 Account

Subscribe vs snapshot:

FXCM Rest API provides two ways to deliever data. susbcribe vs snapshot.

After susbcribe, data will be pushed to your socket whenever there is an update. You can susbcribe Market data stream /susbcribe or live table update /trading/susbcribe. You can also unsubscribe. You can request a snapshot of trading tables via /trading/get_model.

  Model choices: 'Offer', 'OpenPosition', 'ClosedPosition', 'Order', 'Summary', 'LeverageProfile', 'Account', 'Properties'.   

OrderID vs TradeID:

OrderID and TradeID are different. In Market order, an order id is created straightaway and it is in callback immediately.

  {"response":{"executed":true},"data":{"type":0,"orderId":81712802}}

A trade id is not generated until after order is executed. You have to subscribe the order table and listing the live update and look up the trade id. You will not get trade id in snapshot, because that information was gone when you submit the request.

  Examples:
  Subscribing for Orders table:
  POST /trading/subscribe
  models=Order
  
  Placing Market order:
  POST /trading/open_trade
  account_id=1537581&symbol=EUR%2FUSD&is_buy=false&rate=0&amount=5&order_type=AtMarket&time_in_force=GTC

  Response from server:
  {"executed":true}{"type":0,"orderId":390285837}

  Received Order record from /trading/subscribe with order_id and trade_id:
  {"t":3,"ratePrecision":5,"orderId":"390285837","tradeId":"170162801","time":"04252018120716391","accountName":"01537581","accountId":"1537581","timeInForce":"GTC","expireDate":"","currency":"EUR/USD","isBuy":false,"buy":0,"sell":1.21818,"type":"OM","status":2,"amountK":5,"currencyPoint":0.5,"stopMove":0,"stop":0,"stopRate":0,"limit":0,"limitRate":0,"isEntryOrder":false,"ocoBulkId":0,"isNetQuantity":false,"isLimitOrder":false,"isStopOrder":false,"isELSOrder":false,"stopPegBaseType":-1,"limitPegBaseType":-1,"range":0,"action":"I"}

Furthermore, a single market order can have many TradeIDs, if they are partial fills or closing of other orders. in this case, its more approriate to provide the OrderID which ties back to that spcific market order request, from there you can join this OrderID to any associated.

In entry order, an order ID is in callback function. You can also see it on order table sanpshot. but you will not get TradeID until order been executed.

limitation on historical candle download per request:

Time-frame max days back max num
m1 16 10,000
m5 56 10,000
m15 212 10,000
m30 316 10,000
h1 624 10,000
h2 1224 10,000
h3 2056 10,000
h4 2664 10,000
h6 3632 10,000
h8 5128 10,000
D1, W1, M1 no limit no limit

Real Case Study:

  1. Learn how to run BT backtest on FXCM historical data via RestAPI at here. What is bt?
  2. Learn how to run QSTrader on FXCM data via RestAPI at here. what is QSTrader?
  3. Building/back testing RSI strategy via RestAPI at here.
  4. Building/back testing Moving Average Crossover strategy via RestAPI at Here
  5. One video demonstrate how to backtest strategies in Visual Studio via FXCM data On QuantConnect LEAN platform at here

Note:

o This is for personal use and abides by our EULA

o For more information, you may contact us: [email protected]

Disclaimer:

Trading forex/CFDs on margin carries a high level of risk and may not be suitable for all investors as you could sustain losses in excess of deposits. Leverage can work against you. The products are intended for retail and professional clients. Due to the certain restrictions imposed by the local law and regulation, German resident retail client(s) could sustain a total loss of deposited funds but are not subject to subsequent payment obligations beyond the deposited funds. Be aware and fully understand all risks associated with the market and trading. Prior to trading any products, carefully consider your financial situation and experience level. If you decide to trade products offered by FXCM Australia Pty. Limited (“FXCM AU”) (AFSL 309763), you must read and understand the Financial Services Guide, Product Disclosure Statement, and Terms of Business. Any opinions, news, research, analyses, prices, or other information is provided as general market commentary, and does not constitute investment advice. FXCM will not accept liability for any loss or damage, including without limitation to, any loss of profit, which may arise directly or indirectly from use of or reliance on such information. FXCM will not accept liability for any loss or damage, including without limitation to, any loss of profit, which may arise directly or indirectly from use of or reliance on such information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.