Skip to main content

autotrade-mofid

Python library for buy, sell, edit, and cancel limit orders on Mofid EasyTrader.

from autotrade import buy, sell

buy("فولاد", 10, dry_run=True)          # prepare only
buy("تمشک", 92, price_mode="fixed", price=54370)
sell("تمشک", 92, price_mode="fixed", price=54360)

Login uses Playwright; orders go over EasyTrader’s unofficial MTS HTTP API.

Automates real money. Start with dry_run=True. Use at your own risk.

Install into another project

pip install autotrade-mofid
playwright install chrome

Optional CLI (python -m autotrade …):

pip install "autotrade-mofid[cli]"

Set credentials in the environment or a .env next to your app:

export MOFID_USER=…
export MOFID_PASS=…
# or: export AUTOTRADE_ENV=/path/to/.env

Or pass them per call:

from autotrade import buy

buy("فولاد", 1, dry_run=True, username="09…", password="…")

API

Call Purpose
buy(symbol, qty, **opts) Buy helper
sell(symbol, qty, **opts) Sell helper
list_orders(**opts) Open and today's orders
edit_order(order_id, **opts) Modify the unfilled remainder
cancel_order(order_id, **opts) Cancel, then confirm
Order / place_order / with_account Lower-level control
OrderError Bad arguments, or the order cannot be edited or cancelled
TradeError Broker rejected the request, or a cancel was not confirmed

Common options for buy / sell:

  • price_mode — auto (default), ceiling, floor, reference, fixed
  • price — Rial; required for fixed
  • target_time — "now" (default) or "HH:MM:SS" on the broker clock
  • dry_run — prepare only, no submit
  • username / password — both together, or omit both and use env / .env
from autotrade import Order, get_settings, place_order, with_account

account = with_account(get_settings())
order = Order.resolve(
    account,
    side="buy",
    symbol="فولاد",
    quantity=10,
    price_mode="auto",
    target_time="08:44:58",
    dry_run=True,
)
place_order(order, account)

Orders, edit, and cancel

python -m autotrade orders
python -m autotrade edit --order-id ID --price-mode ceiling
python -m autotrade edit --order-id ID -p 4540 -q 10 --dry-run
python -m autotrade cancel --order-id ID
python -m autotrade cancel --order-id ID --dry-run

orders prints id, symbol, side, qty, filled, price, and status for the broker's open and today's order list.

edit changes only the unfilled remainder. A fully executed or cancelled order is refused before any modify request. --price-mode uses the same ceiling, floor, reference, and fixed prices as buy/sell (auto follows the order's side). The new price must sit in the symbol's daily band, the open quantity must match the lot size (and the price step, when the symbol has one), and the open notional must be at least 5,000,000 Rial. --dry-run prints the request and does not send it.

cancel calls the delete endpoint once, then reads the order list. If the broker reports the cancel as still in progress, the command keeps reading until the order is gone or cancelled. It does not send the cancel again. The filled quantity is reported either way. If the order is still open after that wait, the command stops.

from autotrade import cancel_order, edit_order, list_orders

list_orders()
edit_order("1121…", price_mode="fixed", price=4540, quantity=10, dry_run=True)
cancel_order("1121…", dry_run=True)

Exit code 2 is a bad request (missing id, order not open). Exit code 1 is a broker rejection or a cancel that could not be confirmed.

Endpoints

EasyTrader 2.6.1 sends these from the order ticket. Login still harvests the bearer token; these calls are plain HTTP, same as buy and sell.

Action Request Body
List GET /core/api/order —
Edit PUT /core/api/v2/order { "modifyOrder": { "parentId": "<current order id>", "id": null, "price", "quantity", "side", "validityType", "createDateTime", "commission", "symbolIsin", "symbolName", "orderModelType": 1, "totalValue", "orderFrom": 34 } }
Cancel DELETE /core/api/v2/delete-order { "orderId": "<id>", "orderFrom": 34 }

quantity on an edit is the new open quantity (the unfilled remainder, or -q). parentId is the id of the order being replaced. The web app leaves id null and does not send the host serial (hon). A create-shaped body ({"order": ...} without parentId) is what the broker rejects as a missing parent order id.

Develop this repo

python3.15 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
playwright install chrome
cp .env.example .env
pytest -q

If Chrome is missing, install Chromium and switch channel="chrome" → channel="chromium" in autotrade/browser.py.

How it works

  1. Reuse a cached JWT, or log in with Playwright and harvest Authorization: Bearer …
  2. Resolve symbol → ISIN, live quote, commission
  3. Wait for the broker clock when target_time is not "now"
  4. Submit POST /core/api/v2/order until accepted (or a hard rejection)
  5. Treat success as order still on the book or cash moved

Changelog

See CHANGELOG.md.

Licence

MIT

Metadata

Release files for autotrade-mofid 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for autotrade-mofid 0.2.0
File Size Uploaded Provenance Actions
autotrade_mofid-0.2.0.tar.gz 43.2 kB With provenance Details for autotrade_mofid-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for autotrade-mofid 0.2.0
File Interpreter ABI Platform Actions
autotrade_mofid-0.2.0-py3-none-any.whl Python 3 none any Details for autotrade_mofid-0.2.0-py3-none-any.whl

Total release size: 84.1 kB

Release files / autotrade_mofid-0.2.0.tar.gz

Download URL autotrade_mofid-0.2.0.tar.gz
Size 43.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8fc689a13f6932179a6c527dcad8fb199edb91a52e59445de96f5961dce4522a
BLAKE2b-256 checksum
How to use checksums
d40f2b2c316754b45145b0a5c6177407c37e1d087638ce8432c26ac446e6be9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / autotrade_mofid-0.2.0-py3-none-any.whl

Download URL autotrade_mofid-0.2.0-py3-none-any.whl
Size 40.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fcd641bc3e0bc7058c367795abfced08ebc722b57e3f52428779e44880ee2aba
BLAKE2b-256 checksum
How to use checksums
3739b04ac1fff42146d3f9e8db3dd2373b0906b2cb97d8cf51c9f874b8ed423d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Security for autotrade-mofid 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for autotrade_mofid-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page