]>
Commit | Line | Data |
---|---|---|
ada1b5f1 IB |
1 | import time |
2 | import requests | |
6ca5a1ec | 3 | import portfolio |
3d0247f9 IB |
4 | import simplejson as json |
5 | from decimal import Decimal as D, ROUND_DOWN | |
ada1b5f1 | 6 | from datetime import date, datetime, timedelta |
aca4d437 | 7 | import inspect |
ada1b5f1 IB |
8 | from json import JSONDecodeError |
9 | from simplejson.errors import JSONDecodeError as SimpleJSONDecodeError | |
6ca5a1ec | 10 | |
ada1b5f1 | 11 | __all__ = ["Portfolio", "BalanceStore", "ReportStore", "TradeStore"] |
3d0247f9 IB |
12 | |
13 | class ReportStore: | |
f86ee140 IB |
14 | def __init__(self, market, verbose_print=True): |
15 | self.market = market | |
16 | self.verbose_print = verbose_print | |
3d0247f9 | 17 | |
718e3e91 | 18 | self.print_logs = [] |
f86ee140 IB |
19 | self.logs = [] |
20 | ||
9bde69bf IB |
21 | def merge(self, other_report): |
22 | self.logs += other_report.logs | |
23 | self.logs.sort(key=lambda x: x["date"]) | |
24 | ||
718e3e91 IB |
25 | self.print_logs += other_report.print_logs |
26 | self.print_logs.sort(key=lambda x: x[0]) | |
27 | ||
f86ee140 | 28 | def print_log(self, message): |
718e3e91 IB |
29 | now = datetime.now() |
30 | message = "{:%Y-%m-%d %H:%M:%S}: {}".format(now, str(message)) | |
31 | self.print_logs.append([now, message]) | |
f86ee140 | 32 | if self.verbose_print: |
3d0247f9 IB |
33 | print(message) |
34 | ||
f86ee140 | 35 | def add_log(self, hash_): |
3d0247f9 | 36 | hash_["date"] = datetime.now() |
f86ee140 | 37 | self.logs.append(hash_) |
3d0247f9 | 38 | |
b4e0ba0b IB |
39 | @staticmethod |
40 | def default_json_serial(obj): | |
41 | if isinstance(obj, (datetime, date)): | |
42 | return obj.isoformat() | |
43 | return str(obj) | |
44 | ||
f86ee140 | 45 | def to_json(self): |
b4e0ba0b IB |
46 | return json.dumps(self.logs, default=self.default_json_serial, indent=" ") |
47 | ||
48 | def to_json_array(self): | |
49 | for log in (x.copy() for x in self.logs): | |
50 | yield ( | |
51 | log.pop("date"), | |
52 | log.pop("type"), | |
53 | json.dumps(log, default=self.default_json_serial, indent=" ") | |
54 | ) | |
3d0247f9 | 55 | |
f86ee140 IB |
56 | def set_verbose(self, verbose_print): |
57 | self.verbose_print = verbose_print | |
3d0247f9 | 58 | |
7bd830a8 IB |
59 | def log_stage(self, stage, **kwargs): |
60 | def as_json(element): | |
61 | if callable(element): | |
62 | return inspect.getsource(element).strip() | |
63 | elif hasattr(element, "as_json"): | |
64 | return element.as_json() | |
65 | else: | |
66 | return element | |
67 | ||
68 | args = { k: as_json(v) for k, v in kwargs.items() } | |
69 | args_str = ["{}={}".format(k, v) for k, v in args.items()] | |
f86ee140 | 70 | self.print_log("-" * (len(stage) + 8)) |
7bd830a8 | 71 | self.print_log("[Stage] {} {}".format(stage, ", ".join(args_str))) |
3d0247f9 | 72 | |
f86ee140 | 73 | self.add_log({ |
3d0247f9 IB |
74 | "type": "stage", |
75 | "stage": stage, | |
7bd830a8 | 76 | "args": args, |
3d0247f9 IB |
77 | }) |
78 | ||
f86ee140 IB |
79 | def log_balances(self, tag=None): |
80 | self.print_log("[Balance]") | |
81 | for currency, balance in self.market.balances.all.items(): | |
82 | self.print_log("\t{}".format(balance)) | |
3d0247f9 | 83 | |
f86ee140 | 84 | self.add_log({ |
3d0247f9 | 85 | "type": "balance", |
18167a3c | 86 | "tag": tag, |
f86ee140 | 87 | "balances": self.market.balances.as_json() |
3d0247f9 IB |
88 | }) |
89 | ||
f86ee140 | 90 | def log_tickers(self, amounts, other_currency, |
3d0247f9 IB |
91 | compute_value, type): |
92 | values = {} | |
93 | rates = {} | |
aca4d437 IB |
94 | if callable(compute_value): |
95 | compute_value = inspect.getsource(compute_value).strip() | |
96 | ||
3d0247f9 IB |
97 | for currency, amount in amounts.items(): |
98 | values[currency] = amount.as_json()["value"] | |
99 | rates[currency] = amount.rate | |
f86ee140 | 100 | self.add_log({ |
3d0247f9 IB |
101 | "type": "tickers", |
102 | "compute_value": compute_value, | |
103 | "balance_type": type, | |
104 | "currency": other_currency, | |
105 | "balances": values, | |
106 | "rates": rates, | |
107 | "total": sum(amounts.values()).as_json()["value"] | |
108 | }) | |
109 | ||
f86ee140 IB |
110 | def log_dispatch(self, amount, amounts, liquidity, repartition): |
111 | self.add_log({ | |
3d0247f9 IB |
112 | "type": "dispatch", |
113 | "liquidity": liquidity, | |
114 | "repartition_ratio": repartition, | |
115 | "total_amount": amount.as_json(), | |
116 | "repartition": { k: v.as_json()["value"] for k, v in amounts.items() } | |
117 | }) | |
118 | ||
f86ee140 | 119 | def log_trades(self, matching_and_trades, only): |
3d0247f9 IB |
120 | trades = [] |
121 | for matching, trade in matching_and_trades: | |
122 | trade_json = trade.as_json() | |
123 | trade_json["skipped"] = not matching | |
124 | trades.append(trade_json) | |
125 | ||
f86ee140 | 126 | self.add_log({ |
3d0247f9 IB |
127 | "type": "trades", |
128 | "only": only, | |
f86ee140 | 129 | "debug": self.market.debug, |
3d0247f9 IB |
130 | "trades": trades |
131 | }) | |
132 | ||
f86ee140 | 133 | def log_orders(self, orders, tick=None, only=None, compute_value=None): |
aca4d437 IB |
134 | if callable(compute_value): |
135 | compute_value = inspect.getsource(compute_value).strip() | |
f86ee140 IB |
136 | self.print_log("[Orders]") |
137 | self.market.trades.print_all_with_order(ind="\t") | |
138 | self.add_log({ | |
3d0247f9 IB |
139 | "type": "orders", |
140 | "only": only, | |
141 | "compute_value": compute_value, | |
142 | "tick": tick, | |
143 | "orders": [order.as_json() for order in orders if order is not None] | |
144 | }) | |
145 | ||
f86ee140 | 146 | def log_order(self, order, tick, finished=False, update=None, |
3d0247f9 | 147 | new_order=None, compute_value=None): |
aca4d437 IB |
148 | if callable(compute_value): |
149 | compute_value = inspect.getsource(compute_value).strip() | |
3d0247f9 | 150 | if finished: |
f86ee140 | 151 | self.print_log("[Order] Finished {}".format(order)) |
3d0247f9 | 152 | elif update == "waiting": |
f86ee140 | 153 | self.print_log("[Order] {}, tick {}, waiting".format(order, tick)) |
3d0247f9 | 154 | elif update == "adjusting": |
f86ee140 | 155 | self.print_log("[Order] {}, tick {}, cancelling and adjusting to {}".format(order, tick, new_order)) |
3d0247f9 | 156 | elif update == "market_fallback": |
f86ee140 | 157 | self.print_log("[Order] {}, tick {}, fallbacking to market value".format(order, tick)) |
3d0247f9 | 158 | elif update == "market_adjust": |
f86ee140 | 159 | self.print_log("[Order] {}, tick {}, market value, cancelling and adjusting to {}".format(order, tick, new_order)) |
3d0247f9 | 160 | |
f86ee140 | 161 | self.add_log({ |
3d0247f9 IB |
162 | "type": "order", |
163 | "tick": tick, | |
164 | "update": update, | |
165 | "order": order.as_json(), | |
166 | "compute_value": compute_value, | |
167 | "new_order": new_order.as_json() if new_order is not None else None | |
168 | }) | |
169 | ||
f86ee140 IB |
170 | def log_move_balances(self, needed, moving): |
171 | self.add_log({ | |
3d0247f9 | 172 | "type": "move_balances", |
f86ee140 | 173 | "debug": self.market.debug, |
3d0247f9 IB |
174 | "needed": { k: v.as_json()["value"] if isinstance(v, portfolio.Amount) else v for k, v in needed.items() }, |
175 | "moving": { k: v.as_json()["value"] if isinstance(v, portfolio.Amount) else v for k, v in moving.items() }, | |
176 | }) | |
177 | ||
f86ee140 | 178 | def log_http_request(self, method, url, body, headers, response): |
d8e233ac IB |
179 | if isinstance(response, Exception): |
180 | self.add_log({ | |
181 | "type": "http_request", | |
182 | "method": method, | |
183 | "url": url, | |
184 | "body": body, | |
185 | "headers": headers, | |
186 | "status": -1, | |
187 | "response": None, | |
188 | "error": response.__class__.__name__, | |
189 | "error_message": str(response), | |
190 | }) | |
191 | else: | |
192 | self.add_log({ | |
193 | "type": "http_request", | |
194 | "method": method, | |
195 | "url": url, | |
196 | "body": body, | |
197 | "headers": headers, | |
198 | "status": response.status_code, | |
199 | "response": response.text | |
200 | }) | |
3d0247f9 | 201 | |
f86ee140 IB |
202 | def log_error(self, action, message=None, exception=None): |
203 | self.print_log("[Error] {}".format(action)) | |
3d0247f9 | 204 | if exception is not None: |
f86ee140 | 205 | self.print_log(str("\t{}: {}".format(exception.__class__.__name__, exception))) |
3d0247f9 | 206 | if message is not None: |
f86ee140 | 207 | self.print_log("\t{}".format(message)) |
3d0247f9 | 208 | |
f86ee140 | 209 | self.add_log({ |
3d0247f9 IB |
210 | "type": "error", |
211 | "action": action, | |
212 | "exception_class": exception.__class__.__name__ if exception is not None else None, | |
213 | "exception_message": str(exception) if exception is not None else None, | |
214 | "message": message, | |
215 | }) | |
216 | ||
f86ee140 IB |
217 | def log_debug_action(self, action): |
218 | self.print_log("[Debug] {}".format(action)) | |
3d0247f9 | 219 | |
f86ee140 | 220 | self.add_log({ |
3d0247f9 IB |
221 | "type": "debug_action", |
222 | "action": action, | |
223 | }) | |
6ca5a1ec | 224 | |
90d7423e IB |
225 | def log_market(self, args, user_id, market_id, report_path, debug): |
226 | self.add_log({ | |
227 | "type": "market", | |
228 | "commit": "$Format:%H$", | |
229 | "args": vars(args), | |
230 | "user_id": user_id, | |
231 | "market_id": market_id, | |
232 | "report_path": report_path, | |
233 | "debug": debug, | |
234 | }) | |
235 | ||
6ca5a1ec | 236 | class BalanceStore: |
f86ee140 IB |
237 | def __init__(self, market): |
238 | self.market = market | |
239 | self.all = {} | |
6ca5a1ec | 240 | |
f86ee140 IB |
241 | def currencies(self): |
242 | return self.all.keys() | |
6ca5a1ec | 243 | |
f86ee140 | 244 | def in_currency(self, other_currency, compute_value="average", type="total"): |
6ca5a1ec | 245 | amounts = {} |
f86ee140 | 246 | for currency, balance in self.all.items(): |
6ca5a1ec | 247 | other_currency_amount = getattr(balance, type)\ |
f86ee140 | 248 | .in_currency(other_currency, self.market, compute_value=compute_value) |
6ca5a1ec | 249 | amounts[currency] = other_currency_amount |
f86ee140 | 250 | self.market.report.log_tickers(amounts, other_currency, |
3d0247f9 | 251 | compute_value, type) |
6ca5a1ec IB |
252 | return amounts |
253 | ||
f86ee140 IB |
254 | def fetch_balances(self, tag=None): |
255 | all_balances = self.market.ccxt.fetch_all_balances() | |
6ca5a1ec IB |
256 | for currency, balance in all_balances.items(): |
257 | if balance["exchange_total"] != 0 or balance["margin_total"] != 0 or \ | |
f86ee140 IB |
258 | currency in self.all: |
259 | self.all[currency] = portfolio.Balance(currency, balance) | |
260 | self.market.report.log_balances(tag=tag) | |
6ca5a1ec | 261 | |
f86ee140 | 262 | def dispatch_assets(self, amount, liquidity="medium", repartition=None): |
6ca5a1ec | 263 | if repartition is None: |
ada1b5f1 | 264 | repartition = Portfolio.repartition(liquidity=liquidity) |
6ca5a1ec IB |
265 | sum_ratio = sum([v[0] for k, v in repartition.items()]) |
266 | amounts = {} | |
267 | for currency, (ptt, trade_type) in repartition.items(): | |
268 | amounts[currency] = ptt * amount / sum_ratio | |
269 | if trade_type == "short": | |
270 | amounts[currency] = - amounts[currency] | |
aca4d437 | 271 | self.all.setdefault(currency, portfolio.Balance(currency, {})) |
f86ee140 | 272 | self.market.report.log_dispatch(amount, amounts, liquidity, repartition) |
6ca5a1ec IB |
273 | return amounts |
274 | ||
f86ee140 IB |
275 | def as_json(self): |
276 | return { k: v.as_json() for k, v in self.all.items() } | |
3d0247f9 | 277 | |
6ca5a1ec | 278 | class TradeStore: |
f86ee140 IB |
279 | def __init__(self, market): |
280 | self.market = market | |
281 | self.all = [] | |
6ca5a1ec | 282 | |
aca4d437 IB |
283 | @property |
284 | def pending(self): | |
17598517 | 285 | return list(filter(lambda t: t.pending, self.all)) |
aca4d437 | 286 | |
f86ee140 | 287 | def compute_trades(self, values_in_base, new_repartition, only=None): |
3d0247f9 | 288 | computed_trades = [] |
6ca5a1ec | 289 | base_currency = sum(values_in_base.values()).currency |
f86ee140 | 290 | for currency in self.market.balances.currencies(): |
6ca5a1ec IB |
291 | if currency == base_currency: |
292 | continue | |
293 | value_from = values_in_base.get(currency, portfolio.Amount(base_currency, 0)) | |
294 | value_to = new_repartition.get(currency, portfolio.Amount(base_currency, 0)) | |
1aa7d4fa | 295 | |
6ca5a1ec | 296 | if value_from.value * value_to.value < 0: |
f86ee140 | 297 | computed_trades.append(self.trade_if_matching( |
1aa7d4fa | 298 | value_from, portfolio.Amount(base_currency, 0), |
f86ee140 IB |
299 | currency, only=only)) |
300 | computed_trades.append(self.trade_if_matching( | |
1aa7d4fa | 301 | portfolio.Amount(base_currency, 0), value_to, |
f86ee140 | 302 | currency, only=only)) |
6ca5a1ec | 303 | else: |
f86ee140 | 304 | computed_trades.append(self.trade_if_matching( |
3d0247f9 | 305 | value_from, value_to, |
f86ee140 | 306 | currency, only=only)) |
3d0247f9 IB |
307 | for matching, trade in computed_trades: |
308 | if matching: | |
f86ee140 IB |
309 | self.all.append(trade) |
310 | self.market.report.log_trades(computed_trades, only) | |
1aa7d4fa | 311 | |
f86ee140 IB |
312 | def trade_if_matching(self, value_from, value_to, currency, |
313 | only=None): | |
1aa7d4fa | 314 | trade = portfolio.Trade(value_from, value_to, currency, |
f86ee140 | 315 | self.market) |
3d0247f9 IB |
316 | matching = only is None or trade.action == only |
317 | return [matching, trade] | |
6ca5a1ec | 318 | |
f86ee140 | 319 | def prepare_orders(self, only=None, compute_value="default"): |
3d0247f9 | 320 | orders = [] |
aca4d437 | 321 | for trade in self.pending: |
6ca5a1ec | 322 | if only is None or trade.action == only: |
3d0247f9 | 323 | orders.append(trade.prepare_order(compute_value=compute_value)) |
f86ee140 | 324 | self.market.report.log_orders(orders, only, compute_value) |
6ca5a1ec | 325 | |
17598517 IB |
326 | def close_trades(self): |
327 | for trade in self.all: | |
328 | trade.close() | |
329 | ||
f86ee140 IB |
330 | def print_all_with_order(self, ind=""): |
331 | for trade in self.all: | |
3d0247f9 | 332 | trade.print_with_order(ind=ind) |
6ca5a1ec | 333 | |
f86ee140 IB |
334 | def run_orders(self): |
335 | orders = self.all_orders(state="pending") | |
3d0247f9 | 336 | for order in orders: |
6ca5a1ec | 337 | order.run() |
f86ee140 IB |
338 | self.market.report.log_stage("run_orders") |
339 | self.market.report.log_orders(orders) | |
6ca5a1ec | 340 | |
f86ee140 IB |
341 | def all_orders(self, state=None): |
342 | all_orders = sum(map(lambda v: v.orders, self.all), []) | |
6ca5a1ec IB |
343 | if state is None: |
344 | return all_orders | |
345 | else: | |
346 | return list(filter(lambda o: o.status == state, all_orders)) | |
347 | ||
f86ee140 IB |
348 | def update_all_orders_status(self): |
349 | for order in self.all_orders(state="open"): | |
6ca5a1ec IB |
350 | order.get_status() |
351 | ||
dc1ca9a3 IB |
352 | class NoopLock: |
353 | def __enter__(self, *args): | |
354 | pass | |
355 | def __exit__(self, *args): | |
356 | pass | |
357 | ||
358 | class LockedVar: | |
359 | def __init__(self, value): | |
360 | self.lock = NoopLock() | |
361 | self.val = value | |
362 | ||
363 | def start_lock(self): | |
364 | import threading | |
365 | self.lock = threading.Lock() | |
366 | ||
367 | def set(self, value): | |
368 | with self.lock: | |
369 | self.val = value | |
370 | ||
371 | def get(self, key=None): | |
372 | with self.lock: | |
373 | if key is not None and isinstance(self.val, dict): | |
374 | return self.val.get(key) | |
375 | else: | |
376 | return self.val | |
377 | ||
378 | def __getattr__(self, key): | |
379 | with self.lock: | |
380 | return getattr(self.val, key) | |
381 | ||
ada1b5f1 IB |
382 | class Portfolio: |
383 | URL = "https://cryptoportfolio.io/wp-content/uploads/portfolio/json/cryptoportfolio.json" | |
dc1ca9a3 IB |
384 | data = LockedVar(None) |
385 | liquidities = LockedVar({}) | |
386 | last_date = LockedVar(None) | |
387 | report = LockedVar(ReportStore(None)) | |
388 | worker = None | |
389 | worker_started = False | |
390 | worker_notify = None | |
391 | callback = None | |
392 | ||
393 | @classmethod | |
394 | def start_worker(cls, poll=30): | |
395 | import threading | |
396 | ||
397 | cls.worker = threading.Thread(name="portfolio", daemon=True, | |
398 | target=cls.wait_for_notification, kwargs={"poll": poll}) | |
399 | cls.worker_notify = threading.Event() | |
400 | cls.callback = threading.Event() | |
401 | ||
402 | cls.last_date.start_lock() | |
403 | cls.liquidities.start_lock() | |
404 | cls.report.start_lock() | |
405 | ||
406 | cls.worker_started = True | |
407 | cls.worker.start() | |
408 | ||
409 | @classmethod | |
410 | def is_worker_thread(cls): | |
411 | if cls.worker is None: | |
412 | return False | |
413 | else: | |
414 | import threading | |
415 | return cls.worker == threading.current_thread() | |
416 | ||
417 | @classmethod | |
418 | def wait_for_notification(cls, poll=30): | |
419 | if not cls.is_worker_thread(): | |
420 | raise RuntimeError("This method needs to be ran with the worker") | |
421 | while cls.worker_started: | |
422 | cls.worker_notify.wait() | |
423 | cls.worker_notify.clear() | |
424 | cls.report.print_log("Fetching cryptoportfolio") | |
425 | cls.get_cryptoportfolio(refetch=True) | |
426 | cls.callback.set() | |
427 | time.sleep(poll) | |
ada1b5f1 IB |
428 | |
429 | @classmethod | |
dc1ca9a3 IB |
430 | def notify_and_wait(cls): |
431 | cls.callback.clear() | |
432 | cls.worker_notify.set() | |
433 | cls.callback.wait() | |
434 | ||
435 | @classmethod | |
436 | def wait_for_recent(cls, delta=4, poll=30): | |
ada1b5f1 | 437 | cls.get_cryptoportfolio() |
dc1ca9a3 IB |
438 | while cls.last_date.get() is None or datetime.now() - cls.last_date.get() > timedelta(delta): |
439 | if cls.worker is None: | |
440 | time.sleep(poll) | |
441 | cls.report.print_log("Attempt to fetch up-to-date cryptoportfolio") | |
ada1b5f1 IB |
442 | cls.get_cryptoportfolio(refetch=True) |
443 | ||
444 | @classmethod | |
445 | def repartition(cls, liquidity="medium"): | |
446 | cls.get_cryptoportfolio() | |
dc1ca9a3 IB |
447 | liquidities = cls.liquidities.get(liquidity) |
448 | return liquidities[cls.last_date.get()] | |
ada1b5f1 IB |
449 | |
450 | @classmethod | |
451 | def get_cryptoportfolio(cls, refetch=False): | |
dc1ca9a3 IB |
452 | if cls.data.get() is not None and not refetch: |
453 | return | |
454 | if cls.worker is not None and not cls.is_worker_thread(): | |
455 | cls.notify_and_wait() | |
ada1b5f1 IB |
456 | return |
457 | try: | |
458 | r = requests.get(cls.URL) | |
459 | cls.report.log_http_request(r.request.method, | |
460 | r.request.url, r.request.body, r.request.headers, r) | |
461 | except Exception as e: | |
462 | cls.report.log_error("get_cryptoportfolio", exception=e) | |
463 | return | |
464 | try: | |
dc1ca9a3 | 465 | cls.data.set(r.json(parse_int=D, parse_float=D)) |
ada1b5f1 IB |
466 | cls.parse_cryptoportfolio() |
467 | except (JSONDecodeError, SimpleJSONDecodeError): | |
dc1ca9a3 IB |
468 | cls.data.set(None) |
469 | cls.last_date.set(None) | |
470 | cls.liquidities.set({}) | |
ada1b5f1 IB |
471 | |
472 | @classmethod | |
473 | def parse_cryptoportfolio(cls): | |
474 | def filter_weights(weight_hash): | |
475 | if weight_hash[1][0] == 0: | |
476 | return False | |
477 | if weight_hash[0] == "_row": | |
478 | return False | |
479 | return True | |
480 | ||
481 | def clean_weights(i): | |
482 | def clean_weights_(h): | |
483 | if h[0].endswith("s"): | |
484 | return [h[0][0:-1], (h[1][i], "short")] | |
485 | else: | |
486 | return [h[0], (h[1][i], "long")] | |
487 | return clean_weights_ | |
488 | ||
489 | def parse_weights(portfolio_hash): | |
dc1ca9a3 IB |
490 | if "weights" not in portfolio_hash: |
491 | return {} | |
ada1b5f1 IB |
492 | weights_hash = portfolio_hash["weights"] |
493 | weights = {} | |
494 | for i in range(len(weights_hash["_row"])): | |
495 | date = datetime.strptime(weights_hash["_row"][i], "%Y-%m-%d") | |
496 | weights[date] = dict(filter( | |
497 | filter_weights, | |
498 | map(clean_weights(i), weights_hash.items()))) | |
499 | return weights | |
500 | ||
dc1ca9a3 IB |
501 | high_liquidity = parse_weights(cls.data.get("portfolio_1")) |
502 | medium_liquidity = parse_weights(cls.data.get("portfolio_2")) | |
ada1b5f1 | 503 | |
dc1ca9a3 IB |
504 | cls.liquidities.set({ |
505 | "medium": medium_liquidity, | |
506 | "high": high_liquidity, | |
507 | }) | |
508 | cls.last_date.set(max( | |
509 | max(medium_liquidity.keys(), default=datetime(1, 1, 1)), | |
510 | max(high_liquidity.keys(), default=datetime(1, 1, 1)) | |
511 | )) | |
ada1b5f1 | 512 | |
6ca5a1ec | 513 |