Skip to main content

Python project for Forexconnect API from FXCM

Project description

AlgoAPi

ALgoAPI is a Python library for dealing with executing trading using FXCM ForexConnect API.

Installation

git clone https://github.com/KrishnaInvestment/algoapi.git
cd algoapi
pip3 install . 

Alternatively you can install the package using PIP

pip install algoapi

Usage

Login

from algoapi.fxconnect import FXCMClient

# Login to the API
fx = FXCMClient(
    USER_ID="YOUR_ID",
    USER_PASSWORD="YOUR_PASSWORD",
    URL="http://www.fxcorporate.com/Hosts.jsp",
    CONNECTION="Demo",
).login()

#You can add all the parameters of login in the link below as per the requirements

#to avoid entering the information each time maintain .env with variables
USER_ID = 'YOUR_ID'
USER_PASSWORD = 'YOUR_PASSWORD'
URL = 'http://www.fxcorporate.com/Hosts.jsp'
CONNECTION = 'Real'

You can check other inputs for login

Executing a trade

from algoapi.fxconnect.trade import OpenPosition
#You can place two types of order here at market price and at entry price

#Trading at entry price
op = OpenPosition(fx)
order_id = op.at_entry_price(
    INSTRUMENT="EUR/USD",
    TRANSACTION_TYPE="B",
    LOTS=1,
    RATE=rate,
    RATE_STOP=40,
    TRAIL_STEP_STOP=30,
    RATE_LIMIT=30,
)
#At entry price the rate must be added and stop/target are based on the pip value
#Instrument, TRANSACTION_TYPE, LOTS, RATE are required variable for executing entry trade
#However other variable are optional
# The entry price returns the order_id


#Trading at market price
trade_id, order_id = op.at_market_price(
    INSTRUMENT="EUR/USD", TRANSACTION_TYPE="B", LOTS=1
)

# You can add stop loss , limit , trail_step_stop as per the requirement

Closing a Trade

from algoapi.fxconnect.trade import ClosePosition
cp = ClosePosition(fx)
#Closing a position with the trade id
cp.close_position(trade_id)

#Close all Open position
cp.close_all_open_position()

Updating a Trade

from algoapi.fxconnect.trade import UpdatePosition
up = ClosePosition(fx)
#Update Limit price
up.update_limit_price(limit_price, trade_id)
#Limit price should be the actual price 
up.update_limit_price(1.11875,'75134317')
#Note all the ID's (trade_id, order_id are in string format)

#Update Stop price
up.update_stop_price(stop_price, trade_id, trail_step)
#Stop price should be the actual price
up.update_stop_price(1.11575,'75134317', trail_step)

#Trail step moves the stop limit as the price fluctuates in our desire direction

Deleting an Order

from algoapi.fxconnect.trade import DeleteOrder
do = DeleteOrder(fx)
#Closing a position with the trade id
do.delete_order(order_id)

Fetching Trade and Order Information

from algoapi.fxconnect.utils import get_pandas_table
df = get_pandas_table(fx, table_type)
#Table types like TRADES, OFFERS, ORDERS, CLOSED_POSITION, ACCOUNTS etc
#It will list all the information of that particular table
df_orders = get_pandas_table(fx, 'TRADES')

#You can  filter the tables based on the column value
df_filter_column = get_pandas_table(fx, table_type, key='Columns_name', value='column_value')
df_order_id_filter = get_pandas_table(fx, 'ORDERS', key='order_id', value='75134317')

#To get the latest price of the instrument
from forexconnect import Common
offer = Common.get_offer(fx, "EUR/USD")
# depending on the long and short position you can get the 
ask = offer.ask
bid = offer.bid

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

algoapi-0.0.4.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

algoapi-0.0.4-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file algoapi-0.0.4.tar.gz.

File metadata

  • Download URL: algoapi-0.0.4.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.4

File hashes

Hashes for algoapi-0.0.4.tar.gz
Algorithm Hash digest
SHA256 196d9d33b1896e77722e56076866d4ee298f2762c5e6ef9974f4a167e3aa8758
MD5 c41609e8ed9798a86923cbb650f38cae
BLAKE2b-256 3ba4859211f754725a5fb4ee0a11dd9e1bcf059eab24e0cf79b9d316f31edefb

See more details on using hashes here.

File details

Details for the file algoapi-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: algoapi-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.4

File hashes

Hashes for algoapi-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a81c2cdb142b75473f7006bf29be1642e1b2cdd8d04fa59bd45c74b46c687195
MD5 2dc2c3bc7310732b889bd14b7d7ee7c9
BLAKE2b-256 523cbe4ff1e63bcddd487c629bc0bc70d43135ddea84899a571945324d41a0fd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page