{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Server Connection" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This section is about the **server and API connection** itself. It needs to be established before any other tasks can be accomplished." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Basic Connection" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The following assumes that you have created a configuration file with your credentials as described in the _Quick Start_ section." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import fxcmpy" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "con = fxcmpy.fxcmpy(config_file='fxcm.cfg')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Status Information " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To check if the connection is established, you can use the method `con.is_connected()`." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con.is_connected()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After the connection is established, `fxcmpy` gathers information about your FXCM account.\n", "\n", "For example, the `ids` of your accounts within your FXCM account are retrieved." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[2815291]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con.get_account_ids()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The first account `id` is used as *default*:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2815291" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con.get_default_account()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To set another account as default, use `con.set_default_account()`." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ "con.set_default_account(2815291)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `ids` of your existing orders from previous sessions are also available ... " ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[337894215, 384867768, 337894217, 384867770]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con.get_order_ids() # regular orders" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[384867769]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "con.get_oco_order_ids() # OCO orders" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "... as well as the available instruments." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['EUR/USD', 'USD/JPY', 'GBP/USD', 'USD/CHF', 'EUR/CHF', 'AUD/USD', 'USD/CAD', 'NZD/USD', 'EUR/GBP', 'EUR/JPY', 'GBP/JPY', 'CHF/JPY', 'GBP/CHF', 'EUR/AUD', 'EUR/CAD', 'AUD/CAD', 'AUD/JPY', 'CAD/JPY', 'NZD/JPY', 'GBP/CAD', 'GBP/NZD', 'GBP/AUD', 'AUD/NZD', 'USD/SEK', 'EUR/SEK', 'EUR/NOK', 'USD/NOK', 'USD/MXN', 'AUD/CHF', 'EUR/NZD', 'USD/ZAR', 'USD/HKD', 'ZAR/JPY', 'USD/TRY', 'EUR/TRY', 'NZD/CHF', 'CAD/CHF', 'NZD/CAD', 'TRY/JPY', 'USD/CNH', 'AUS200', 'ESP35', 'FRA40', 'GER30', 'HKG33', 'JPN225', 'NAS100', 'SPX500', 'UK100', 'US30', 'Copper', 'CHN50', 'EUSTX50', 'USDOLLAR', 'USOil', 'UKOil', 'SOYF', 'NGAS', 'Bund', 'XAU/USD', 'XAG/USD']\n" ] } ], "source": [ "instruments = con.get_instruments()\n", "print(instruments)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To free resources, it is recommended to close the connection at the end of a session. " ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": true }, "outputs": [], "source": [ "con.close()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }