{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "6070f9e8", "metadata": {}, "outputs": [], "source": [ "from openai import AzureOpenAI\n", "\n", "client = AzureOpenAI(\n", " api_key=\"734e15b7855f4c9f875630ce7f058f55\",\n", " api_version=\"2024-02-15-preview\", # depends on region & setup\n", " azure_endpoint=\"https://india-region-openai.openai.azure.com/openai/deployments/gpt4o/chat/completions?api-version=2024-02-15-preview\"\n", ")" ] }, { "cell_type": "code", "execution_count": 2, "id": "25578314", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "फ्रांस की राजधानी पेरिस है।\n" ] } ], "source": [ "response = client.chat.completions.create(\n", " model=\"gpt-4o-mini\", # Or another suitable model\n", " messages=[\n", " {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n", " {\"role\": \"user\", \"content\": \"What is the capital of France? in hindi\"}\n", " ]\n", ")\n", "print(response.choices[0].message.content)" ] }, { "cell_type": "code", "execution_count": 1, "id": "747e0e68", "metadata": {}, "outputs": [], "source": [ "from openai import OpenAI\n", "\n", "client = OpenAI(\n", " api_key=\"AIzaSyCn2Uu0j7f37W_mbI3cR-_dEUZb5zSafbU\",\n", " base_url=\"https://generativelanguage.googleapis.com/v1beta/openai/\"\n", ")" ] }, { "cell_type": "code", "execution_count": 2, "id": "0d14dd0e", "metadata": {}, "outputs": [ { "ename": "RateLimitError", "evalue": "Error code: 429 - [{'error': {'code': 429, 'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, head to: https://ai.google.dev/gemini-api/docs/rate-limits. To monitor your current usage, head to: https://ai.dev/usage?tab=rate-limit. \\n* Quota exceeded for metric: generativelanguage.googleapis.com/generate_content_free_tier_requests, limit: 0, model: gemini-3-pro\\n* Quota exceeded for metric: generativelanguage.googleapis.com/generate_content_free_tier_requests, limit: 0, model: gemini-3-pro\\nPlease retry in 35.786346879s.', 'status': 'RESOURCE_EXHAUSTED', 'details': [{'@type': 'type.googleapis.com/google.rpc.Help', 'links': [{'description': 'Learn more about Gemini API quotas', 'url': 'https://ai.google.dev/gemini-api/docs/rate-limits'}]}, {'@type': 'type.googleapis.com/google.rpc.QuotaFailure', 'violations': [{'quotaMetric': 'generativelanguage.googleapis.com/generate_content_free_tier_requests', 'quotaId': 'GenerateRequestsPerMinutePerProjectPerModel-FreeTier', 'quotaDimensions': {'model': 'gemini-3-pro', 'location': 'global'}}, {'quotaMetric': 'generativelanguage.googleapis.com/generate_content_free_tier_requests', 'quotaId': 'GenerateRequestsPerDayPerProjectPerModel-FreeTier', 'quotaDimensions': {'model': 'gemini-3-pro', 'location': 'global'}}]}, {'@type': 'type.googleapis.com/google.rpc.RetryInfo', 'retryDelay': '35s'}]}}]", "output_type": "error", "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mRateLimitError\u001b[39m Traceback (most recent call last)", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[2]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m response = \u001b[43mclient\u001b[49m\u001b[43m.\u001b[49m\u001b[43mchat\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcompletions\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcreate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 2\u001b[39m \u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mgemini-3-pro-preview\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# Or another suitable model\u001b[39;49;00m\n\u001b[32m 3\u001b[39m \u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m=\u001b[49m\u001b[43m[\u001b[49m\n\u001b[32m 4\u001b[39m \u001b[43m \u001b[49m\u001b[43m{\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mrole\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43msystem\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mcontent\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mYou are a helpful assistant.\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m}\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5\u001b[39m \u001b[43m \u001b[49m\u001b[43m{\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mrole\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43muser\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mcontent\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mWhat is the capital of France? in hindi\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m}\u001b[49m\n\u001b[32m 6\u001b[39m \u001b[43m \u001b[49m\u001b[43m]\u001b[49m\n\u001b[32m 7\u001b[39m \u001b[43m)\u001b[49m\n\u001b[32m 8\u001b[39m \u001b[38;5;28mprint\u001b[39m(response.choices[\u001b[32m0\u001b[39m].message.content)\n", "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\PaTeL\\anaconda3\\envs\\trade\\Lib\\site-packages\\openai\\_utils\\_utils.py:287\u001b[39m, in \u001b[36mrequired_args..inner..wrapper\u001b[39m\u001b[34m(*args, **kwargs)\u001b[39m\n\u001b[32m 285\u001b[39m msg = \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mMissing required argument: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mquote(missing[\u001b[32m0\u001b[39m])\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m\n\u001b[32m 286\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(msg)\n\u001b[32m--> \u001b[39m\u001b[32m287\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\PaTeL\\anaconda3\\envs\\trade\\Lib\\site-packages\\openai\\resources\\chat\\completions\\completions.py:1087\u001b[39m, in \u001b[36mCompletions.create\u001b[39m\u001b[34m(self, messages, model, audio, frequency_penalty, function_call, functions, logit_bias, logprobs, max_completion_tokens, max_tokens, metadata, modalities, n, parallel_tool_calls, prediction, presence_penalty, reasoning_effort, response_format, seed, service_tier, stop, store, stream, stream_options, temperature, tool_choice, tools, top_logprobs, top_p, user, web_search_options, extra_headers, extra_query, extra_body, timeout)\u001b[39m\n\u001b[32m 1044\u001b[39m \u001b[38;5;129m@required_args\u001b[39m([\u001b[33m\"\u001b[39m\u001b[33mmessages\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mmodel\u001b[39m\u001b[33m\"\u001b[39m], [\u001b[33m\"\u001b[39m\u001b[33mmessages\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mmodel\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mstream\u001b[39m\u001b[33m\"\u001b[39m])\n\u001b[32m 1045\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mcreate\u001b[39m(\n\u001b[32m 1046\u001b[39m \u001b[38;5;28mself\u001b[39m,\n\u001b[32m (...)\u001b[39m\u001b[32m 1084\u001b[39m timeout: \u001b[38;5;28mfloat\u001b[39m | httpx.Timeout | \u001b[38;5;28;01mNone\u001b[39;00m | NotGiven = NOT_GIVEN,\n\u001b[32m 1085\u001b[39m ) -> ChatCompletion | Stream[ChatCompletionChunk]:\n\u001b[32m 1086\u001b[39m validate_response_format(response_format)\n\u001b[32m-> \u001b[39m\u001b[32m1087\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_post\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 1088\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m/chat/completions\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 1089\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmaybe_transform\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 1090\u001b[39m \u001b[43m \u001b[49m\u001b[43m{\u001b[49m\n\u001b[32m 1091\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmessages\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1092\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmodel\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1093\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43maudio\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43maudio\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1094\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mfrequency_penalty\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mfrequency_penalty\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1095\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mfunction_call\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mfunction_call\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1096\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mfunctions\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mfunctions\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1097\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mlogit_bias\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mlogit_bias\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1098\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mlogprobs\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mlogprobs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1099\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmax_completion_tokens\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmax_completion_tokens\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1100\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmax_tokens\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmax_tokens\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1101\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmetadata\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmetadata\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1102\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmodalities\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmodalities\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1103\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mn\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mn\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1104\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mparallel_tool_calls\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mparallel_tool_calls\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1105\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mprediction\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mprediction\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1106\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mpresence_penalty\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mpresence_penalty\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1107\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mreasoning_effort\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mreasoning_effort\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1108\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mresponse_format\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mresponse_format\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1109\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mseed\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mseed\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1110\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mservice_tier\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mservice_tier\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1111\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mstop\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1112\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mstore\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mstore\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1113\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mstream\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1114\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mstream_options\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1115\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtemperature\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtemperature\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1116\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtool_choice\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtool_choice\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1117\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtools\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtools\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1118\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtop_logprobs\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtop_logprobs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1119\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtop_p\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtop_p\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1120\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43muser\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43muser\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1121\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mweb_search_options\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mweb_search_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1122\u001b[39m \u001b[43m \u001b[49m\u001b[43m}\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1123\u001b[39m \u001b[43m \u001b[49m\u001b[43mcompletion_create_params\u001b[49m\u001b[43m.\u001b[49m\u001b[43mCompletionCreateParamsStreaming\u001b[49m\n\u001b[32m 1124\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\n\u001b[32m 1125\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mcompletion_create_params\u001b[49m\u001b[43m.\u001b[49m\u001b[43mCompletionCreateParamsNonStreaming\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1126\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1127\u001b[39m \u001b[43m \u001b[49m\u001b[43moptions\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmake_request_options\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 1128\u001b[39m \u001b[43m \u001b[49m\u001b[43mextra_headers\u001b[49m\u001b[43m=\u001b[49m\u001b[43mextra_headers\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mextra_query\u001b[49m\u001b[43m=\u001b[49m\u001b[43mextra_query\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mextra_body\u001b[49m\u001b[43m=\u001b[49m\u001b[43mextra_body\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtimeout\u001b[49m\n\u001b[32m 1129\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1130\u001b[39m \u001b[43m \u001b[49m\u001b[43mcast_to\u001b[49m\u001b[43m=\u001b[49m\u001b[43mChatCompletion\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1131\u001b[39m \u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstream\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[32m 1132\u001b[39m \u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[43m=\u001b[49m\u001b[43mStream\u001b[49m\u001b[43m[\u001b[49m\u001b[43mChatCompletionChunk\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1133\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\PaTeL\\anaconda3\\envs\\trade\\Lib\\site-packages\\openai\\_base_client.py:1256\u001b[39m, in \u001b[36mSyncAPIClient.post\u001b[39m\u001b[34m(self, path, cast_to, body, options, files, stream, stream_cls)\u001b[39m\n\u001b[32m 1242\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mpost\u001b[39m(\n\u001b[32m 1243\u001b[39m \u001b[38;5;28mself\u001b[39m,\n\u001b[32m 1244\u001b[39m path: \u001b[38;5;28mstr\u001b[39m,\n\u001b[32m (...)\u001b[39m\u001b[32m 1251\u001b[39m stream_cls: \u001b[38;5;28mtype\u001b[39m[_StreamT] | \u001b[38;5;28;01mNone\u001b[39;00m = \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[32m 1252\u001b[39m ) -> ResponseT | _StreamT:\n\u001b[32m 1253\u001b[39m opts = FinalRequestOptions.construct(\n\u001b[32m 1254\u001b[39m method=\u001b[33m\"\u001b[39m\u001b[33mpost\u001b[39m\u001b[33m\"\u001b[39m, url=path, json_data=body, files=to_httpx_files(files), **options\n\u001b[32m 1255\u001b[39m )\n\u001b[32m-> \u001b[39m\u001b[32m1256\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m cast(ResponseT, \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcast_to\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mopts\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[43m)\u001b[49m)\n", "\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\PaTeL\\anaconda3\\envs\\trade\\Lib\\site-packages\\openai\\_base_client.py:1044\u001b[39m, in \u001b[36mSyncAPIClient.request\u001b[39m\u001b[34m(self, cast_to, options, stream, stream_cls)\u001b[39m\n\u001b[32m 1041\u001b[39m err.response.read()\n\u001b[32m 1043\u001b[39m log.debug(\u001b[33m\"\u001b[39m\u001b[33mRe-raising status error\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m-> \u001b[39m\u001b[32m1044\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;28mself\u001b[39m._make_status_error_from_response(err.response) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m 1046\u001b[39m \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[32m 1048\u001b[39m \u001b[38;5;28;01massert\u001b[39;00m response \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m, \u001b[33m\"\u001b[39m\u001b[33mcould not resolve response (should never happen)\u001b[39m\u001b[33m\"\u001b[39m\n", "\u001b[31mRateLimitError\u001b[39m: Error code: 429 - [{'error': {'code': 429, 'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, head to: https://ai.google.dev/gemini-api/docs/rate-limits. To monitor your current usage, head to: https://ai.dev/usage?tab=rate-limit. \\n* Quota exceeded for metric: generativelanguage.googleapis.com/generate_content_free_tier_requests, limit: 0, model: gemini-3-pro\\n* Quota exceeded for metric: generativelanguage.googleapis.com/generate_content_free_tier_requests, limit: 0, model: gemini-3-pro\\nPlease retry in 35.786346879s.', 'status': 'RESOURCE_EXHAUSTED', 'details': [{'@type': 'type.googleapis.com/google.rpc.Help', 'links': [{'description': 'Learn more about Gemini API quotas', 'url': 'https://ai.google.dev/gemini-api/docs/rate-limits'}]}, {'@type': 'type.googleapis.com/google.rpc.QuotaFailure', 'violations': [{'quotaMetric': 'generativelanguage.googleapis.com/generate_content_free_tier_requests', 'quotaId': 'GenerateRequestsPerMinutePerProjectPerModel-FreeTier', 'quotaDimensions': {'model': 'gemini-3-pro', 'location': 'global'}}, {'quotaMetric': 'generativelanguage.googleapis.com/generate_content_free_tier_requests', 'quotaId': 'GenerateRequestsPerDayPerProjectPerModel-FreeTier', 'quotaDimensions': {'model': 'gemini-3-pro', 'location': 'global'}}]}, {'@type': 'type.googleapis.com/google.rpc.RetryInfo', 'retryDelay': '35s'}]}}]" ] } ], "source": [ "response = client.chat.completions.create(\n", " model=\"gemini-3-pro-preview\", # Or another suitable model\n", " messages=[\n", " {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n", " {\"role\": \"user\", \"content\": \"What is the capital of France? in hindi\"}\n", " ]\n", ")\n", "print(response.choices[0].message.content)" ] }, { "cell_type": "code", "execution_count": 8, "id": "2c2e5773", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "d:\\Project\\tradellm\\data\\main\\5_simulation_inference_3\n" ] } ], "source": [ "cd .." ] }, { "cell_type": "code", "execution_count": 9, "id": "b4f67e89", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Volume in drive D is PaTeL\n", " Volume Serial Number is 1A7B-14BD\n", "\n", " Directory of d:\\Project\\tradellm\\data\\main\\5_simulation_inference_3\n", "\n", "27-11-2025 04:01 PM .\n", "27-11-2025 04:01 PM ..\n", "27-11-2025 02:49 PM 650 .env\n", "03-11-2025 07:56 PM 95 .env.example\n", "25-11-2025 11:03 PM app\n", "03-11-2025 07:11 PM best_result_gemini_2.5_pro\n", "05-11-2025 03:48 PM data\n", "27-11-2025 04:24 PM data-generation-gpt-4o-mini-newsonly-t-0.6-tp-0.6\n", "27-11-2025 04:24 PM data-generation-gpt-4o-mini-t-0.6-tp-0.6\n", "27-11-2025 02:49 PM data-generation-gpt-4o-t-0.6-tp-0.7\n", "27-11-2025 03:24 PM gemini-3-edited\n", "27-11-2025 03:22 PM 497,413 gemini-3-edited.zip\n", "26-11-2025 11:18 PM gpt-4o-expert\n", "26-11-2025 06:46 PM gpt-4o-mini-expert\n", "26-11-2025 11:19 PM gpt-4o-mini-expert-tushar\n", "26-11-2025 04:47 PM gpt-4o-mini-news-expert\n", "26-11-2025 06:46 PM gpt-4o-mini-news-only\n", "26-11-2025 03:45 PM gpt-4o-news-only\n", "23-11-2025 07:39 PM 9,319 README.md\n", "03-11-2025 01:26 PM 209 requirements.txt\n", "03-11-2025 01:21 PM scripts\n", " 5 File(s) 507,686 bytes\n", " 16 Dir(s) 17,007,751,168 bytes free\n" ] } ], "source": [ "!dir" ] }, { "cell_type": "code", "execution_count": 10, "id": "9b4f422a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
enteredentry_timeentry_pricesideexitedexit_timeexit_priceexit_reasonpnl_pctopen_positionunrealized_pctnotedatetime
0True2024-01-01 15:15:0048215shortTrue2024-01-01 15:22:0048080.0target0.2800FalseNaNNaN2024-01-01 15:29:00
1True2024-01-02 09:56:0048035shortFalseNaTNaNNaNNaNTrue0.1382NaN2024-01-02 10:15:00
2True2024-01-02 09:56:0048035shortFalseNaTNaNNaNNaNTrue0.3610NaN2024-01-02 11:15:00
3True2024-01-02 09:56:0048035shortFalseNaTNaNNaNNaNTrue0.3652NaN2024-01-02 12:15:00
4True2024-01-02 09:56:0048035shortTrue2024-01-02 13:04:0047800.0target0.4892FalseNaNNaN2024-01-02 13:15:00
..........................................
435True2024-04-29 12:17:0048920longFalseNaTNaNNaNNaNTrue0.1571NaN2024-04-29 13:15:00
436True2024-04-29 12:17:0048920longTrue2024-04-29 13:26:0049150.0target0.4702FalseNaNNaN2024-04-29 14:15:00
437True2024-04-30 09:16:0049500longFalseNaTNaNNaNNaNTrue0.0090NaN2024-04-30 10:15:00
438True2024-04-30 09:16:0049500longFalseNaTNaNNaNNaNTrue0.1771NaN2024-04-30 11:15:00
439True2024-04-30 09:16:0049500longTrue2024-04-30 11:30:0049520.0stoploss0.0404FalseNaNNaN2024-04-30 12:15:00
\n", "

164 rows × 13 columns

\n", "
" ], "text/plain": [ " entered entry_time entry_price side exited \\\n", "0 True 2024-01-01 15:15:00 48215 short True \n", "1 True 2024-01-02 09:56:00 48035 short False \n", "2 True 2024-01-02 09:56:00 48035 short False \n", "3 True 2024-01-02 09:56:00 48035 short False \n", "4 True 2024-01-02 09:56:00 48035 short True \n", ".. ... ... ... ... ... \n", "435 True 2024-04-29 12:17:00 48920 long False \n", "436 True 2024-04-29 12:17:00 48920 long True \n", "437 True 2024-04-30 09:16:00 49500 long False \n", "438 True 2024-04-30 09:16:00 49500 long False \n", "439 True 2024-04-30 09:16:00 49500 long True \n", "\n", " exit_time exit_price exit_reason pnl_pct open_position \\\n", "0 2024-01-01 15:22:00 48080.0 target 0.2800 False \n", "1 NaT NaN NaN NaN True \n", "2 NaT NaN NaN NaN True \n", "3 NaT NaN NaN NaN True \n", "4 2024-01-02 13:04:00 47800.0 target 0.4892 False \n", ".. ... ... ... ... ... \n", "435 NaT NaN NaN NaN True \n", "436 2024-04-29 13:26:00 49150.0 target 0.4702 False \n", "437 NaT NaN NaN NaN True \n", "438 NaT NaN NaN NaN True \n", "439 2024-04-30 11:30:00 49520.0 stoploss 0.0404 False \n", "\n", " unrealized_pct note datetime \n", "0 NaN NaN 2024-01-01 15:29:00 \n", "1 0.1382 NaN 2024-01-02 10:15:00 \n", "2 0.3610 NaN 2024-01-02 11:15:00 \n", "3 0.3652 NaN 2024-01-02 12:15:00 \n", "4 NaN NaN 2024-01-02 13:15:00 \n", ".. ... ... ... \n", "435 0.1571 NaN 2024-04-29 13:15:00 \n", "436 NaN NaN 2024-04-29 14:15:00 \n", "437 0.0090 NaN 2024-04-30 10:15:00 \n", "438 0.1771 NaN 2024-04-30 11:15:00 \n", "439 NaN NaN 2024-04-30 12:15:00 \n", "\n", "[164 rows x 13 columns]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "df = pd.read_excel('./gemini-3-edited/gemini-3-edited/stats_log.xlsx')\n", "\n", "# Identify trades using (entry_time, entry_price)\n", "trade_groups = df.groupby(['entry_time', 'entry_price'])\n", "\n", "valid_trades = []\n", "\n", "for (entry_time, entry_price), grp in trade_groups:\n", "\n", " # 1) Check if the trade closed profitably\n", " closed_rows = grp[grp['exited'] == True]\n", "\n", " if closed_rows.empty:\n", " continue # skip open trades\n", "\n", " pnl = closed_rows['pnl_pct'].iloc[-1] # final pnl\n", "\n", " if pnl <= 0:\n", " continue # not profitable\n", "\n", " # 2) Check unrealized_pct is always >= 0 (or NaN)\n", " unreal = grp['unrealized_pct']\n", "\n", " # Replace NaN (closed rows) with a very positive number\n", " unreal_clean = unreal.fillna(999)\n", "\n", " if (unreal_clean >= 0).all():\n", " valid_trades.append(grp)\n", "\n", "# Combine all valid trades\n", "df_final = pd.concat(valid_trades)\n", "\n", "df_final\n" ] }, { "cell_type": "code", "execution_count": 11, "id": "8ee1965d", "metadata": {}, "outputs": [], "source": [ "df_final.to_excel(\"test_.xlsx\")" ] }, { "cell_type": "code", "execution_count": 12, "id": "a5bf0a01", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Volume in drive D is PaTeL\n", " Volume Serial Number is 1A7B-14BD\n", "\n", " Directory of d:\\Project\\tradellm\\data\\main\\5_simulation_inference_3\n", "\n", "27-11-2025 04:49 PM .\n", "27-11-2025 04:01 PM ..\n", "27-11-2025 02:49 PM 650 .env\n", "03-11-2025 07:56 PM 95 .env.example\n", "25-11-2025 11:03 PM app\n", "03-11-2025 07:11 PM best_result_gemini_2.5_pro\n", "05-11-2025 03:48 PM data\n", "27-11-2025 04:24 PM data-generation-gpt-4o-mini-newsonly-t-0.6-tp-0.6\n", "27-11-2025 04:24 PM data-generation-gpt-4o-mini-t-0.6-tp-0.6\n", "27-11-2025 02:49 PM data-generation-gpt-4o-t-0.6-tp-0.7\n", "27-11-2025 03:24 PM gemini-3-edited\n", "27-11-2025 03:22 PM 497,413 gemini-3-edited.zip\n", "26-11-2025 11:18 PM gpt-4o-expert\n", "26-11-2025 06:46 PM gpt-4o-mini-expert\n", "26-11-2025 11:19 PM gpt-4o-mini-expert-tushar\n", "26-11-2025 04:47 PM gpt-4o-mini-news-expert\n", "26-11-2025 06:46 PM gpt-4o-mini-news-only\n", "26-11-2025 03:45 PM gpt-4o-news-only\n", "23-11-2025 07:39 PM 9,319 README.md\n", "03-11-2025 01:26 PM 209 requirements.txt\n", "03-11-2025 01:21 PM scripts\n", "27-11-2025 04:49 PM 15,318 test_.xlsx\n", " 6 File(s) 523,004 bytes\n", " 16 Dir(s) 17,007,722,496 bytes free\n" ] } ], "source": [ "ls" ] }, { "cell_type": "code", "execution_count": 21, "id": "899f1d86", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['timestamp', 'identifier', 'system_prompt', 'user', 'assistant',\n", " 'response_format'],\n", " dtype='object')" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "trade.columns" ] }, { "cell_type": "code", "execution_count": 27, "id": "e3a84690", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
timestampidentifiersystem_promptuserassistantresponse_formatenteredentry_timeentry_pricesideexitedexit_timeexit_priceexit_reasonpnl_pctopen_positionunrealized_pctnotedatetimeprimary_key
02024-01-01 15:15:00trade_loop_!10:15You are an expert trading assistant capable of...\\nExpert analysis and past news indicate that ...{\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Con...{'$defs': {'SummaryBankNifty': {'properties': ...True2024-01-01 15:15:0048215shortTrue2024-01-01 15:22:0048080.0target0.2800FalseNaNNaN2024-01-01 15:29:002024-01-01 15:15:00
12024-01-02 09:15:00day_start_with_sentiment_and_expertYou are an expert trading assistant capable of...Based on the latest news, the predicted market...{\"major_concern_nifty50\":\"Formation of bearish...{'properties': {'major_concern_nifty50': {'des...True2024-01-02 09:56:0048035shortFalseNaTNaNNaNNaNTrue0.1382NaN2024-01-02 10:15:002024-01-02 09:15:00
22024-01-02 09:15:00day_start_tradeYou are an expert trading assistant capable of...Expert analysis and past news indicate that th...{\"status\":\"Trade\",\"brief_reason\":\"Bearish MACD...{'properties': {'status': {'enum': ['No trade'...True2024-01-02 09:56:0048035shortFalseNaTNaNNaNNaNTrue0.1382NaN2024-01-02 10:15:002024-01-02 09:15:00
32024-01-02 10:15:00trade_at_10:15You are an expert trading assistant capable of...Expert analysis and past news indicate that th...{\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Pri...{'$defs': {'SummaryBankNifty': {'properties': ...True2024-01-02 09:56:0048035shortFalseNaTNaNNaNNaNTrue0.3610NaN2024-01-02 11:15:002024-01-02 10:15:00
42024-01-02 11:15:00trade_loop_!10:15You are an expert trading assistant capable of...\\nExpert analysis and past news indicate that ...{\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Bea...{'$defs': {'SummaryBankNifty': {'properties': ...True2024-01-02 09:56:0048035shortFalseNaTNaNNaNNaNTrue0.3652NaN2024-01-02 12:15:002024-01-02 11:15:00
...............................................................
1812024-04-29 13:15:00trade_loop_!10:15You are an expert trading assistant capable of...\\nExpert analysis and past news indicate that ...{\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Bul...{'$defs': {'SummaryBankNifty': {'properties': ...True2024-04-29 12:17:0048920longTrue2024-04-29 13:26:0049150.0target0.4702FalseNaNNaN2024-04-29 14:15:002024-04-29 13:15:00
1822024-04-30 09:15:00day_start_with_sentiment_and_expertYou are an expert trading assistant capable of...Based on the latest news, the predicted market...{\"major_concern_nifty50\":\"The convergence of t...{'properties': {'major_concern_nifty50': {'des...True2024-04-30 09:16:0049500longFalseNaTNaNNaNNaNTrue0.0090NaN2024-04-30 10:15:002024-04-30 09:15:00
1832024-04-30 09:15:00day_start_tradeYou are an expert trading assistant capable of...Expert analysis and past news indicate that th...{\"status\":\"Trade\",\"brief_reason\":\"Bullish sent...{'properties': {'status': {'enum': ['No trade'...True2024-04-30 09:16:0049500longFalseNaTNaNNaNNaNTrue0.0090NaN2024-04-30 10:15:002024-04-30 09:15:00
1842024-04-30 10:15:00trade_at_10:15You are an expert trading assistant capable of...Expert analysis and past news indicate that th...{\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Hol...{'$defs': {'SummaryBankNifty': {'properties': ...True2024-04-30 09:16:0049500longFalseNaTNaNNaNNaNTrue0.1771NaN2024-04-30 11:15:002024-04-30 10:15:00
1852024-04-30 11:15:00trade_loop_!10:15You are an expert trading assistant capable of...\\nExpert analysis and past news indicate that ...{\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Tra...{'$defs': {'SummaryBankNifty': {'properties': ...True2024-04-30 09:16:0049500longTrue2024-04-30 11:30:0049520.0stoploss0.0404FalseNaNNaN2024-04-30 12:15:002024-04-30 11:15:00
\n", "

186 rows × 20 columns

\n", "
" ], "text/plain": [ " timestamp identifier \\\n", "0 2024-01-01 15:15:00 trade_loop_!10:15 \n", "1 2024-01-02 09:15:00 day_start_with_sentiment_and_expert \n", "2 2024-01-02 09:15:00 day_start_trade \n", "3 2024-01-02 10:15:00 trade_at_10:15 \n", "4 2024-01-02 11:15:00 trade_loop_!10:15 \n", ".. ... ... \n", "181 2024-04-29 13:15:00 trade_loop_!10:15 \n", "182 2024-04-30 09:15:00 day_start_with_sentiment_and_expert \n", "183 2024-04-30 09:15:00 day_start_trade \n", "184 2024-04-30 10:15:00 trade_at_10:15 \n", "185 2024-04-30 11:15:00 trade_loop_!10:15 \n", "\n", " system_prompt \\\n", "0 You are an expert trading assistant capable of... \n", "1 You are an expert trading assistant capable of... \n", "2 You are an expert trading assistant capable of... \n", "3 You are an expert trading assistant capable of... \n", "4 You are an expert trading assistant capable of... \n", ".. ... \n", "181 You are an expert trading assistant capable of... \n", "182 You are an expert trading assistant capable of... \n", "183 You are an expert trading assistant capable of... \n", "184 You are an expert trading assistant capable of... \n", "185 You are an expert trading assistant capable of... \n", "\n", " user \\\n", "0 \\nExpert analysis and past news indicate that ... \n", "1 Based on the latest news, the predicted market... \n", "2 Expert analysis and past news indicate that th... \n", "3 Expert analysis and past news indicate that th... \n", "4 \\nExpert analysis and past news indicate that ... \n", ".. ... \n", "181 \\nExpert analysis and past news indicate that ... \n", "182 Based on the latest news, the predicted market... \n", "183 Expert analysis and past news indicate that th... \n", "184 Expert analysis and past news indicate that th... \n", "185 \\nExpert analysis and past news indicate that ... \n", "\n", " assistant \\\n", "0 {\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Con... \n", "1 {\"major_concern_nifty50\":\"Formation of bearish... \n", "2 {\"status\":\"Trade\",\"brief_reason\":\"Bearish MACD... \n", "3 {\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Pri... \n", "4 {\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Bea... \n", ".. ... \n", "181 {\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Bul... \n", "182 {\"major_concern_nifty50\":\"The convergence of t... \n", "183 {\"status\":\"Trade\",\"brief_reason\":\"Bullish sent... \n", "184 {\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Hol... \n", "185 {\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Tra... \n", "\n", " response_format entered \\\n", "0 {'$defs': {'SummaryBankNifty': {'properties': ... True \n", "1 {'properties': {'major_concern_nifty50': {'des... True \n", "2 {'properties': {'status': {'enum': ['No trade'... True \n", "3 {'$defs': {'SummaryBankNifty': {'properties': ... True \n", "4 {'$defs': {'SummaryBankNifty': {'properties': ... True \n", ".. ... ... \n", "181 {'$defs': {'SummaryBankNifty': {'properties': ... True \n", "182 {'properties': {'major_concern_nifty50': {'des... True \n", "183 {'properties': {'status': {'enum': ['No trade'... True \n", "184 {'$defs': {'SummaryBankNifty': {'properties': ... True \n", "185 {'$defs': {'SummaryBankNifty': {'properties': ... True \n", "\n", " entry_time entry_price side exited exit_time \\\n", "0 2024-01-01 15:15:00 48215 short True 2024-01-01 15:22:00 \n", "1 2024-01-02 09:56:00 48035 short False NaT \n", "2 2024-01-02 09:56:00 48035 short False NaT \n", "3 2024-01-02 09:56:00 48035 short False NaT \n", "4 2024-01-02 09:56:00 48035 short False NaT \n", ".. ... ... ... ... ... \n", "181 2024-04-29 12:17:00 48920 long True 2024-04-29 13:26:00 \n", "182 2024-04-30 09:16:00 49500 long False NaT \n", "183 2024-04-30 09:16:00 49500 long False NaT \n", "184 2024-04-30 09:16:00 49500 long False NaT \n", "185 2024-04-30 09:16:00 49500 long True 2024-04-30 11:30:00 \n", "\n", " exit_price exit_reason pnl_pct open_position unrealized_pct note \\\n", "0 48080.0 target 0.2800 False NaN NaN \n", "1 NaN NaN NaN True 0.1382 NaN \n", "2 NaN NaN NaN True 0.1382 NaN \n", "3 NaN NaN NaN True 0.3610 NaN \n", "4 NaN NaN NaN True 0.3652 NaN \n", ".. ... ... ... ... ... ... \n", "181 49150.0 target 0.4702 False NaN NaN \n", "182 NaN NaN NaN True 0.0090 NaN \n", "183 NaN NaN NaN True 0.0090 NaN \n", "184 NaN NaN NaN True 0.1771 NaN \n", "185 49520.0 stoploss 0.0404 False NaN NaN \n", "\n", " datetime primary_key \n", "0 2024-01-01 15:29:00 2024-01-01 15:15:00 \n", "1 2024-01-02 10:15:00 2024-01-02 09:15:00 \n", "2 2024-01-02 10:15:00 2024-01-02 09:15:00 \n", "3 2024-01-02 11:15:00 2024-01-02 10:15:00 \n", "4 2024-01-02 12:15:00 2024-01-02 11:15:00 \n", ".. ... ... \n", "181 2024-04-29 14:15:00 2024-04-29 13:15:00 \n", "182 2024-04-30 10:15:00 2024-04-30 09:15:00 \n", "183 2024-04-30 10:15:00 2024-04-30 09:15:00 \n", "184 2024-04-30 11:15:00 2024-04-30 10:15:00 \n", "185 2024-04-30 12:15:00 2024-04-30 11:15:00 \n", "\n", "[186 rows x 20 columns]" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "# stats = pd.read_excel('./gemini-3-edited/gemini-3-edited/stats_log.xlsx')\n", "trade = pd.read_excel(\"./gemini3-data.xlsx\")\n", "stats=df_final\n", "def compute_primary_key(row):\n", " dt = row['datetime']\n", "\n", " # RULE 1: Do not adjust if exit reason is market-close type\n", " reason = str(row.get('exit_reason', '')).lower()\n", " if \"market close\" in reason or \"exited at market price\" in reason:\n", " return dt\n", "\n", " # RULE 2: Apply adjustments\n", " minute = dt.minute\n", "\n", " if minute == 29:\n", " return dt - pd.Timedelta(minutes=14)\n", " elif minute == 30:\n", " return dt - pd.Timedelta(minutes=1)\n", " elif minute == 15:\n", " return dt - pd.Timedelta(hours=1)\n", " else:\n", " return dt # no change fallback\n", "\n", "# Apply function\n", "stats['primary_key'] = stats.apply(compute_primary_key, axis=1)\n", "\n", "merged_df = pd.merge(trade, stats, left_on='timestamp',right_on=\"primary_key\",how='inner')\n", "merged_df" ] }, { "cell_type": "code", "execution_count": 28, "id": "3876fe08", "metadata": {}, "outputs": [], "source": [ "merged_df.to_excel(\"test.xlsx\")" ] }, { "cell_type": "code", "execution_count": null, "id": "96d47e36", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "trade", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.5" } }, "nbformat": 4, "nbformat_minor": 5 }