Skip to content

feat: expose parsing so that user can reuse it#39

Merged
qualiaenjoyer merged 3 commits intoqualiaenjoyer:mainfrom
MAKMED1337:expose-event-parsing
Mar 4, 2026
Merged

feat: expose parsing so that user can reuse it#39
qualiaenjoyer merged 3 commits intoqualiaenjoyer:mainfrom
MAKMED1337:expose-event-parsing

Conversation

@MAKMED1337
Copy link
Contributor

Fixes: #33
However I need to discuss 2 questions:

  1. Throw errors vs use logger
  2. Should we inject parse message inside callback, like process_event(parse_market_event(cast("Text", event)))? In this case it makes callback easier to use, but it erases some error information. We can also generalize it to return Text only in the case when parsing was unsuccessful, like def cb(event: MarketEvents | Text).

@MAKMED1337 MAKMED1337 marked this pull request as draft March 4, 2026 13:16
@qualiaenjoyer
Copy link
Owner

hmm, I think I'll accept this for now and decide later about your points.

@MAKMED1337
Copy link
Contributor Author

So, do you want to undraft it?

@qualiaenjoyer qualiaenjoyer marked this pull request as ready for review March 4, 2026 22:12
…t cast in eip712

switched to  mappings to help mypy
@qualiaenjoyer
Copy link
Owner

so I set it up to not log/print empty strings for now. also, lomond (the ws library) automatically pings and reconnects.

@MAKMED1337
Copy link
Contributor Author

I am a little bit confused about pyrefly, how do you run it?

uv run ruff check --fix; uv run python -m mypy . --strict; uv run pyrefly check
All checks passed!
Success: no issues found in 33 source files
 INFO Checking project configured at `/mnt/nvme/projects/polymarket-apis/pyproject.toml`
 WARN Redundant cast: `HexStr` is the same type as `HexStr` [redundant-cast]
  --> src/polymarket_apis/utilities/signing/eip712.py:28:28
   |
28 |       auth_struct_hash = cast(
   |  ____________________________-
29 | |         "HexStr",
30 | |         prepend_zx(
31 | |             keccak(clob_auth_msg.signable_bytes(get_clob_auth_domain(chain_id))).hex(),
32 | |         ),
33 | |     )
   | |_____-
   |
 WARN Redundant cast: `HexStr` is the same type as `HexStr` [redundant-cast]
  --> src/polymarket_apis/utilities/signing/eip712.py:34:16
   |
34 |       return cast(
   |  ________________-
35 | |         "HexStr", prepend_zx(signer.sign(auth_struct_hash))
36 | |     )
   | |_____-
   |
 INFO 0 errors

@MAKMED1337
Copy link
Contributor Author

Why to use Mapping instead of dict? And I also propose exposing these types from type/__init__.py

@qualiaenjoyer
Copy link
Owner

I do uv run pyrefly check as well

@qualiaenjoyer
Copy link
Owner

expose MarketEvents, UserEvents, LiveDataEvents?

@MAKMED1337
Copy link
Contributor Author

expose MarketEvents, UserEvents, LiveDataEvents?

Yes

@MAKMED1337
Copy link
Contributor Author

I do uv run pyrefly check as well

Maybe check uv run which pyrefly
For my case it is inside the venv /mnt/nvme/projects/polymarket-apis/.venv/bin/pyrefly

Also check this:

┌─[makmed1337@MAKMED1337] - [~/projects/polymarket-apis] - [чт бер 05, 00:30]
└─[$] <git:(expose-event-parsing*)> uv run pyrefly -v dump-config
 INFO Checking project configured at `/mnt/nvme/projects/polymarket-apis/pyproject.toml`
