Skip to content

Instantly share code, notes, and snippets.

@KenoLeon
Created May 18, 2023 17:15
Show Gist options
  • Select an option

  • Save KenoLeon/c60e16b8fe052bac40af66cf5f071aa7 to your computer and use it in GitHub Desktop.

Select an option

Save KenoLeon/c60e16b8fe052bac40af66cf5f071aa7 to your computer and use it in GitHub Desktop.
Numerai Daily Scripts.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/KenoLeon/c60e16b8fe052bac40af66cf5f071aa7/numerai-daily-scripts.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "dC4J53y1MYNJ"
},
"outputs": [],
"source": [
"pip install --upgrade numerapi"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "T8_rvTCI2QdY"
},
"outputs": [],
"source": [
"# GET BALANCE OF A SINGLE MODEL/ACCOUNT\n",
"\n",
"from numerapi.numerapi import NumerAPI\n",
"\n",
"\n",
"def main():\n",
" modelskeys = [\n",
"\n",
" [\n",
" \"MODEL\",\n",
" \"\",\n",
" \"\"\n",
" ]\n",
" ]\n",
"\n",
" napi = NumerAPI(verbosity=\"info\")\n",
" for model in modelskeys:\n",
" napi = NumerAPI(model[2], model[1])\n",
" res = (napi.get_account())\n",
" print(str(res['username']) + ' NMR: ' + str(res['availableNmr']))\n",
"\n",
"\n",
"if __name__ == \"__main__\":\n",
" main()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "1NlPtCTvMdzz"
},
"outputs": [],
"source": [
"# GET STAKES (WITHOUT PAYOUTS)\n",
"\n",
"from numerapi.numerapi import NumerAPI\n",
"import numerapi\n",
"\n",
"api = NumerAPI()\n",
"stakes = float(api.stake_get(\"ModelName\"))\n",
"stakes = round(stakes, 2)\n",
"print(\"ModelName: \" + str(stakes))\n",
"\n",
"stakes = float(api.stake_get(\"ModelName\"))\n",
"stakes = round(stakes, 2)\n",
"print(\"ModelName: \" + str(stakes))\n",
"\n",
"stakes = float(api.stake_get(\"ModelName\"))\n",
"stakes = round(stakes, 3)\n",
"print(\"ModelName: \" + str(stakes))"
]
},
{
"cell_type": "code",
"source": [
"# /////////////////////// ⭐️ DAILY PERF ⭐️ /////////////////////////////\n",
"from numerapi.numerapi import NumerAPI\n",
"import numerapi\n",
"\n",
"api = NumerAPI()\n",
"\n",
"def calculate_model_payout(model):\n",
" query = '''query($modelName: String!) { \n",
" v3UserProfile(modelName: $modelName) {\n",
" roundModelPerformances {\n",
" roundNumber\n",
" roundResolved\n",
" payout\n",
" selectedStakeValue\n",
" }\n",
" }\n",
" }'''\n",
"\n",
" args = {'modelName': model}\n",
" res = api.raw_query(query, args)\n",
" data = res['data']\n",
"\n",
" filtered_performances = [performance for performance in data['v3UserProfile']['roundModelPerformances'] \n",
" if performance['payout'] is not None and performance['roundResolved'] is False]\n",
"\n",
" total_payout = 0\n",
" for performance in filtered_performances: \n",
" payout = performance['payout']\n",
" print(\"Round\", performance['roundNumber'], \"Payout:\", payout)\n",
" total_payout += float(performance['payout'])\n",
" print(\"Total Payout:\", total_payout)\n",
"\n",
" stakes = float(api.stake_get(model))\n",
" print(model + \" Current Stake : \" + str(stakes))\n",
" print(model + \" Net : \" + str(stakes+total_payout))\n",
" print(\"|| ------------ * ------------ ||\")\n",
"\n",
" return stakes + total_payout\n",
"\n",
"models = [\"model1\", \"model2\", \"model3\"]\n",
"\n",
"total_payouts = []\n",
"for model in models:\n",
" total_payout = calculate_model_payout(model)\n",
" total_payouts.append(total_payout)\n",
"\n",
"print(\"Total payouts:\")\n",
"for payout in total_payouts:\n",
" print(payout)\n",
"\n",
"\n"
],
"metadata": {
"id": "fYQLtefDaZbA"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# /////////////////////// Look ahead 👀 /////////////////////////////\n",
"\n",
"from numerapi import NumerAPI\n",
"api = NumerAPI()\n",
"round_number = 464\n",
"\n",
"def calculate_total_payout_for_round(round_number):\n",
" models = [\"model1\", \"model2\", \"model3\"]\n",
" total_payout = 0\n",
" \n",
" for model in models:\n",
" query = '''query($modelName: String!) { \n",
" v3UserProfile(modelName: $modelName) {\n",
" roundModelPerformances {\n",
" roundNumber\n",
" roundResolved\n",
" payout\n",
" selectedStakeValue\n",
" }\n",
" }\n",
" }'''\n",
"\n",
" args = {'modelName': model}\n",
" res = api.raw_query(query, args)\n",
" data = res['data']\n",
"\n",
" filtered_performances = [performance for performance in data['v3UserProfile']['roundModelPerformances'] \n",
" if performance['roundNumber'] == round_number and performance['payout'] is not None \n",
" and performance['roundResolved'] is False]\n",
"\n",
" for performance in filtered_performances: \n",
" payout = performance['payout']\n",
" print(\"Model: \" + model + \" Round \" + str(round_number) + \" Payout: \" + str(payout))\n",
" total_payout += float(performance['payout'])\n",
" \n",
" print(\"Total Payout for Round \" + str(round_number) + \" is: \" + str(total_payout))\n",
" return total_payout\n",
"\n",
"calculate_total_payout_for_round(round_number)"
],
"metadata": {
"id": "D2mh4YDDet4O"
},
"execution_count": null,
"outputs": []
}
],
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyOWHMJ2FpU9XnX+o0q1C2qi",
"include_colab_link": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment