Skip to content

Commit

Permalink
replace the FXCM REST API Demonstration.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
FXCMAPI committed Oct 17, 2018
1 parent 6f7b27f commit a9d7497
Showing 1 changed file with 14 additions and 59 deletions.
73 changes: 14 additions & 59 deletions FXCM-Algo-Summit/FXCM REST API Demonstration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@
"import datetime as dt\n",
"fxcmpy.__version__\n",
"\n",
"token = 'YOUR_TOKEN_HERE'\n",
"\n",
"#Use the config file to connect to the API. \n",
"con = fxcmpy.fxcmpy(config_file='fxcm.cfg')\n",
"con = fxcmpy.fxcmpy(access_token = token, log_level='error',log_file=None)\n",
"\n",
"#The server is demo by default. THe options below are also available for usage.\n",
"#con = fxcmpy.fxcmpy(config_file='fxcm.cfg', server='demo')"
"#con = fxcmpy.fxcmpy(config_file='fxcm.cfg', server='demo')\n",
"\n",
"#Connect to the API with a real account. Do not forget to change the access token in the config file.\n",
"#con = fxcmpy.fxcmpy(config_file='fxcm.cfg', server='real')"
]
},
{
Expand Down Expand Up @@ -86,7 +91,7 @@
"source": [
"#Getting historical prices by specifying only the period. \n",
"\n",
"con.get_candles('GBP/JPY', period='m1')"
"con.get_candles('EUR/JPY', period='m1')"
]
},
{
Expand All @@ -99,7 +104,7 @@
"source": [
"#Getting historical prices by specifying the number of results you would like to see.\n",
"\n",
"con.get_candles('EUR/USD', period='D1', number=50)"
"con.get_candles('EUR/USD', period='m1', number=100)"
]
},
{
Expand Down Expand Up @@ -142,9 +147,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"metadata": {},
"outputs": [],
"source": [
"# Once you are subscribed the fxcm.py collects the data in a pandas DataFrame. \n",
Expand Down Expand Up @@ -213,36 +216,12 @@
"source": [
"# Place an order with more control over parameters\n",
"\n",
"order2 = con.open_trade(symbol='GBP/JPY', is_buy=True,\n",
"order2 = con.open_trade(symbol='EUR/JPY', is_buy=True,\n",
" rate=105, is_in_pips=False,\n",
" amount='10', time_in_force='GTC',\n",
" order_type='AtMarket', limit=150)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Modify a stop or limit\n",
"\n",
"tradeID = con.get_open_trade_ids()[-1]\n",
"\n",
"con.change_trade_stop_limit(tradeID, is_in_pips=False, is_stop=False, rate = 170)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Check on open positions and limit modification\n",
"\n",
"con.get_open_positions().T"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand All @@ -260,21 +239,10 @@
"source": [
"# Close position by specifying the tradeId\n",
"\n",
"pos = con.get_open_position(52602457)\n",
"pos = con.get_open_position(65680347)\n",
"pos.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Check to see if the position closed\n",
"\n",
"con.get_open_positions().T"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -292,22 +260,9 @@
"metadata": {},
"outputs": [],
"source": [
"# Check to see if all USD/JPY positions have closed\n",
"# CLose all the positions at once\n",
"\n",
"con.get_open_positions().T"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# CLose all remaining positions at once\n",
"\n",
"con.close_all()\n",
"\n",
"con.get_open_positions().T"
"con.close_all()"
]
},
{
Expand Down

0 comments on commit a9d7497

Please sign in to comment.