Skip to main content

Ctrader Fix API

Project description

Python Ctrader Fix API

Installation

pip install ejtraderCT -U

or

python setup.py install

import

from ejtraderCT import Ctrader

import time
import logging
from datetime import datetime

logging.getLogger().setLevel(logging.INFO)

Fix login account and details

FIX_SERVER="h8.p.c-trader.cn"
FIX_BROKER="icmarkets"
FIX_LOGIN="3152339"
FIX_PASSWORD="393214"
FIX_CURRENCY="EUR"

api = Ctrader(FIX_SERVER,FIX_BROKER,FIX_LOGIN,FIX_PASSWORD,FIX_CURRENCY)

You can create market or pending order with the commands.

Market Orders

api.buy("EURUSD", 0.01, 1.18, 1.19)
api.sell("EURUSD", 0.01, 1.19, 1.18)

Limit Orders

api.buyLimit("EURUSD", 0.01, 1.17, 1.19, 1.18)
api.sellLimit("EURUSD", 0.01, 1.23, 1.17, 1.22)

Stop Orders

api.buyStop("EURUSD", 0.01, 1.20, 1.24, 1.22)
api.sellStop("EURUSD", 0.01, 1.19, 1.17, 1.18)

Positions

positions = api.positions()
print(positions)
for position in positions:
    api.positionCloseById(position['pos_id'], position['amount'])

positions = api.positions()
print(positions)

Orders Manipulation

Corders = api.orders()
print(orders)
for order in orders:
    api.orderCancelById(order['ord_id'])

orders = api.orders()
print(orders)

If you want to cancel all Orders

api.cancel_all()

if you want to close all positions

api.close_all()

Future add comming soon

Modify pending orders

api.modify()

Real time Data and history

history = api.history("GBPUSD", "M5", int(datetime.now().timestamp()) - 10000)
# print(history)

Account information

accountInfo = api.accountInfo()
print(accountInfo)
print(accountInfo['broker'])
print(accountInfo['balance'])

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

ejtraderCT-1.0.0.tar.gz (12.3 kB view hashes)

Uploaded Source

Built Distribution

ejtraderCT-1.0.0-py3-none-any.whl (23.6 kB view hashes)

Uploaded Python 3

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