Fixed problem with logging messages and token dereference.

This commit is contained in:
Geoff Taylor 2021-05-02 14:36:16 +01:00
parent 9881f5f3dc
commit 9ff7619985
3 changed files with 41 additions and 40 deletions

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "olympic-beatles", "id": "historical-repeat",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# ⚠ Warning\n", "# ⚠ Warning\n",
@ -16,7 +16,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "meaning-feature", "id": "pretty-cylinder",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🥭 Context\n", "# 🥭 Context\n",
@ -26,7 +26,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "assigned-american", "id": "interim-cherry",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Environment Variables\n", "## Environment Variables\n",
@ -41,7 +41,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "written-heavy", "id": "generous-handy",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Provided Configured Objects\n", "## Provided Configured Objects\n",
@ -61,7 +61,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "cross-passport", "id": "commercial-milton",
"metadata": { "metadata": {
"jupyter": { "jupyter": {
"source_hidden": true "source_hidden": true
@ -87,7 +87,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "corrected-disclaimer", "id": "boxed-peoples",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## AccountInfo class\n", "## AccountInfo class\n",
@ -98,7 +98,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "cutting-miller", "id": "metropolitan-layer",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -142,7 +142,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "flying-mount", "id": "unauthorized-cycling",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Context class" "## Context class"
@ -151,7 +151,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "strong-recycling", "id": "steady-hotel",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -268,13 +268,14 @@
" return Context._lookup_name_by_address(token_address, MangoConstants[self.cluster][\"symbols\"]) or \"« Unknown Token »\"\n", " return Context._lookup_name_by_address(token_address, MangoConstants[self.cluster][\"symbols\"]) or \"« Unknown Token »\"\n",
"\n", "\n",
" def wait_for_confirmation(self, transaction_id: str, max_wait_in_seconds: int = 60) -> None:\n", " def wait_for_confirmation(self, transaction_id: str, max_wait_in_seconds: int = 60) -> None:\n",
" self.logger.info(f\"Waiting up to {max_wait_in_seconds} seconds for {transaction_id}.\")\n",
" for wait in range(0, max_wait_in_seconds):\n", " for wait in range(0, max_wait_in_seconds):\n",
" time.sleep(1)\n", " time.sleep(1)\n",
" confirmed = default_context.client.get_confirmed_transaction(transaction_id)\n", " confirmed = default_context.client.get_confirmed_transaction(transaction_id)\n",
" if confirmed[\"result\"] is not None:\n", " if confirmed[\"result\"] is not None:\n",
" print(f\"Confirmed after {wait} seconds.\")\n", " self.logger.info(f\"Confirmed after {wait} seconds.\")\n",
" return\n", " return\n",
" print(f\"Timed out after {wait} seconds waiting on transaction {transaction_id}.\")\n", " self.logger.info(f\"Timed out after {wait} seconds waiting on transaction {transaction_id}.\")\n",
"\n", "\n",
" def __str__(self) -> str:\n", " def __str__(self) -> str:\n",
" return f\"\"\"« Context:\n", " return f\"\"\"« Context:\n",
@ -292,7 +293,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "defined-station", "id": "stainless-aurora",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## default_context object\n", "## default_context object\n",
@ -303,7 +304,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "enhanced-victor", "id": "geographic-chaos",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -322,7 +323,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "metric-attachment", "id": "alternative-surname",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## solana_context object\n", "## solana_context object\n",
@ -333,7 +334,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "vietnamese-reducing", "id": "individual-extraction",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -345,7 +346,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "vocational-salvation", "id": "systematic-split",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## serum_context object\n", "## serum_context object\n",
@ -356,7 +357,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "combined-messaging", "id": "political-trading",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -368,7 +369,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "hollywood-administrator", "id": "quarterly-breast",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🏃 Running\n", "# 🏃 Running\n",
@ -379,7 +380,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "handmade-following", "id": "religious-amateur",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "suitable-circuit", "id": "pressing-banner",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# ⚠ Warning\n", "# ⚠ Warning\n",
@ -16,7 +16,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "natural-persian", "id": "champion-control",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🥭 Liquidation\n", "# 🥭 Liquidation\n",
@ -31,7 +31,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "interesting-fleet", "id": "awful-rocket",
"metadata": { "metadata": {
"jupyter": { "jupyter": {
"source_hidden": true "source_hidden": true
@ -49,7 +49,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "overall-canadian", "id": "compact-english",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 🦺 Safety\n", "## 🦺 Safety\n",
@ -63,7 +63,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "false-billy", "id": "revised-premises",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 📇 Collateralisation Ratios Details\n", "## 📇 Collateralisation Ratios Details\n",
@ -81,7 +81,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "polish-hartford", "id": "found-lloyd",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 💧 Liquidation Process" "# 💧 Liquidation Process"
@ -89,7 +89,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "productive-mailman", "id": "short-project",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 📇 Steps\n", "## 📇 Steps\n",
@ -117,7 +117,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "speaking-retirement", "id": "cellular-shell",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🏃 Running\n", "# 🏃 Running\n",
@ -134,17 +134,17 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "middle-dancing", "id": "passing-count",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"MARGIN_ACCOUNT_TO_LIQUIDATE = \"6u4kaF4UT4uZ2oczR63nHtydXGevDRBpSYNXGsHNNXVL\"" "MARGIN_ACCOUNT_TO_LIQUIDATE = \"\""
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "virtual-capitol", "id": "naughty-compiler",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "standard-football", "id": "dressed-devices",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# ⚠ Warning\n", "# ⚠ Warning\n",
@ -16,7 +16,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "little-africa", "id": "random-numbers",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🥭 SimpleLiquidator\n", "# 🥭 SimpleLiquidator\n",
@ -27,7 +27,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "rubber-given", "id": "excited-sword",
"metadata": { "metadata": {
"jupyter": { "jupyter": {
"source_hidden": true "source_hidden": true
@ -46,7 +46,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "chinese-lease", "id": "manual-captain",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# SimpleLiquidator class\n", "# SimpleLiquidator class\n",
@ -68,14 +68,14 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "positive-capacity", "id": "positive-champagne",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"def token_balances_from_wallet(context: Context, wallet: Wallet, group: Group) -> typing.List[TokenValue]:\n", "def token_balances_from_wallet(context: Context, wallet: Wallet, group: Group) -> typing.List[TokenValue]:\n",
" balances: typing.List[TokenValue] = []\n", " balances: typing.List[TokenValue] = []\n",
" for token in group.tokens:\n", " for token in group.tokens:\n",
" balance = TokenValue(token.token, context.fetch_token_balance(wallet.address, token.mint))\n", " balance = TokenValue(token, context.fetch_token_balance(wallet.address, token.mint))\n",
" balances += [balance]\n", " balances += [balance]\n",
"\n", "\n",
" return balances\n", " return balances\n",
@ -157,14 +157,14 @@
" group_after = Group.load(self.context)\n", " group_after = Group.load(self.context)\n",
" margin_account_after_liquidation = MarginAccount.load(self.context, mam.margin_account.address, group_after)\n", " margin_account_after_liquidation = MarginAccount.load(self.context, mam.margin_account.address, group_after)\n",
" intrinsic_balances_after = margin_account_after_liquidation.get_intrinsic_balances(group_after)\n", " intrinsic_balances_after = margin_account_after_liquidation.get_intrinsic_balances(group_after)\n",
" self.logger.info(\"Margin Account After:\", intrinsic_balances_after)\n", " self.logger.info(f\"Margin account balances after: {intrinsic_balances_after}\")\n",
" wallet_balances_after = token_balances_from_wallet(self.context, self.wallet, group)\n", " wallet_balances_after = token_balances_from_wallet(self.context, self.wallet, group)\n",
" self.logger.info(f\"Wallet balances after:\\n{wallet_balances_after}\")\n" " self.logger.info(f\"Wallet balances after:\\n{wallet_balances_after}\")\n"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "organic-leather", "id": "fallen-sustainability",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 🏃 Running" "# 🏃 Running"
@ -173,7 +173,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "blind-logic", "id": "excited-recycling",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [