# jetblack-fixparser
A parser for FIX messages.
## Installation
The package can be installed with `pip`.
```bash
pip install jetblack-fixparser
```
## Protocol Files
While FIX is a standard, the structure of the fields and messages is configurable.
This configuration is typically loaded from a file. The source repository
contains a number of such files in the `/etc` folder in `YAML` format. There is
also a *QuickFix* loader.
The YAML format makes use of defaults. All message fields default to type `field`,
so only `group` and `component` fields need to be explicitly specified. Also all
message fields are consider optional, non-optional fields must be marked as
`required: true`.
## Usage
### Decoding
To decode a FIX bytes buffer -
```python
from jetblack_fixparser import load_yaml_protocol, FixMessage
buffer = b'8=FIX.4.4|9=94|35=3|49=A|56=AB|128=B1|34=214|50=U1|52=20100304-09:42:23.130|45=176|371=15|372=X|373=1|58=txt|10=058|',
protocol = load_yaml_protocol(
'FIX44.yaml',
is_millisecond_time=True,
is_float_decimal=True
)
fix_message = FixMessage.decode(
protocol,
buffer,
sep=b'|',
strict=True,
validate=True,
convert_sep_for_checksum=True
)
print(fix_message.message)
```
Note that strict validation is enabled. This ensures all required fields are
specified. Also the separator is changed from `NULL` to `|` to so they can be
displayed. However the checksum was calculated with the original field separator
so the `convert_sep_for_checksum` is set to `true`.
### Encoding
To encode a dictionary describing a FIX message -
```python
from datetime import datetime, timezone
from jetblack_fixparser import load_yaml_protocol, FixMessage
protocol = load_yaml_protocol(
'FIX44.yaml',
is_millisecond_time=True,
is_float_decimal=True,
is_type_enum=None
)
sending_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=timezone.utc)
fix_message = FixMessage(
protocol,
{
'MsgType': 'LOGON',
'MsgSeqNum': 42,
'SenderCompID': "SENDER",
'TargetCompID': "TARGET",
'SendingTime': sending_time,
'EncryptMethod': "NONE",
'HeartBtInt': 30
}
)
buffer = fix_message.encode(regenerate_integrity=True)
print(buffer)
```
Note that the `BeginString`, `BodyLength` and `Checksum` fields were automatically
generated.
### Factories
To encode and decode a message using a factory -
```python
from datetime import datetime, timezone
from jetblack_fixparser import load_yaml_protocol, FixMessage, FixMessageFactory
protocol = load_yaml_protocol(
'FIX44.yaml',
is_millisecond_time=True,
is_float_decimal=True,
is_type_enum=None
)
factory = FixMessageFactory(protocol, "SENDER", "TARGET")
sending_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=timezone.utc)
fix_messages = factory.create(
'LOGON',
42,
sending_time,
{
'EncryptMethod': "NONE",
'HeartBtInt': 30
}
)
buffer = fix_message.encode(regenerate_integrity=True)
roundtrip = FixMessage.decode(protocol, buffer)
assert fix_message.message == roundtrip.message
```
Because the sender and target remain the same, we can simplify message generation
with the factory.
Raw data
{
"_id": null,
"home_page": "https://github.com/rob-blackbourn/jetblack-fixparser",
"name": "jetblack-fixparser",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "Rob Blackbourn",
"author_email": "rob.blackbourn@googlemail.com",
"download_url": "https://files.pythonhosted.org/packages/d8/8c/5e7cb0efb487980a757ab5e57e13711a19e19be0f507a9fcac288db63a8d/jetblack-fixparser-2.4.0.tar.gz",
"platform": null,
"description": "# jetblack-fixparser\n\nA parser for FIX messages.\n\n## Installation\n\nThe package can be installed with `pip`.\n\n```bash\npip install jetblack-fixparser\n```\n\n## Protocol Files\n\nWhile FIX is a standard, the structure of the fields and messages is configurable.\nThis configuration is typically loaded from a file. The source repository\ncontains a number of such files in the `/etc` folder in `YAML` format. There is\nalso a *QuickFix* loader.\n\nThe YAML format makes use of defaults. All message fields default to type `field`,\nso only `group` and `component` fields need to be explicitly specified. Also all\nmessage fields are consider optional, non-optional fields must be marked as\n`required: true`.\n\n## Usage\n\n### Decoding\n\nTo decode a FIX bytes buffer -\n\n```python\nfrom jetblack_fixparser import load_yaml_protocol, FixMessage\n\nbuffer = b'8=FIX.4.4|9=94|35=3|49=A|56=AB|128=B1|34=214|50=U1|52=20100304-09:42:23.130|45=176|371=15|372=X|373=1|58=txt|10=058|',\n\nprotocol = load_yaml_protocol(\n 'FIX44.yaml',\n is_millisecond_time=True,\n is_float_decimal=True\n)\n\nfix_message = FixMessage.decode(\n protocol,\n buffer,\n sep=b'|',\n strict=True,\n validate=True,\n convert_sep_for_checksum=True\n)\n\nprint(fix_message.message)\n```\n\nNote that strict validation is enabled. This ensures all required fields are\nspecified. Also the separator is changed from `NULL` to `|` to so they can be\ndisplayed. However the checksum was calculated with the original field separator\nso the `convert_sep_for_checksum` is set to `true`.\n\n### Encoding\n\nTo encode a dictionary describing a FIX message - \n\n```python\nfrom datetime import datetime, timezone\nfrom jetblack_fixparser import load_yaml_protocol, FixMessage\n\nprotocol = load_yaml_protocol(\n 'FIX44.yaml',\n is_millisecond_time=True,\n is_float_decimal=True,\n is_type_enum=None\n)\nsending_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=timezone.utc)\n\nfix_message = FixMessage(\n protocol,\n {\n 'MsgType': 'LOGON',\n 'MsgSeqNum': 42,\n 'SenderCompID': \"SENDER\",\n 'TargetCompID': \"TARGET\",\n 'SendingTime': sending_time,\n 'EncryptMethod': \"NONE\",\n 'HeartBtInt': 30\n }\n)\nbuffer = fix_message.encode(regenerate_integrity=True)\n\nprint(buffer)\n```\n\nNote that the `BeginString`, `BodyLength` and `Checksum` fields were automatically\ngenerated.\n\n### Factories\n\nTo encode and decode a message using a factory - \n\n```python\nfrom datetime import datetime, timezone\nfrom jetblack_fixparser import load_yaml_protocol, FixMessage, FixMessageFactory\n\nprotocol = load_yaml_protocol(\n 'FIX44.yaml',\n is_millisecond_time=True,\n is_float_decimal=True,\n is_type_enum=None\n)\n\nfactory = FixMessageFactory(protocol, \"SENDER\", \"TARGET\")\n\nsending_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=timezone.utc)\nfix_messages = factory.create(\n 'LOGON',\n 42,\n sending_time,\n {\n 'EncryptMethod': \"NONE\",\n 'HeartBtInt': 30\n }\n )\n\nbuffer = fix_message.encode(regenerate_integrity=True)\nroundtrip = FixMessage.decode(protocol, buffer)\nassert fix_message.message == roundtrip.message\n```\n\nBecause the sender and target remain the same, we can simplify message generation\nwith the factory.\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "A parser for FIX messages",
"version": "2.4.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ee9c31fe100913f3f70a87968bf9d83cd4f733f5bc477603a08cfe4176be2fa9",
"md5": "405f36962ca956805f7de5ab56565862",
"sha256": "d0ab2ff810e0fcc9e85a05f524734b79bfff30b803e32dc00e5d3f31a3a40521"
},
"downloads": -1,
"filename": "jetblack_fixparser-2.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "405f36962ca956805f7de5ab56565862",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 28224,
"upload_time": "2023-04-02T11:29:19",
"upload_time_iso_8601": "2023-04-02T11:29:19.436398Z",
"url": "https://files.pythonhosted.org/packages/ee/9c/31fe100913f3f70a87968bf9d83cd4f733f5bc477603a08cfe4176be2fa9/jetblack_fixparser-2.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d88c5e7cb0efb487980a757ab5e57e13711a19e19be0f507a9fcac288db63a8d",
"md5": "f1f81832a5d516bc26cedd8f9814f1fc",
"sha256": "3e0b84c9e982c83e03621caf4adf6907833ceecbe0337814a41bed0ebfb9a666"
},
"downloads": -1,
"filename": "jetblack-fixparser-2.4.0.tar.gz",
"has_sig": false,
"md5_digest": "f1f81832a5d516bc26cedd8f9814f1fc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 20666,
"upload_time": "2023-04-02T11:29:17",
"upload_time_iso_8601": "2023-04-02T11:29:17.111739Z",
"url": "https://files.pythonhosted.org/packages/d8/8c/5e7cb0efb487980a757ab5e57e13711a19e19be0f507a9fcac288db63a8d/jetblack-fixparser-2.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-02 11:29:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "rob-blackbourn",
"github_project": "jetblack-fixparser",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "jetblack-fixparser"
}