Metadata-Version: 2.4
Name: fivesocket
Version: 0.1.0
Summary: Zero-dependency Python client for MetaTrader 5 over FiveSocket's hosted REST API. Works on macOS, Linux, Docker, and Windows.
Author-email: FiveSocket <hello@fivesocket.com>
License: MIT
Project-URL: Homepage, https://fivesocket.com
Project-URL: Documentation, https://docs.fivesocket.com/python
Project-URL: Repository, https://github.com/fivesocket/fivesocket-python
Keywords: mt5,metatrader5,mt5-api,forex,trading,prop-firm,backtesting
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Office/Business :: Financial :: Investment
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# fivesocket-python

Call your MetaTrader 5 account from Python on macOS, Linux, Docker, or Windows over HTTPS. No Windows PC, no VPS, no Wine setup, and no open MT5 terminal.

If you have ever run `pip install MetaTrader5` on a Mac or a Linux container and hit `No matching distribution found for MetaTrader5`, this is the hosted alternative. MetaQuotes only ships Windows wheels for the official package. FiveSocket runs the MT5 terminal on our side and exposes your broker account through a standard REST API.

This package uses Python's standard library only. Nothing to compile, no C extensions, no dependencies.

## What you can do with it

- Read live balance, equity, margin, open positions, closed trades, and broker candles straight into pandas.
- Check prop-firm drawdown headroom for FTMO, FundedNext, and The5ers before placing a trade.
- Run bar-based strategy backtests on your own broker's candle history.
- Submit, modify, and close orders with `Idempotency-Key` protection and automatic polling when an order returns `commit_unknown`. Every order sent through FiveSocket is checked against your per-symbol volume caps and prop-firm rules first.

## Install

```bash
pip install fivesocket
```

Or copy `fivesocket/client.py` directly into your project. It is one file and needs Python 3.10+.

## Quick start

1. Create an account at [fivesocket.com](https://fivesocket.com) and link an MT5 demo or live account in the browser. You get 7 days of free usage with no card required after linking.
2. Create an API key in the dashboard (`read` scope for data, `trading:execute` if you want to place orders).
3. Export your key and account ID:

```bash
export FIVESOCKET_KEY="mt5_live_..."
export FIVESOCKET_ACCOUNT_ID="acc_..."
```

4. Read your balance, positions, and candles:

```python
from fivesocket import FiveSocket

client = FiveSocket()
account_id = "acc_..."

print(client.get_balance(account_id))
print(client.list_positions(account_id))

candles = client.get_candles(account_id, symbol="EURUSD", timeframe="H1", count=100)
print(candles["candles"][-1])
```

## Placing orders safely

FiveSocket requires an `Idempotency-Key` header on order writes and uses decimal strings for `volume` and prices so floating-point rounding never slips into a live lot size.

```python
from fivesocket import FiveSocket

client = FiveSocket()
result = client.submit_order(
    "acc_...",
    symbol="EURUSD",
    side="buy",
    volume="0.01",
    order_type="market",
)
print(result)
```

If the broker link drops mid-flight, FiveSocket returns HTTP 202 with `outcome: "commit_unknown"` and a `commandId`. Never fire a second market order when that happens. `submit_order` polls `GET /v1/accounts/{accountId}/execution/commands/{commandId}` for you until the broker confirms the final state.

Remember to test on a demo account first and configure your symbol allowlist and max volume caps before enabling `trading:execute`.

## Checking prop-firm limits

```python
status = client.get_prop_status("acc_...")
print(status)
```

If you want to check daily loss and max drawdown math before connecting an account, we also publish free browser calculators at [fivesocket.com/tools](https://fivesocket.com/tools).

## When you should not use this

If you need sub-millisecond co-located HFT or you want to run compiled `.ex5` Expert Advisors directly on an MT5 chart, rent a Windows VPS near your broker. FiveSocket is built for Python bots, n8n/TradingView relays, backtests, and AI assistants where maintaining a Windows box is the wrong job.

## Examples and tests

Run the unit tests locally:

```bash
python3 -m unittest discover -s tests
```

See [`examples/`](examples) for ready-to-run scripts covering account reads, pandas DataFrames, and market orders.

## Links

- Python guide: [fivesocket.com/mt5-api-python](https://fivesocket.com/mt5-api-python)
- MT5 on Mac guide: [fivesocket.com/metatrader5-python-mac](https://fivesocket.com/metatrader5-python-mac)
- Full REST API reference: [docs.fivesocket.com](https://docs.fivesocket.com)
- Hosted MT5 MCP server (Claude, ChatGPT, Cursor): [fivesocket/mt5-mcp-server](https://github.com/fivesocket/mt5-mcp-server)
- TradingView webhook relay: [fivesocket/tradingview-mt5-webhook](https://github.com/fivesocket/tradingview-mt5-webhook)

## License

MIT. See [LICENSE](LICENSE).
