Skip to main content

Ctrader Fix API

Project description

Python Ctrader Fix API

Installation

Tested on python 3.7 to 3.9

pip install ejtraderCT -U

Or install from source

git clone https://github.com/ejtraderLabs/ejtraderCT
cd ejtraderCT
python setup.py install

Import librarys

from ejtraderCT import Ctrader

import time
import logging
from datetime import datetime

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

Fix login account and details

SERVER="h8.p.c-trader.cn"
BROKER="icmarkets"
LOGIN="3152339"
PASSWORD="393214"
CURRENCY="EUR"

api = Ctrader(SERVER,BROKER,LOGIN,PASSWORD,CURRENCY)

Real time quote

Subscribe to symbol
api.symbolSubscribe("EURUSD", "GBPUSD")
All symbols quote list
quote = api.quote()
print(quote)

# Output

{'EURUSD': {'bid': 1.02616, 'ask': 1.02618}, 'GBPUSD': {'bid': 1.21358, 'ask': 1.21362}}

Single symbol quote

quote = api.quote("EURUSD")
print(quote)

# Output

{'bid': 1.02612, 'ask': 1.02614}

Market position and pending order.

Market Position
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)

List Positions

positions = api.positions()
print(positions)

List limit and stop Orders

orders = api.orders()
print(orders)

Cancle order by id

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

Close position by id

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

cancel all Orders

api.cancel_all()

close all positions

api.close_all()

ToDo

  • Account Information
  • SL and TP
  • Modify Orders
  • Modify position
  • real time bid & ask

Thanks for

@HarukaMa @douglasbarros

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.4.tar.gz (27.4 kB view hashes)

Uploaded Source

Built Distribution

ejtraderCT-1.0.4-py3-none-any.whl (26.5 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