File size: 61,463 Bytes
45a77a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
{
 "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.<locals>.inner.<locals>.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    <DIR>          .\n",
      "27-11-2025  04:01 PM    <DIR>          ..\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    <DIR>          app\n",
      "03-11-2025  07:11 PM    <DIR>          best_result_gemini_2.5_pro\n",
      "05-11-2025  03:48 PM    <DIR>          data\n",
      "27-11-2025  04:24 PM    <DIR>          data-generation-gpt-4o-mini-newsonly-t-0.6-tp-0.6\n",
      "27-11-2025  04:24 PM    <DIR>          data-generation-gpt-4o-mini-t-0.6-tp-0.6\n",
      "27-11-2025  02:49 PM    <DIR>          data-generation-gpt-4o-t-0.6-tp-0.7\n",
      "27-11-2025  03:24 PM    <DIR>          gemini-3-edited\n",
      "27-11-2025  03:22 PM           497,413 gemini-3-edited.zip\n",
      "26-11-2025  11:18 PM    <DIR>          gpt-4o-expert\n",
      "26-11-2025  06:46 PM    <DIR>          gpt-4o-mini-expert\n",
      "26-11-2025  11:19 PM    <DIR>          gpt-4o-mini-expert-tushar\n",
      "26-11-2025  04:47 PM    <DIR>          gpt-4o-mini-news-expert\n",
      "26-11-2025  06:46 PM    <DIR>          gpt-4o-mini-news-only\n",
      "26-11-2025  03:45 PM    <DIR>          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    <DIR>          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": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>entered</th>\n",
       "      <th>entry_time</th>\n",
       "      <th>entry_price</th>\n",
       "      <th>side</th>\n",
       "      <th>exited</th>\n",
       "      <th>exit_time</th>\n",
       "      <th>exit_price</th>\n",
       "      <th>exit_reason</th>\n",
       "      <th>pnl_pct</th>\n",
       "      <th>open_position</th>\n",
       "      <th>unrealized_pct</th>\n",
       "      <th>note</th>\n",
       "      <th>datetime</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>True</td>\n",
       "      <td>2024-01-01 15:15:00</td>\n",
       "      <td>48215</td>\n",
       "      <td>short</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-01-01 15:22:00</td>\n",
       "      <td>48080.0</td>\n",
       "      <td>target</td>\n",
       "      <td>0.2800</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-01-01 15:29:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>True</td>\n",
       "      <td>2024-01-02 09:56:00</td>\n",
       "      <td>48035</td>\n",
       "      <td>short</td>\n",
       "      <td>False</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>0.1382</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-01-02 10:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>True</td>\n",
       "      <td>2024-01-02 09:56:00</td>\n",
       "      <td>48035</td>\n",
       "      <td>short</td>\n",
       "      <td>False</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>0.3610</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-01-02 11:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>True</td>\n",
       "      <td>2024-01-02 09:56:00</td>\n",
       "      <td>48035</td>\n",
       "      <td>short</td>\n",
       "      <td>False</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>0.3652</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-01-02 12:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>True</td>\n",
       "      <td>2024-01-02 09:56:00</td>\n",
       "      <td>48035</td>\n",
       "      <td>short</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-01-02 13:04:00</td>\n",
       "      <td>47800.0</td>\n",
       "      <td>target</td>\n",
       "      <td>0.4892</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-01-02 13:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>435</th>\n",
       "      <td>True</td>\n",
       "      <td>2024-04-29 12:17:00</td>\n",
       "      <td>48920</td>\n",
       "      <td>long</td>\n",
       "      <td>False</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>0.1571</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-04-29 13:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>436</th>\n",
       "      <td>True</td>\n",
       "      <td>2024-04-29 12:17:00</td>\n",
       "      <td>48920</td>\n",
       "      <td>long</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-04-29 13:26:00</td>\n",
       "      <td>49150.0</td>\n",
       "      <td>target</td>\n",
       "      <td>0.4702</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-04-29 14:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>437</th>\n",
       "      <td>True</td>\n",
       "      <td>2024-04-30 09:16:00</td>\n",
       "      <td>49500</td>\n",
       "      <td>long</td>\n",
       "      <td>False</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>0.0090</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-04-30 10:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>438</th>\n",
       "      <td>True</td>\n",
       "      <td>2024-04-30 09:16:00</td>\n",
       "      <td>49500</td>\n",
       "      <td>long</td>\n",
       "      <td>False</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>0.1771</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-04-30 11:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>439</th>\n",
       "      <td>True</td>\n",
       "      <td>2024-04-30 09:16:00</td>\n",
       "      <td>49500</td>\n",
       "      <td>long</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-04-30 11:30:00</td>\n",
       "      <td>49520.0</td>\n",
       "      <td>stoploss</td>\n",
       "      <td>0.0404</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-04-30 12:15:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>164 rows × 13 columns</p>\n",
       "</div>"
      ],
      "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    <DIR>          .\n",
      "27-11-2025  04:01 PM    <DIR>          ..\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    <DIR>          app\n",
      "03-11-2025  07:11 PM    <DIR>          best_result_gemini_2.5_pro\n",
      "05-11-2025  03:48 PM    <DIR>          data\n",
      "27-11-2025  04:24 PM    <DIR>          data-generation-gpt-4o-mini-newsonly-t-0.6-tp-0.6\n",
      "27-11-2025  04:24 PM    <DIR>          data-generation-gpt-4o-mini-t-0.6-tp-0.6\n",
      "27-11-2025  02:49 PM    <DIR>          data-generation-gpt-4o-t-0.6-tp-0.7\n",
      "27-11-2025  03:24 PM    <DIR>          gemini-3-edited\n",
      "27-11-2025  03:22 PM           497,413 gemini-3-edited.zip\n",
      "26-11-2025  11:18 PM    <DIR>          gpt-4o-expert\n",
      "26-11-2025  06:46 PM    <DIR>          gpt-4o-mini-expert\n",
      "26-11-2025  11:19 PM    <DIR>          gpt-4o-mini-expert-tushar\n",
      "26-11-2025  04:47 PM    <DIR>          gpt-4o-mini-news-expert\n",
      "26-11-2025  06:46 PM    <DIR>          gpt-4o-mini-news-only\n",
      "26-11-2025  03:45 PM    <DIR>          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    <DIR>          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": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>identifier</th>\n",
       "      <th>system_prompt</th>\n",
       "      <th>user</th>\n",
       "      <th>assistant</th>\n",
       "      <th>response_format</th>\n",
       "      <th>entered</th>\n",
       "      <th>entry_time</th>\n",
       "      <th>entry_price</th>\n",
       "      <th>side</th>\n",
       "      <th>exited</th>\n",
       "      <th>exit_time</th>\n",
       "      <th>exit_price</th>\n",
       "      <th>exit_reason</th>\n",
       "      <th>pnl_pct</th>\n",
       "      <th>open_position</th>\n",
       "      <th>unrealized_pct</th>\n",
       "      <th>note</th>\n",
       "      <th>datetime</th>\n",
       "      <th>primary_key</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2024-01-01 15:15:00</td>\n",
       "      <td>trade_loop_!10:15</td>\n",
       "      <td>You are an expert trading assistant capable of...</td>\n",
       "      <td>\\nExpert analysis and past news indicate that ...</td>\n",
       "      <td>{\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Con...</td>\n",
       "      <td>{'$defs': {'SummaryBankNifty': {'properties': ...</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-01-01 15:15:00</td>\n",
       "      <td>48215</td>\n",
       "      <td>short</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-01-01 15:22:00</td>\n",
       "      <td>48080.0</td>\n",
       "      <td>target</td>\n",
       "      <td>0.2800</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-01-01 15:29:00</td>\n",
       "      <td>2024-01-01 15:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2024-01-02 09:15:00</td>\n",
       "      <td>day_start_with_sentiment_and_expert</td>\n",
       "      <td>You are an expert trading assistant capable of...</td>\n",
       "      <td>Based on the latest news, the predicted market...</td>\n",
       "      <td>{\"major_concern_nifty50\":\"Formation of bearish...</td>\n",
       "      <td>{'properties': {'major_concern_nifty50': {'des...</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-01-02 09:56:00</td>\n",
       "      <td>48035</td>\n",
       "      <td>short</td>\n",
       "      <td>False</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>0.1382</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-01-02 10:15:00</td>\n",
       "      <td>2024-01-02 09:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2024-01-02 09:15:00</td>\n",
       "      <td>day_start_trade</td>\n",
       "      <td>You are an expert trading assistant capable of...</td>\n",
       "      <td>Expert analysis and past news indicate that th...</td>\n",
       "      <td>{\"status\":\"Trade\",\"brief_reason\":\"Bearish MACD...</td>\n",
       "      <td>{'properties': {'status': {'enum': ['No trade'...</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-01-02 09:56:00</td>\n",
       "      <td>48035</td>\n",
       "      <td>short</td>\n",
       "      <td>False</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>0.1382</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-01-02 10:15:00</td>\n",
       "      <td>2024-01-02 09:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2024-01-02 10:15:00</td>\n",
       "      <td>trade_at_10:15</td>\n",
       "      <td>You are an expert trading assistant capable of...</td>\n",
       "      <td>Expert analysis and past news indicate that th...</td>\n",
       "      <td>{\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Pri...</td>\n",
       "      <td>{'$defs': {'SummaryBankNifty': {'properties': ...</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-01-02 09:56:00</td>\n",
       "      <td>48035</td>\n",
       "      <td>short</td>\n",
       "      <td>False</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>0.3610</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-01-02 11:15:00</td>\n",
       "      <td>2024-01-02 10:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2024-01-02 11:15:00</td>\n",
       "      <td>trade_loop_!10:15</td>\n",
       "      <td>You are an expert trading assistant capable of...</td>\n",
       "      <td>\\nExpert analysis and past news indicate that ...</td>\n",
       "      <td>{\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Bea...</td>\n",
       "      <td>{'$defs': {'SummaryBankNifty': {'properties': ...</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-01-02 09:56:00</td>\n",
       "      <td>48035</td>\n",
       "      <td>short</td>\n",
       "      <td>False</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>0.3652</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-01-02 12:15:00</td>\n",
       "      <td>2024-01-02 11:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>181</th>\n",
       "      <td>2024-04-29 13:15:00</td>\n",
       "      <td>trade_loop_!10:15</td>\n",
       "      <td>You are an expert trading assistant capable of...</td>\n",
       "      <td>\\nExpert analysis and past news indicate that ...</td>\n",
       "      <td>{\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Bul...</td>\n",
       "      <td>{'$defs': {'SummaryBankNifty': {'properties': ...</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-04-29 12:17:00</td>\n",
       "      <td>48920</td>\n",
       "      <td>long</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-04-29 13:26:00</td>\n",
       "      <td>49150.0</td>\n",
       "      <td>target</td>\n",
       "      <td>0.4702</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-04-29 14:15:00</td>\n",
       "      <td>2024-04-29 13:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>182</th>\n",
       "      <td>2024-04-30 09:15:00</td>\n",
       "      <td>day_start_with_sentiment_and_expert</td>\n",
       "      <td>You are an expert trading assistant capable of...</td>\n",
       "      <td>Based on the latest news, the predicted market...</td>\n",
       "      <td>{\"major_concern_nifty50\":\"The convergence of t...</td>\n",
       "      <td>{'properties': {'major_concern_nifty50': {'des...</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-04-30 09:16:00</td>\n",
       "      <td>49500</td>\n",
       "      <td>long</td>\n",
       "      <td>False</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>0.0090</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-04-30 10:15:00</td>\n",
       "      <td>2024-04-30 09:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>183</th>\n",
       "      <td>2024-04-30 09:15:00</td>\n",
       "      <td>day_start_trade</td>\n",
       "      <td>You are an expert trading assistant capable of...</td>\n",
       "      <td>Expert analysis and past news indicate that th...</td>\n",
       "      <td>{\"status\":\"Trade\",\"brief_reason\":\"Bullish sent...</td>\n",
       "      <td>{'properties': {'status': {'enum': ['No trade'...</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-04-30 09:16:00</td>\n",
       "      <td>49500</td>\n",
       "      <td>long</td>\n",
       "      <td>False</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>0.0090</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-04-30 10:15:00</td>\n",
       "      <td>2024-04-30 09:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>184</th>\n",
       "      <td>2024-04-30 10:15:00</td>\n",
       "      <td>trade_at_10:15</td>\n",
       "      <td>You are an expert trading assistant capable of...</td>\n",
       "      <td>Expert analysis and past news indicate that th...</td>\n",
       "      <td>{\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Hol...</td>\n",
       "      <td>{'$defs': {'SummaryBankNifty': {'properties': ...</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-04-30 09:16:00</td>\n",
       "      <td>49500</td>\n",
       "      <td>long</td>\n",
       "      <td>False</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>0.1771</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-04-30 11:15:00</td>\n",
       "      <td>2024-04-30 10:15:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>185</th>\n",
       "      <td>2024-04-30 11:15:00</td>\n",
       "      <td>trade_loop_!10:15</td>\n",
       "      <td>You are an expert trading assistant capable of...</td>\n",
       "      <td>\\nExpert analysis and past news indicate that ...</td>\n",
       "      <td>{\"trade\":{\"status\":\"Trade\",\"brief_reason\":\"Tra...</td>\n",
       "      <td>{'$defs': {'SummaryBankNifty': {'properties': ...</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-04-30 09:16:00</td>\n",
       "      <td>49500</td>\n",
       "      <td>long</td>\n",
       "      <td>True</td>\n",
       "      <td>2024-04-30 11:30:00</td>\n",
       "      <td>49520.0</td>\n",
       "      <td>stoploss</td>\n",
       "      <td>0.0404</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2024-04-30 12:15:00</td>\n",
       "      <td>2024-04-30 11:15:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>186 rows × 20 columns</p>\n",
       "</div>"
      ],
      "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
}