-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add get_order_book_changes * return real delta from _calculate_delta
- Loading branch information
1 parent
56c1270
commit b7dfe75
Showing
15 changed files
with
1,164 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
tests/unit/utils/txn_parser/test_get_order_book_changes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
from unittest import TestCase | ||
|
||
from xrpl.utils import get_order_book_changes | ||
|
||
path_to_json = "tests/unit/utils/txn_parser/transaction_jsons/" | ||
with open(path_to_json + "offer_created.json", "r") as infile: | ||
offer_created = json.load(infile) | ||
with open(path_to_json + "offer_partially_filled_and_filled.json", "r") as infile: | ||
offer_partially_filled_and_filled = json.load(infile) | ||
with open(path_to_json + "offer_cancelled.json", "r") as infile: | ||
offer_cancelled = json.load(infile) | ||
with open(path_to_json + "offer_with_expiration.json", "r") as infile: | ||
offer_with_expiration = json.load(infile) | ||
|
||
|
||
class TestGetOrderBookChanges(TestCase): | ||
def test_offer_created(self: TestGetOrderBookChanges): | ||
actual = get_order_book_changes(offer_created["meta"]) | ||
expected = [ | ||
{ | ||
"maker_account": "rJHbqhp9Sea4f43RoUanrDE1gW9MymTLp9", | ||
"offer_changes": [ | ||
{ | ||
"flags": 131072, | ||
"taker_gets": {"currency": "XRP", "value": "44.930000"}, | ||
"taker_pays": { | ||
"currency": "USD", | ||
"issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", | ||
"value": "14.524821", | ||
}, | ||
"sequence": 71307620, | ||
"status": "created", | ||
"maker_exchange_rate": "0.3232766748275094591586912976", | ||
"expiration_time": 740218424, | ||
} | ||
], | ||
} | ||
] | ||
self.assertEqual(actual, expected) | ||
|
||
def test_offer_partially_filled_and_filled(self: TestGetOrderBookChanges): | ||
actual = get_order_book_changes(offer_partially_filled_and_filled["meta"]) | ||
expected = [ | ||
{ | ||
"maker_account": "rNzgS71DyJPMnWMA8aS7NqvXP7bNuwyaZo", | ||
"offer_changes": [ | ||
{ | ||
"flags": 131072, | ||
"taker_gets": { | ||
"currency": "USD", | ||
"issuer": "rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq", | ||
"value": "-63.7479881398749", | ||
}, | ||
"taker_pays": { | ||
"currency": "USD", | ||
"issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", | ||
"value": "-62.4730283770749", | ||
}, | ||
"sequence": 5931, | ||
"status": "filled", | ||
"maker_exchange_rate": "0.9799999999999607517025555356", | ||
} | ||
], | ||
}, | ||
{ | ||
"maker_account": "rPu2feBaViWGmWJhvaF5yLocTVD8FUxd2A", | ||
"offer_changes": [ | ||
{ | ||
"flags": 131072, | ||
"taker_gets": { | ||
"currency": "USD", | ||
"issuer": "rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq", | ||
"value": "-117.3895136925395", | ||
}, | ||
"taker_pays": { | ||
"currency": "USD", | ||
"issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", | ||
"value": "-115.0877585220975", | ||
}, | ||
"sequence": 67701941, | ||
"status": "partially-filled", | ||
"maker_exchange_rate": "0.980392156862744680458408839", | ||
} | ||
], | ||
}, | ||
] | ||
self.assertEqual(actual, expected) | ||
|
||
def test_offer_cancelled(self: TestGetOrderBookChanges): | ||
actual = get_order_book_changes(offer_cancelled["meta"]) | ||
expected = [ | ||
{ | ||
"maker_account": "rEUt5Wy44vDKBDaGkUWG6oSTvxmqgnKWCg", | ||
"offer_changes": [ | ||
{ | ||
"flags": 0, | ||
"taker_gets": { | ||
"currency": "XDX", | ||
"issuer": "rMJAXYsbNzhwp7FfYnAsYP5ty3R9XnurPo", | ||
"value": "-82335.52909", | ||
}, | ||
"taker_pays": {"currency": "XRP", "value": "-47.504858"}, | ||
"sequence": 70922543, | ||
"status": "cancelled", | ||
"maker_exchange_rate": "0.0005769666937838341642215588998", | ||
} | ||
], | ||
} | ||
] | ||
self.assertEqual(actual, expected) | ||
|
||
def test_offer_with_expiration(self: TestGetOrderBookChanges): | ||
actual = get_order_book_changes(offer_with_expiration["meta"]) | ||
expected = [ | ||
{ | ||
"maker_account": "rJHHRtt6qmiz71tyGFMZUoxMGakdgqEou5", | ||
"offer_changes": [ | ||
{ | ||
"flags": 0, | ||
"taker_gets": {"currency": "XRP", "value": "-50.000000"}, | ||
"taker_pays": { | ||
"currency": "457175696C69627269756D000000000000000000", | ||
"issuer": "rpakCr61Q92abPXJnVboKENmpKssWyHpwu", | ||
"value": "-230.8404670389911", | ||
}, | ||
"sequence": 67782876, | ||
"status": "cancelled", | ||
"maker_exchange_rate": "4.616809340779822", | ||
"expiration_time": 708682031, | ||
} | ||
], | ||
} | ||
] | ||
self.assertEqual(actual, expected) |
90 changes: 90 additions & 0 deletions
90
tests/unit/utils/txn_parser/transaction_jsons/offer_cancelled.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
{ | ||
"Account": "rEUt5Wy44vDKBDaGkUWG6oSTvxmqgnKWCg", | ||
"Fee": "15", | ||
"Flags": 2147483648, | ||
"LastLedgerSequence": 72374248, | ||
"OfferSequence": 70922543, | ||
"Sequence": 70922544, | ||
"SigningPubKey": "ED024DA5B0A65470D8582D43BDD54D2BD861C9485CFB13EFA2928650CE6686A86D", | ||
"TransactionType": "OfferCancel", | ||
"TxnSignature": "37EB64C659AE77A70FB93A2DFA0AE5282E3B6C0C8E89A3FE08E004D216CB5C8C62219761E3764AFCBA82692DF6204516FD63C0265CC894B360EA06F18401E90E", | ||
"date": 708682141, | ||
"hash": "40FDBE9F71213696FE67CC80B2847E7DA1D3E03A4446D34DCC7DE347137FF436", | ||
"inLedger": 72374247, | ||
"ledger_index": 72374247, | ||
"meta": { | ||
"AffectedNodes": [ | ||
{ | ||
"DeletedNode": { | ||
"FinalFields": { | ||
"ExchangeRate": "57147f7b444d5b06", | ||
"Flags": 0, | ||
"RootIndex": "2004607367326F467796C4080157BE0997B306F1CA6AE0C657147F7B444D5B06", | ||
"TakerGetsCurrency": "0000000000000000000000005844580000000000", | ||
"TakerGetsIssuer": "DEC71A7A7168ED930218B15994FD007CE80A4913", | ||
"TakerPaysCurrency": "0000000000000000000000000000000000000000", | ||
"TakerPaysIssuer": "0000000000000000000000000000000000000000" | ||
}, | ||
"LedgerEntryType": "DirectoryNode", | ||
"LedgerIndex": "2004607367326F467796C4080157BE0997B306F1CA6AE0C657147F7B444D5B06" | ||
} | ||
}, | ||
{ | ||
"ModifiedNode": { | ||
"FinalFields": { | ||
"Account": "rEUt5Wy44vDKBDaGkUWG6oSTvxmqgnKWCg", | ||
"Balance": "1283353963", | ||
"Flags": 0, | ||
"OwnerCount": 2, | ||
"Sequence": 70922545 | ||
}, | ||
"LedgerEntryType": "AccountRoot", | ||
"LedgerIndex": "2CAC78E1EEC7340A666AED1DE99DB8B6C8235CB6675903CAB26EA5C62D4F0BB4", | ||
"PreviousFields": { | ||
"Balance": "1283353978", | ||
"OwnerCount": 3, | ||
"Sequence": 70922544 | ||
}, | ||
"PreviousTxnID": "3C6A9B3C72B79DB877AC205ADC1700281C20D08CCD30A6779C3E1B550B558B95", | ||
"PreviousTxnLgrSeq": 72373937 | ||
} | ||
}, | ||
{ | ||
"DeletedNode": { | ||
"FinalFields": { | ||
"Account": "rEUt5Wy44vDKBDaGkUWG6oSTvxmqgnKWCg", | ||
"BookDirectory": "2004607367326F467796C4080157BE0997B306F1CA6AE0C657147F7B444D5B06", | ||
"BookNode": "0", | ||
"Flags": 0, | ||
"OwnerNode": "0", | ||
"PreviousTxnID": "3C6A9B3C72B79DB877AC205ADC1700281C20D08CCD30A6779C3E1B550B558B95", | ||
"PreviousTxnLgrSeq": 72373937, | ||
"Sequence": 70922543, | ||
"TakerGets": { | ||
"currency": "XDX", | ||
"issuer": "rMJAXYsbNzhwp7FfYnAsYP5ty3R9XnurPo", | ||
"value": "82335.52909" | ||
}, | ||
"TakerPays": "47504858" | ||
}, | ||
"LedgerEntryType": "Offer", | ||
"LedgerIndex": "A867E960F0D9F88D7BE2885AA3E69C5F2C7F76499D6CC483E353D6616EEBD352" | ||
} | ||
}, | ||
{ | ||
"ModifiedNode": { | ||
"FinalFields": { | ||
"Flags": 0, | ||
"Owner": "rEUt5Wy44vDKBDaGkUWG6oSTvxmqgnKWCg", | ||
"RootIndex": "FEB025593E20EE2B66382D9F9079719A40AD0DE257CBBD6421092037E39C9A53" | ||
}, | ||
"LedgerEntryType": "DirectoryNode", | ||
"LedgerIndex": "FEB025593E20EE2B66382D9F9079719A40AD0DE257CBBD6421092037E39C9A53" | ||
} | ||
} | ||
], | ||
"TransactionIndex": 16, | ||
"TransactionResult": "tesSUCCESS" | ||
}, | ||
"validated": true | ||
} |
93 changes: 93 additions & 0 deletions
93
tests/unit/utils/txn_parser/transaction_jsons/offer_created.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
{ | ||
"Account": "rJHbqhp9Sea4f43RoUanrDE1gW9MymTLp9", | ||
"Expiration": 740218424, | ||
"Fee": "25", | ||
"Flags": 2148007936, | ||
"LastLedgerSequence": 72374322, | ||
"Sequence": 71307620, | ||
"SigningPubKey": "020AF1B1419DB3C80FBB3B2621315F78F03806118094140B6FE535ED809561AC23", | ||
"TakerGets": "44930000", | ||
"TakerPays": { | ||
"currency": "USD", | ||
"issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", | ||
"value": "14.524821" | ||
}, | ||
"TransactionType": "OfferCreate", | ||
"TxnSignature": "3045022100C1CA7C960C1BD0B2EA9ACCA13BB429C1C5B558AB2B8AFE9FE3815DB075E07806022030152DC46694A3BF8BA1509944F9388723CB30C678E659613D4B3BF8166CCCA5", | ||
"date": 708682430, | ||
"hash": "463E28521ACA7FB5F4081E7E368FA5AEB76FB641FCB3C92CA9E8971A990CE84A", | ||
"inLedger": 72374321, | ||
"ledger_index": 72374321, | ||
"meta": { | ||
"AffectedNodes": [ | ||
{ | ||
"ModifiedNode": { | ||
"FinalFields": { | ||
"Flags": 0, | ||
"Owner": "rJHbqhp9Sea4f43RoUanrDE1gW9MymTLp9", | ||
"RootIndex": "3418F55643869450792F7047DC92DD661D38E68AC827C378D7C12FE8E017DD2B" | ||
}, | ||
"LedgerEntryType": "DirectoryNode", | ||
"LedgerIndex": "3418F55643869450792F7047DC92DD661D38E68AC827C378D7C12FE8E017DD2B" | ||
} | ||
}, | ||
{ | ||
"ModifiedNode": { | ||
"FinalFields": { | ||
"Account": "rJHbqhp9Sea4f43RoUanrDE1gW9MymTLp9", | ||
"Balance": "69932774", | ||
"Flags": 0, | ||
"OwnerCount": 3, | ||
"Sequence": 71307621 | ||
}, | ||
"LedgerEntryType": "AccountRoot", | ||
"LedgerIndex": "72D49D4E2ECA5153A90413AA4BCEFBFBE748A2B66A96F5E5611089C095BD666D", | ||
"PreviousFields": { | ||
"Balance": "69932799", | ||
"OwnerCount": 2, | ||
"Sequence": 71307620 | ||
}, | ||
"PreviousTxnID": "70C2D1F863FBF18CA7E9B17D7B35A19BD5ED22C8B703D447A21C746E1F66F311", | ||
"PreviousTxnLgrSeq": 72374313 | ||
} | ||
}, | ||
{ | ||
"ModifiedNode": { | ||
"FinalFields": { | ||
"ExchangeRate": "4e0b7c2f29ac3197", | ||
"Flags": 0, | ||
"RootIndex": "DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4E0B7C2F29AC3197", | ||
"TakerGetsCurrency": "0000000000000000000000000000000000000000", | ||
"TakerGetsIssuer": "0000000000000000000000000000000000000000", | ||
"TakerPaysCurrency": "0000000000000000000000005553440000000000", | ||
"TakerPaysIssuer": "0A20B3C85F482532A9578DBB3950B85CA06594D1" | ||
}, | ||
"LedgerEntryType": "DirectoryNode", | ||
"LedgerIndex": "DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4E0B7C2F29AC3197" | ||
} | ||
}, | ||
{ | ||
"CreatedNode": { | ||
"LedgerEntryType": "Offer", | ||
"LedgerIndex": "DFA50F8A0710C8483D5DEF31E87BFA5DBC617F16045EC187EB21A07B7A2B23DA", | ||
"NewFields": { | ||
"Account": "rJHbqhp9Sea4f43RoUanrDE1gW9MymTLp9", | ||
"BookDirectory": "DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4E0B7C2F29AC3197", | ||
"Expiration": 740218424, | ||
"Flags": 131072, | ||
"Sequence": 71307620, | ||
"TakerGets": "44930000", | ||
"TakerPays": { | ||
"currency": "USD", | ||
"issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", | ||
"value": "14.524821" | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"TransactionIndex": 37, | ||
"TransactionResult": "tesSUCCESS" | ||
}, | ||
"validated": true | ||
} |
Oops, something went wrong.