diff --git a/resources/NBTest/NBTest_002_CPCandOptimizer.ipynb b/resources/NBTest/NBTest_002_CPCandOptimizer.ipynb
index a33cc15bc..221896bc7 100644
--- a/resources/NBTest/NBTest_002_CPCandOptimizer.ipynb
+++ b/resources/NBTest/NBTest_002_CPCandOptimizer.ipynb
@@ -1077,24 +1077,24 @@
" \n",
"
\n",
" \n",
- " MKR | \n",
- " 0.2500 | \n",
+ " LINK | \n",
+ " 0.0025 | \n",
"
\n",
" \n",
- " WBTC | \n",
- " 10.0000 | \n",
+ " USDC | \n",
+ " 0.0005 | \n",
"
\n",
" \n",
- " AAVE | \n",
- " 0.0500 | \n",
+ " WBTC | \n",
+ " 10.0000 | \n",
"
\n",
" \n",
- " LINK | \n",
- " 0.0025 | \n",
+ " MKR | \n",
+ " 0.2500 | \n",
"
\n",
" \n",
- " USDC | \n",
- " 0.0005 | \n",
+ " AAVE | \n",
+ " 0.0500 | \n",
"
\n",
" \n",
"\n",
@@ -1103,11 +1103,11 @@
"text/plain": [
" WETH\n",
"tknb \n",
- "MKR 0.2500\n",
- "WBTC 10.0000\n",
- "AAVE 0.0500\n",
"LINK 0.0025\n",
- "USDC 0.0005"
+ "USDC 0.0005\n",
+ "WBTC 10.0000\n",
+ "MKR 0.2500\n",
+ "AAVE 0.0500"
]
},
"execution_count": 47,
@@ -1484,11 +1484,11 @@
"data": {
"text/plain": [
"{'ETH': TTE(x=[], y=[0]),\n",
- " 'DAI': TTE(x=[1, 4, 8], y=[3, 6]),\n",
- " 'AAVE': TTE(x=[7], y=[8]),\n",
" 'LINK': TTE(x=[2, 3, 5, 6], y=[]),\n",
+ " 'USDC': TTE(x=[], y=[1, 2, 4, 5, 7]),\n",
+ " 'DAI': TTE(x=[1, 4, 8], y=[3, 6]),\n",
" 'BNT': TTE(x=[0], y=[]),\n",
- " 'USDC': TTE(x=[], y=[1, 2, 4, 5, 7])}"
+ " 'AAVE': TTE(x=[7], y=[8])}"
]
},
"execution_count": 63,
@@ -2145,7 +2145,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Arbitrage gains: 1.3195 WETH [time=0.0128s]\n"
+ "Arbitrage gains: 1.3195 WETH [time=0.0118s]\n"
]
}
],
@@ -2603,7 +2603,7 @@
" 'targettkn': 'WETH',\n",
" 'pairs_t': (('USDC', 'USDT'), ('WETH', 'USDT'), ('WETH', 'USDC')),\n",
" 'dtknfromp_f': .dtknfromp_f(p, *, islog10=True, asdct=False, quiet=False)>,\n",
- " 'optimizer': }"
+ " 'optimizer': }"
]
},
"execution_count": 107,
@@ -2648,20 +2648,6 @@
"text": [
"[margp_optimizer] calculating price estimates\n"
]
- },
- {
- "ename": "TypeError",
- "evalue": "argument of type 'numpy.float64' is not iterable",
- "output_type": "error",
- "traceback": [
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
- "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mO\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmargp_optimizer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"WETH\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mO\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mMO_DTKNFROMPF\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdebug\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mr3\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mprices0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mislog10\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;32massert\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mr3\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mr4\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mr3b\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mprices0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0masdct\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mislog10\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32massert\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mr3\u001b[0m\u001b[0;34m==\u001b[0m\u001b[0mr3b\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
- "\u001b[0;32m~/REPOES/Bancor/FLBot/resources/NBTest/fastlane_bot/tools/optimizer/margpoptimizer.py\u001b[0m in \u001b[0;36mdtknfromp_f\u001b[0;34m(p, islog10, asdct, quiet)\u001b[0m\n\u001b[1;32m 245\u001b[0m \u001b[0;31m# sum_by_tkn[tknq] += sumdy\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 246\u001b[0m \u001b[0;31m# sum_by_tkn[tknb] += sumdx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 247\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mdxvec\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdxvecs\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 248\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mtkn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdx_\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdxvec\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 249\u001b[0m \u001b[0msum_by_tkn\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mtkn\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0mdx_\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
- "\u001b[0;32m~/REPOES/Bancor/FLBot/resources/NBTest/fastlane_bot/tools/optimizer/margpoptimizer.py\u001b[0m in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 224\u001b[0m \u001b[0mc0\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcurves\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 225\u001b[0m \u001b[0;31m#dxdy = (dxdy_f(c.dxdyfromp_ftuple(price)) for c in curves)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 226\u001b[0;31m \u001b[0mdxvecs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdxvecfrompvec_f\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mprice\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mc\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mcurves\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 227\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 228\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mP\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"debug2\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mquiet\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
- "\u001b[0;32m~/REPOES/Bancor/FLBot/resources/NBTest/fastlane_bot/tools/cpc.py\u001b[0m in \u001b[0;36mdxvecfrompvec_f\u001b[0;34m(self, pvec, ignorebounds)\u001b[0m\n\u001b[1;32m 1438\u001b[0m \u001b[0;34m:\u001b[0m\u001b[0mreturns\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mtoken\u001b[0m \u001b[0mdifference\u001b[0m \u001b[0mamounts\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mdict\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0mtknx\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtkny\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mdy\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1439\u001b[0m \"\"\"\n\u001b[0;32m-> 1440\u001b[0;31m \u001b[0;32massert\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtknx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mpvec\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34mf\"pvec must contain price for {self.tknx} [{pvec.keys()}]\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1441\u001b[0m \u001b[0;32massert\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtkny\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mpvec\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34mf\"pvec must contain price for {self.tkny} [{pvec.keys()}]\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1442\u001b[0m \u001b[0mp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpvec\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtknx\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0mpvec\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtkny\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
- "\u001b[0;31mTypeError\u001b[0m: argument of type 'numpy.float64' is not iterable"
- ]
}
],
"source": [
@@ -2677,10 +2663,45 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 110,
"id": "c45ebfaa",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "[margp_optimizer] calculating price estimates\n",
+ "[margp_optimizer] pe [0.0005 0.0005]\n",
+ "[margp_optimizer] p 0.00, 0.00\n",
+ "[margp_optimizer] 1/p 2,000.00, 2,000.00\n",
+ "\n",
+ "[margp_optimizer] ========== cycle 0 =======>>>\n",
+ "log p0 [-3.3010299956639813, -3.3010299956639813]\n",
+ "log dp [3.1611697e-16 3.1611697e-16]\n",
+ "log p [-3.30103 -3.30103]\n",
+ "p (0.0005000000000000001, 0.0005000000000000001)\n",
+ "p 0.00, 0.00\n",
+ "1/p 2,000.00, 2,000.00\n",
+ "tokens_t ('USDT', 'USDC')\n",
+ "dtkn 0.000, 0.000\n",
+ "[criterium=4.47e-16, eps=1.0e-06, c/e=4e-10]\n",
+ "<<<========== cycle 0 ======= [margp_optimizer]\n",
+ "\n",
+ "[margp_optimizer] ========== cycle 1 =======>>>\n",
+ "log p0 [-3.301029995663981, -3.301029995663981]\n",
+ "log dp [-1.58058485e-16 -1.58058485e-16]\n",
+ "log p [-3.30103 -3.30103]\n",
+ "p (0.0005000000000000001, 0.0005000000000000001)\n",
+ "p 0.00, 0.00\n",
+ "1/p 2,000.00, 2,000.00\n",
+ "tokens_t ('USDT', 'USDC')\n",
+ "dtkn -0.000, -0.000\n",
+ "[criterium=2.24e-16, eps=1.0e-06, c/e=2e-10]\n",
+ "<<<========== cycle 1 ======= [margp_optimizer]\n"
+ ]
+ }
+ ],
"source": [
"r = O.margp_optimizer(\"WETH\", result=O.MO_MINIMAL, params=dict(verbose=True))\n",
"rd = r.asdict\n",
@@ -2702,7 +2723,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 111,
"id": "551b9b36",
"metadata": {},
"outputs": [],
@@ -2745,7 +2766,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 112,
"id": "16390e26",
"metadata": {},
"outputs": [],
@@ -2759,7 +2780,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 113,
"id": "34b5d2b2",
"metadata": {},
"outputs": [],
@@ -2778,7 +2799,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 114,
"id": "d9d551b6",
"metadata": {},
"outputs": [],
@@ -2794,7 +2815,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 115,
"id": "88888e71",
"metadata": {},
"outputs": [],
@@ -2822,20 +2843,120 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 116,
"id": "7c7fed1c",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "2.2650783648714423e-07"
+ ]
+ },
+ "execution_count": 116,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"abs(r.dtokens_t[0])"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 117,
"id": "e007be1d",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " WETH | \n",
+ " USDC | \n",
+ " USDT | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " c0 | \n",
+ " 0.413264 | \n",
+ " -7.937258e+02 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " c1 | \n",
+ " -0.452708 | \n",
+ " NaN | \n",
+ " 9.483481e+02 | \n",
+ "
\n",
+ " \n",
+ " c2 | \n",
+ " NaN | \n",
+ " 7.937258e+02 | \n",
+ " -9.483481e+02 | \n",
+ "
\n",
+ " \n",
+ " PRICE | \n",
+ " 1.000000 | \n",
+ " 5.421803e-04 | \n",
+ " 4.557539e-04 | \n",
+ "
\n",
+ " \n",
+ " AMMIn | \n",
+ " 0.413264 | \n",
+ " 7.937258e+02 | \n",
+ " 9.483481e+02 | \n",
+ "
\n",
+ " \n",
+ " AMMOut | \n",
+ " -0.452708 | \n",
+ " -7.937258e+02 | \n",
+ " -9.483481e+02 | \n",
+ "
\n",
+ " \n",
+ " TOTAL NET | \n",
+ " -0.039444 | \n",
+ " 1.905973e-07 | \n",
+ " 2.265078e-07 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " WETH USDC USDT\n",
+ "c0 0.413264 -7.937258e+02 NaN\n",
+ "c1 -0.452708 NaN 9.483481e+02\n",
+ "c2 NaN 7.937258e+02 -9.483481e+02\n",
+ "PRICE 1.000000 5.421803e-04 4.557539e-04\n",
+ "AMMIn 0.413264 7.937258e+02 9.483481e+02\n",
+ "AMMOut -0.452708 -7.937258e+02 -9.483481e+02\n",
+ "TOTAL NET -0.039444 1.905973e-07 2.265078e-07"
+ ]
+ },
+ "execution_count": 117,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"ti = r.trade_instructions()\n",
"assert len(ti) == 3\n",
@@ -2851,10 +2972,98 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 118,
"id": "ccc9d286",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " pair | \n",
+ " pairp | \n",
+ " tknin | \n",
+ " tknout | \n",
+ " WETH | \n",
+ " USDC | \n",
+ " USDT | \n",
+ "
\n",
+ " \n",
+ " cid | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " c0 | \n",
+ " WETH/USDC | \n",
+ " WETH/USDC | \n",
+ " WETH | \n",
+ " USDC | \n",
+ " 0.413264 | \n",
+ " -793.725794 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " c1 | \n",
+ " WETH/USDT | \n",
+ " WETH/USDT | \n",
+ " USDT | \n",
+ " WETH | \n",
+ " -0.452708 | \n",
+ " NaN | \n",
+ " 948.34809 | \n",
+ "
\n",
+ " \n",
+ " c2 | \n",
+ " USDC/USDT | \n",
+ " USDC/USDT | \n",
+ " USDC | \n",
+ " USDT | \n",
+ " NaN | \n",
+ " 793.725794 | \n",
+ " -948.34809 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " pair pairp tknin tknout WETH USDC USDT\n",
+ "cid \n",
+ "c0 WETH/USDC WETH/USDC WETH USDC 0.413264 -793.725794 NaN\n",
+ "c1 WETH/USDT WETH/USDT USDT WETH -0.452708 NaN 948.34809\n",
+ "c2 USDC/USDT USDC/USDT USDC USDT NaN 793.725794 -948.34809"
+ ]
+ },
+ "execution_count": 118,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"df = r.trade_instructions(ti_format=O.TIF_DF)\n",
"assert len(df) == 3\n",
@@ -2864,10 +3073,98 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 119,
"id": "7c7f2301",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " pair | \n",
+ " pairp | \n",
+ " tknin | \n",
+ " tknout | \n",
+ " WETH | \n",
+ " USDC | \n",
+ " USDT | \n",
+ "
\n",
+ " \n",
+ " cid | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " c0 | \n",
+ " WETH/USDC | \n",
+ " WETH/USDC | \n",
+ " WETH | \n",
+ " USDC | \n",
+ " 0.413264 | \n",
+ " -793.725794 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " c1 | \n",
+ " WETH/USDT | \n",
+ " WETH/USDT | \n",
+ " USDT | \n",
+ " WETH | \n",
+ " -0.452708 | \n",
+ " | \n",
+ " 948.34809 | \n",
+ "
\n",
+ " \n",
+ " c2 | \n",
+ " USDC/USDT | \n",
+ " USDC/USDT | \n",
+ " USDC | \n",
+ " USDT | \n",
+ " | \n",
+ " 793.725794 | \n",
+ " -948.34809 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " pair pairp tknin tknout WETH USDC USDT\n",
+ "cid \n",
+ "c0 WETH/USDC WETH/USDC WETH USDC 0.413264 -793.725794 \n",
+ "c1 WETH/USDT WETH/USDT USDT WETH -0.452708 948.34809\n",
+ "c2 USDC/USDT USDC/USDT USDC USDT 793.725794 -948.34809"
+ ]
+ },
+ "execution_count": 119,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"df = r.trade_instructions(ti_format=O.TIF_DF).fillna(\"\")\n",
"assert len(df) == 3\n",
@@ -2878,10 +3175,38 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 120,
"id": "c5cb20e7",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "({'cid': 'c0',\n",
+ " 'tknin': 'WETH',\n",
+ " 'amtin': 0.41326380379418914,\n",
+ " 'tknout': 'USDC',\n",
+ " 'amtout': -793.7257935280832,\n",
+ " 'error': None},\n",
+ " {'cid': 'c1',\n",
+ " 'tknin': 'USDT',\n",
+ " 'amtin': 948.3480897734917,\n",
+ " 'tknout': 'WETH',\n",
+ " 'amtout': -0.4527078152937758,\n",
+ " 'error': None},\n",
+ " {'cid': 'c2',\n",
+ " 'tknin': 'USDC',\n",
+ " 'amtin': 793.7257937186805,\n",
+ " 'tknout': 'USDT',\n",
+ " 'amtout': -948.3480895469838,\n",
+ " 'error': None})"
+ ]
+ },
+ "execution_count": 120,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"dcts = r.trade_instructions(ti_format=O.TIF_DICTS)\n",
"assert len(dcts) == 3\n",
@@ -2894,10 +3219,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 121,
"id": "4b3ee562",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(CPCArbOptimizer.TradeInstruction(cid='c0', tknin='WETH', amtin=0.41326380379418914, tknout='USDC', amtout=-793.7257935280832, error=None),\n",
+ " CPCArbOptimizer.TradeInstruction(cid='c1', tknin='USDT', amtin=948.3480897734917, tknout='WETH', amtout=-0.4527078152937758, error=None),\n",
+ " CPCArbOptimizer.TradeInstruction(cid='c2', tknin='USDC', amtin=793.7257937186805, tknout='USDT', amtout=-948.3480895469838, error=None))"
+ ]
+ },
+ "execution_count": 121,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"objs = r.trade_instructions(ti_format=O.TIF_OBJECTS)\n",
"assert len(objs) == 3\n",
@@ -2907,10 +3245,24 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 122,
"id": "39fdcea2",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Help on method trade_instructions in module fastlane_bot.tools.optimizer.cpcarboptimizer:\n",
+ "\n",
+ "trade_instructions(ti_format=None) method of fastlane_bot.tools.optimizer.cpcarboptimizer.MargpOptimizerResult instance\n",
+ " returns list of TradeInstruction objects\n",
+ " \n",
+ " :ti_format: TIF_OBJECTS, TIF_DICTS, TIF_DFP, TIF_DFRAW, TIF_DFAGGR, TIF_DF\n",
+ "\n"
+ ]
+ }
+ ],
"source": [
"help(r.trade_instructions)"
]
@@ -2925,10 +3277,22 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 123,
"id": "528abf9c",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "ename": "TypeError",
+ "evalue": "Can't instantiate abstract class CPCArbOptimizer with abstract methods kind",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
+ "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mCC\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCPCContainer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mCPC\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_pk\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mp\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m2000\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mk\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m20000\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;36m10000\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpair\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34mf\"{T.ETH}/{T.USDC}\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m11\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mO\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCPCArbOptimizer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mCC\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mc0\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCC\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcurves\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mCC0\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCPCContainer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mc0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mO\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mSimpleOptimizer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mCC\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+ "\u001b[0;31mTypeError\u001b[0m: Can't instantiate abstract class CPCArbOptimizer with abstract methods kind"
+ ]
+ }
+ ],
"source": [
"CC = CPCContainer(CPC.from_pk(p=2000+i*100, k=10*(20000+i*10000), pair=f\"{T.ETH}/{T.USDC}\") for i in range(11))\n",
"O = CPCArbOptimizer(CC)\n",