Skip to main content

Ctrader Fix API

Project description

Pypi Publish

Python Ctrader Fix API

ToDo

  • Account Information "not possible fix limitation"
  • Market Position buy and sell
  • Peding orders limit and stop
  • Partial close
  • Stop loss & Take profit
  • Modify Orders
  • Modify position
  • real time bid & ask

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" # Host name
broker="icmarkets" 
account="3152339"
password="393214"
currency="EUR"

api = Ctrader(server,broker,account,password,currency)
to Disconnect logout from account
api.logout()

Real time quote

Subscribe to symbol
api.subscribe("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
# Buy position

symbol = "EURUSD"
volume = 0.01 # position size
stoploss =  1.18
takeprofit = 1.19

api.buy(symbol, volume, stoploss, takeprofit)

# sell position 

symbol = "EURUSD"
volume = 0.01 # position size
stoploss = 1.19
takeprofit = 1.18

api.sell(symbol, volume, stoploss, takeprofit)
Limit Orders
# Buy limit order

symbol = "EURUSD"
volume = 0.01 # position size
stoploss = 1.17
takeprofit = 1.19
price = 1.18 # entry price 

api.buyLimit(symbol, volume, stoploss, takeprofit, price)


# Sell limit order

symbol = "EURUSD"
volume = 0.01 # position size
stoploss = 1.23
takeprofit = 1.17
price = 1.22 # entry price 

api.sellLimit(symbol, volume, stoploss, takeprofit, price)

Stop Orders

# Buy stop order

symbol = "EURUSD"
volume = 0.01 # position size
stoploss = 1.20
takeprofit = 1.24
price = 1.22 # entry price

api.buyStop(symbol, volume, stoploss, takeprofit, price)

# Sell stop order

symbol = "EURUSD"
volume = 0.01 # position size
stoploss = 1.19
takeprofit = 1.17
price = 1.18 # entry price 

api.sellStop(symbol, volume, stoploss, takeprofit, price)

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()

Modify Position SL and TP

id = "position id "
stoploss = "stop loss price""
takeprofit "stop gain price"

api.positionModify(id, stoploss, takeprofit)

Modify order Order SL and TP and entry price

id = "order id "
stoploss = "stop loss price""
takeprofit= "stop gain price"
price = "limit or stop entry price"

api.orderModify(id, stoploss, takeprofit, price)

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.1.0.tar.gz (27.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ejtraderCT-1.1.0-py3-none-any.whl (26.5 kB view details)

Uploaded Python 3

File details

Details for the file ejtraderCT-1.1.0.tar.gz.

File metadata

  • Download URL: ejtraderCT-1.1.0.tar.gz
  • Upload date:
  • Size: 27.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for ejtraderCT-1.1.0.tar.gz
Algorithm Hash digest
SHA256 f708fb75887d9c5efc2299b88cf7e7aba7c6de86025701242f023c96fd7577ec
MD5 ad5ab62ec2a3dd10c9114d27a52263c0
BLAKE2b-256 09a8b14502cfe578454e97ddfe322e5f47039617e95a5101e0ec897000f4cc4e

See more details on using hashes here.

File details

Details for the file ejtraderCT-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: ejtraderCT-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for ejtraderCT-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b4bf2257d9a8b0fb0e62fd6a923cd04cf874988fb951ae0c46e37409a72cfc47
MD5 3423ca6ddcd42ddcb9e782dba3a32d71
BLAKE2b-256 44959a155ba502c9d42164756532bc6d61ecbf31c3da6ae03903392ca03316c1

See more details on using hashes here.

Supported by

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