start of refactor to objects
This commit is contained in:
314
extended.ipynb
314
extended.ipynb
@@ -2,7 +2,7 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 2,
|
||||
"id": "6c70a8c3",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -27,7 +27,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 3,
|
||||
"id": "ff971ca9",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -41,15 +41,15 @@
|
||||
"\n",
|
||||
"CONFIG = MAINNET_CONFIG\n",
|
||||
"\n",
|
||||
"ORDER_MARKET = \"BTC-USD\"\n",
|
||||
"ORDER_MARKET = \"ETH-USD\"\n",
|
||||
"ORDER_SIDE = OrderSide.BUY\n",
|
||||
"ORDER_QTY = Decimal(\"0.001\")\n",
|
||||
"ORDER_PRICE = Decimal(\"75000\")"
|
||||
"ORDER_QTY = Decimal(\"0.01\")\n",
|
||||
"ORDER_PRICE = Decimal(\"2200\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"execution_count": 4,
|
||||
"id": "fc2c6d2b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -59,18 +59,116 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 41,
|
||||
"id": "c366706f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# placed_order = await trading_client.place_order(\n",
|
||||
"# market_name=ORDER_MARKET,\n",
|
||||
"# amount_of_synthetic=ORDER_QTY,\n",
|
||||
"# price=ORDER_PRICE,\n",
|
||||
"# side=ORDER_SIDE,\n",
|
||||
"# taker_fee=Decimal(\"0.00025\")\n",
|
||||
"# )"
|
||||
"placed_order = await trading_client.place_order(\n",
|
||||
" market_name=ORDER_MARKET,\n",
|
||||
" amount_of_synthetic=ORDER_QTY,\n",
|
||||
" price=ORDER_PRICE,\n",
|
||||
" side=ORDER_SIDE,\n",
|
||||
" taker_fee=Decimal(\"0.00025\"),\n",
|
||||
" previous_order_id='1295034892466447624365619416628580523728221205816494340545831832663414858661'\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"WrappedApiResponse[EmptyModel](status='OK', data=EmptyModel(), error=None, pagination=None)"
|
||||
]
|
||||
},
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"c = await trading_client.orders.mass_cancel(markets=['ETH-USD'])\n",
|
||||
"c"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 59,
|
||||
"id": "1e0cc529",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"d = dict(placed_order)\n",
|
||||
"d = d['data']"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 61,
|
||||
"id": "c6e2570b",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'id': 2047411567531950080,\n",
|
||||
" 'external_id': '970778360519119766032805910949664642915982435081116578514332451865869879614'}"
|
||||
]
|
||||
},
|
||||
"execution_count": 61,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"dict(d)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "3e4cedd1",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'OK'"
|
||||
]
|
||||
},
|
||||
"execution_count": 58,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"dict(placed_order).get('status' \\\n",
|
||||
"'')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Timestamp('2026-04-23 23:55:13.704000')"
|
||||
]
|
||||
},
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"pd.to_datetime(1776988513704, unit='ms')"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -80,28 +178,136 @@
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[PositionModel(id=2047419314696355840, account_id=270571, market='ETH-USD', status='OPENED', side='LONG', leverage=Decimal('50'), size=Decimal('0.215'), value=Decimal('500.247305'), open_price=Decimal('2321.7'), mark_price=Decimal('2326.731653474999'), liquidation_price=Decimal('2222.8'), unrealised_pnl=Decimal('1.081805'), realised_pnl=Decimal('0.065534'), tp_price=None, sl_price=None, adl=2, created_at=1776977778498, updated_at=1776986778819)]"
|
||||
]
|
||||
},
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"d = dict(await trading_client.account.get_positions()).get('data')\n",
|
||||
"d"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"id": "b9ac87f2",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'id': 2047419314696355840,\n",
|
||||
" 'account_id': 270571,\n",
|
||||
" 'market': 'ETH-USD',\n",
|
||||
" 'status': 'OPENED',\n",
|
||||
" 'side': 'LONG',\n",
|
||||
" 'leverage': Decimal('50'),\n",
|
||||
" 'size': Decimal('0.215'),\n",
|
||||
" 'value': Decimal('500.247305'),\n",
|
||||
" 'open_price': Decimal('2321.7'),\n",
|
||||
" 'mark_price': Decimal('2326.731653474999'),\n",
|
||||
" 'liquidation_price': Decimal('2222.8'),\n",
|
||||
" 'unrealised_pnl': Decimal('1.081805'),\n",
|
||||
" 'realised_pnl': Decimal('0.065534'),\n",
|
||||
" 'tp_price': None,\n",
|
||||
" 'sl_price': None,\n",
|
||||
" 'adl': 2,\n",
|
||||
" 'created_at': 1776977778498,\n",
|
||||
" 'updated_at': 1776986778819}"
|
||||
]
|
||||
},
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"dict(d[0])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "62299776",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "IndexError",
|
||||
"evalue": "list index out of range",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
|
||||
"\u001b[31mIndexError\u001b[39m Traceback (most recent call last)",
|
||||
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[40]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m [j \u001b[38;5;28;01mfor\u001b[39;00m j \u001b[38;5;28;01min\u001b[39;00m d \u001b[38;5;28;01mif\u001b[39;00m j.get(\u001b[33m'market'\u001b[39m) == \u001b[33m'ETH-USD'\u001b[39m][\u001b[32m0\u001b[39m]\n",
|
||||
"\u001b[31mIndexError\u001b[39m: list index out of range"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"[j for j in d if j.get('market') == 'ETH-USD']"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 31,
|
||||
"id": "7cd3413d",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"source": [
|
||||
"balance = dict(dict(await trading_client.account.get_balance()).get('data', {}))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "62632db3",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"source": [
|
||||
"r = await trading_client.markets_info.get_pos"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "a7212988",
|
||||
"execution_count": 55,
|
||||
"id": "e9c3fdc4",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"source": [
|
||||
"d = r['ETH-USD'].trading_config"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 58,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"0.01"
|
||||
]
|
||||
},
|
||||
"execution_count": 58,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"float(d.min_order_size)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
@@ -346,17 +552,85 @@
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"id": "b0388dc7",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import valkey\n",
|
||||
"import json\n",
|
||||
"VAL_KEY = valkey.Valkey(host='localhost', port=6379, db=0, decode_responses=True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"b = json.loads(VAL_KEY.get('fund_rate_aster'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"a = json.loads(VAL_KEY.get('fund_rate_aster'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"id": "665377af",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'timestamp_arrival': 1776970338127,\n",
|
||||
" 'timestamp_msg': 1776970338000,\n",
|
||||
" 'symbol': 'ETHUSDT',\n",
|
||||
" 'mark_price': '2310.59000000',\n",
|
||||
" 'index_price': '2311.29372093',\n",
|
||||
" 'estimated_settle_price': '2312.11380907',\n",
|
||||
" 'funding_rate': '-0.00001108',\n",
|
||||
" 'next_funding_time_ts_ms': 1776988800000}"
|
||||
]
|
||||
},
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"json.loads(VAL_KEY.get('fund_rate_aster'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"id": "f15dd3c7",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"VAL_KEY.get('fr_aster_user_positions')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "23f88a3e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "665377af",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
|
||||
Reference in New Issue
Block a user