DEBUG Config is: {source: File("/mnt/nvme/projects/polymarket-apis/pyproject.toml"), project_includes: [/mnt/nvme/projects/polymarket-apis/**/*.py*, /mnt/nvme/projects/polymarket-apis/**/*.ipynb], project_excludes: [**/node_modules, **/__pycache__, **/venv/**/*, **/.[!/.]*/**/*, /mnt/nvme/projects/polymarket-apis/.venv/lib/python3.13/site-packages], search_path: [/mnt/nvme/projects/polymarket-apis/src], python_interpreter_path: Some(Auto("/mnt/nvme/projects/polymarket-apis/.venv/bin/python")), python_environment: {python_platform: linux, python_version: 3.12.0, site_package_path: [], interpreter_site_package_path: [/mnt/nvme/projects/polymarket-apis/.venv/lib/python3.13/site-packages, /mnt/nvme/projects/polymarket-apis/src], interpreter_stdlib_path: [/home/makmed1337/.local/share/uv/python/cpython-3.13.11-linux-x86_64-gnu/lib/python3.13]}, replace_imports_with_any: [], ignore_missing_imports: []}
DEBUG opened gitignore file: /mnt/nvme/projects/polymarket-apis/.gitignore
DEBUG glob `Glob("**/*.py[oc]")` converted to regex: `"(?-u)^(?:/?|.*/)[^/]*\\.py[oc]$"`
DEBUG built glob set; 0 literals, 5 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 1 regexes
DEBUG opened gitignore file: /mnt/nvme/projects/polymarket-apis/.git/info/exclude
Configuration at `/mnt/nvme/projects/polymarket-apis/pyproject.toml`
  Using interpreter: /mnt/nvme/projects/polymarket-apis/.venv/bin/python
  Covered files:
    /mnt/nvme/projects/polymarket-apis/src/polymarket_apis/__init__.py
    /mnt/nvme/projects/polymarket-apis/src/polymarket_apis/clients/__init__.py
    /mnt/nvme/projects/polymarket-apis/src/polymarket_apis/clients/clob_client.py
    /mnt/nvme/projects/polymarket-apis/src/polymarket_apis/clients/data_client.py
    /mnt/nvme/projects/polymarket-apis/src/polymarket_apis/clients/gamma_client.py
    /mnt/nvme/projects/polymarket-apis/src/polymarket_apis/clients/graphql_client.py
    /mnt/nvme/projects/polymarket-apis/src/polymarket_apis/clients/web3_client.py
    /mnt/nvme/projects/polymarket-apis/src/polymarket_apis/clients/websockets_client.py
    /mnt/nvme/projects/polymarket-apis/src/polymarket_apis/types/__init__.py
    /mnt/nvme/projects/polymarket-apis/src/polymarket_apis/types/clob_types.py
    ...and 23 more
  Resolving imports from:
    Import root (inferred from project layout): "/mnt/nvme/projects/polymarket-apis/src"
    Site package path queried from interpreter: ["/mnt/nvme/projects/polymarket-apis/.venv/lib/python3.13/site-packages", "/mnt/nvme/projects/polymarket-apis/src"]
┌─[makmed1337@MAKMED1337] - [~/projects/polymarket-apis] - [чт бер 05, 00:31]
└─[$] <git:(expose-event-parsing*)> uv run pyrefly --version     
pyrefly 0.54.0

@qualiaenjoyer
Copy link
Owner

Why to use Mapping instead of dict? And I also propose exposing these types from type/__init__.py

iirc mypy treats it as read only or something. dict should work as well, but mypy probably interprets it as mutable

@MAKMED1337
Copy link
Contributor Author

Why to use Mapping instead of dict? And I also propose exposing these types from type/__init__.py

iirc mypy treats it as read only or something. dict should work as well, but mypy probably interprets it as mutable

I didn't know, then it's fine

@qualiaenjoyer
Copy link
Owner

uv run pyrefly --version

also use .venv inside project, config and version look identical

@MAKMED1337
Copy link
Contributor Author

uv run pyrefly --version

also use .venv inside project, config and version look identical

uv run pyrefly --version

also use .venv inside project, config and version look identical

I frankly have no idea, you can merge

@qualiaenjoyer qualiaenjoyer merged commit 8b6cbdf into qualiaenjoyer:main Mar 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

websockets_client callback should be passed to the default handler

2 participants