-
Notifications
You must be signed in to change notification settings - Fork 81
/
test_get_order_book_changes.py
137 lines (129 loc) · 5.56 KB
/
test_get_order_book_changes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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)