Python SDK for the Flexemarkets API
Project description
fm-sdk-python
Python SDK for the Flexemarkets API.
Requirements
- Python 3.11+
Install
python3.11 -m pip install .
Or install dependencies directly:
python3.11 -m pip install httpx websockets
Configuration
The SDK loads credentials and endpoint from these sources (highest priority first):
- Arguments passed to
Flexemarkets.connect() - Files
~/.fm/credentialand~/.fm/endpoint(Java.propertiesformat) - Environment variable
FM_API_URL(defaults tohttps://fm-data.herokuapp.com)
Credential file
Create ~/.fm/credential:
account=myaccount
email=user@example.com
password=secret
Or use a bearer token:
token=eyJhbGciOiJIUzI1NiJ9...
Endpoint file
Create ~/.fm/endpoint:
endpoint=https://fm-data.herokuapp.com/api/marketplaces/123
SDK usage
from fm import Flexemarkets, OrderBooks, MarketplaceTrades
# Connect
fm = Flexemarkets.connect(
credential="~/.fm/credential",
endpoint="https://fm-data.herokuapp.com/api/marketplaces/123",
client_description="my-bot",
)
# REST API
marketplace_id = fm.endpoint_marketplace_id
markets = fm.markets(marketplace_id)
session = fm.session(marketplace_id)
holdings = fm.holdings(marketplace_id)
# Submit orders
order = fm.submit_limit(marketplace_id, market_id, "BUY", units=1, price=950)
fm.submit_cancel(marketplace_id, market_id, order.id)
# WebSocket events
import queue
q = queue.Queue(maxsize=1000)
fm.listen(marketplace_id, q)
books = OrderBooks(markets)
trades = MarketplaceTrades(markets)
while True:
event = q.get()
match event:
case list() as orders:
books.update(orders)
trades.update(orders)
case Session() as s:
print(s.state)
case Holding() as h:
print(h.cash)
fm.close()
The client also works as a context manager:
with Flexemarkets.connect(credential, endpoint, "my-bot") as fm:
...
Applications
ticker
Live terminal display of order book best bid/ask, spread, and recent trade prices.
python3.11 ticker.py -C ~/.fm/credential -E https://fm-data.herokuapp.com/api/marketplaces/123
Options:
| Flag | Description |
|---|---|
-C, --credential |
Credential file path or bearer token |
-E, --endpoint |
Marketplace endpoint file path or URL |
Output:
fm-ticker OPEN
Symbol Bid Ask Spread Last trades
------ ------ ------ ------ -----------
AAPL $ 9.50 $10.50 $ 1.00 $9.50 $10.00
IBM $ 4.00 $ 5.00 $ 1.00 $4.50
The display refreshes on each order book update. Press Ctrl-C to stop.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fm_sdk-0.0.1.tar.gz.
File metadata
- Download URL: fm_sdk-0.0.1.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f057c0ec7b7aa4657946ac4dceb6e4e13c482c3b3ca325d2a9114f28b005efaa
|
|
| MD5 |
a3b783ac56ca403390ca6b5031d19123
|
|
| BLAKE2b-256 |
8ffa421e977265f66289e94a69ac53d72e01e6bce9feadf9c90d2190d6568fa9
|
Provenance
The following attestation bundles were made for fm_sdk-0.0.1.tar.gz:
Publisher:
release.yml on JanStureNielsen/fm-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fm_sdk-0.0.1.tar.gz -
Subject digest:
f057c0ec7b7aa4657946ac4dceb6e4e13c482c3b3ca325d2a9114f28b005efaa - Sigstore transparency entry: 975316842
- Sigstore integration time:
-
Permalink:
JanStureNielsen/fm-sdk@0d59699380bb79e65fd410d8976c21ce94e32ab5 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/JanStureNielsen
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0d59699380bb79e65fd410d8976c21ce94e32ab5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fm_sdk-0.0.1-py3-none-any.whl.
File metadata
- Download URL: fm_sdk-0.0.1-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
436737ba5fc5ce7ec6f27a70fd6a6a8c417ec418d1166c78299683c0eb878530
|
|
| MD5 |
06c25e77e5977f2d4ca9e6590c54f055
|
|
| BLAKE2b-256 |
0d017910d11f8084621738660dc7f177d9d1528940b3fc9edb75bc9dd3bce9ae
|
Provenance
The following attestation bundles were made for fm_sdk-0.0.1-py3-none-any.whl:
Publisher:
release.yml on JanStureNielsen/fm-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fm_sdk-0.0.1-py3-none-any.whl -
Subject digest:
436737ba5fc5ce7ec6f27a70fd6a6a8c417ec418d1166c78299683c0eb878530 - Sigstore transparency entry: 975316845
- Sigstore integration time:
-
Permalink:
JanStureNielsen/fm-sdk@0d59699380bb79e65fd410d8976c21ce94e32ab5 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/JanStureNielsen
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0d59699380bb79e65fd410d8976c21ce94e32ab5 -
Trigger Event:
push
-
Statement type: