Skip to main content

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

  1. Arguments passed to Flexemarkets.connect()
  2. Files ~/.fm/credential and ~/.fm/endpoint (Java .properties format)
  3. Environment variable FM_API_URL (defaults to https://api.flexemarkets.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://api.flexemarkets.com/api/marketplaces/123

SDK usage

from fm import Flexemarkets, OrderBooks, MarketplaceTrades

# Connect
fm = Flexemarkets.connect(
    credential="~/.fm/credential",
    endpoint="https://api.flexemarkets.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://api.flexemarkets.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

fm_sdk-0.0.3.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

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

fm_sdk-0.0.3-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

File details

Details for the file fm_sdk-0.0.3.tar.gz.

File metadata

  • Download URL: fm_sdk-0.0.3.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fm_sdk-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c343ceeb23e0468a038c9fb69222c3c61f83bd545e7656441caaa62c65d78a92
MD5 44ac42f95dcc6ceb33b04d3b40373bc5
BLAKE2b-256 d1529cc15328c029c79ec7e29600c1c0e3d841b8fa237582c13781825ce26e3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for fm_sdk-0.0.3.tar.gz:

Publisher: release.yml on flexemarkets/fm-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fm_sdk-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: fm_sdk-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 28.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fm_sdk-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 725df1a305af5c226ce70e33fd2d988426552c3513c87b35073eb1e5e3f8e195
MD5 2462c205a488c5e91b12347b68f6b6dd
BLAKE2b-256 e5781b0d3703b6767332a19ff7662b00c2dd11cc2965a1c76aef9c16f8b5e6e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for fm_sdk-0.0.3-py3-none-any.whl:

Publisher: release.yml on flexemarkets/fm-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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