How to find my account win percentage?

hello , i am using the API to query my activities and after organizing and formatting I’m left with this dataframe in python :

                                                 id activity_type  \
0  20221104093211418::89083d36-0607-4f17-95d7-1ab...          FILL   
0  20221104093819111::08d80404-31df-451f-8ada-9e1...          FILL   
0  20221104093129364::3533d3bb-5a6f-4735-9d51-7c6...          FILL   
0  20221104093946175::d36f558b-9bea-4bf3-95bc-780...          FILL   
0  20221104093216067::1b53079a-8df0-4608-bfb5-30a...          FILL   
0  20221104093810625::1f0d67f9-335e-48dc-9d35-096...          FILL   
0  20221103140200543::4de07116-d248-4c10-b6bb-4a3...          FILL   
0  20221104093523913::87e3d2a1-7c36-49d0-867f-f95...          FILL   
0  20221104100819543::6d9ebe74-2660-4ef9-90ba-ea9...          FILL   
0  20221104102608884::78dae785-a2e6-47fe-bedf-6d4...          FILL   
0  20221104094117542::04cec124-e758-44ad-9b15-729...          FILL   
0  20221104094117801::0f2cf2b6-7b74-491b-94e2-c2e...          FILL   
0  20221104095717669::209653e7-560c-4b81-9045-c18...          FILL   
0  20221103131435193::497ee4a4-ab19-4e69-9728-21c...          FILL   
0  20221103131445812::67454b47-293a-45e2-a67a-d2d...          FILL   
0  20221103131503540::bfdfe437-4836-482f-845a-d56...          FILL   
0  20221103131512944::93e5642e-9473-4fb6-b572-ec2...          FILL   
0  20221103131524140::4a5bd32a-31a2-4580-8f0f-e5f...          FILL   
0  20221103131535492::aad18886-582e-453c-8fa5-1b9...          FILL   
0  20221103131604982::a6f361a0-0486-4b51-917a-606...          FILL   
0  20221103131612554::d5e314dc-ad48-46ce-b111-848...          FILL   
0  20221103131621082::7df9a1c0-9575-499c-a1a8-29e...          FILL   
0  20221103131629288::88a52cad-11e0-4283-bacf-d51...          FILL   
0  20221104093248666::2a55ec7a-1bb6-4b08-ac7e-6d2...          FILL   
0  20221104095752242::bf498c1a-a8cb-4c2a-ba9d-a48...          FILL   
0  20221104102355017::6caf0249-b021-4a95-acb9-620...          FILL   
0  20221104150908788::6fe0ecf5-1dd1-469b-ac15-4cb...          FILL   
0  20221104093254581::4506a5d1-6a28-4b2a-83c5-a3c...          FILL   
0  20221104093941624::f038f6e3-48fe-485e-b23a-a9f...          FILL   
0  20221104094250176::f4b25f55-6b9b-4a6a-8d95-ad1...          FILL   
0  20221104095203381::a7e033a8-d840-4a3e-b8e4-7ae...          FILL   
0  20221104093335321::27df4596-5ec3-4b07-af43-764...          FILL   
0  20221104094057076::5848caeb-da63-4ffe-8af3-916...          FILL   

             transaction_time          type   price    qty        side  \
0  2022-11-04T13:32:11.418156Z          fill   49.65    358  sell_short   
0  2022-11-04T13:38:19.111755Z          fill   49.66    358         buy   
0   2022-11-04T13:31:29.36468Z          fill    4.96   3892         buy   
0  2022-11-04T13:39:46.175925Z          fill    5.03   3892        sell   
0  2022-11-04T13:32:16.067304Z          fill   62.16    214  sell_short   
0  2022-11-04T13:38:10.625622Z          fill   61.86    214         buy   
0  2022-11-03T18:02:00.543892Z          fill    7.98   1525         buy   
0  2022-11-04T13:35:23.913494Z          fill    8.13   1525        sell   
0  2022-11-04T14:08:19.543466Z          fill    8.05   2219         buy   
0   2022-11-04T14:26:08.88405Z          fill   73.92    248  sell_short   
0  2022-11-04T13:41:17.542958Z  partial_fill   10.04   1509  sell_short   
0  2022-11-04T13:41:17.801143Z          fill   10.04    111  sell_short   
0  2022-11-04T13:57:17.669464Z          fill   10.27   1620         buy   
0  2022-11-03T17:14:35.193369Z          fill    1.46      1         buy   
0  2022-11-03T17:14:45.812615Z          fill    1.45      1        sell   
0  2022-11-03T17:15:03.540097Z          fill    1.46      1         buy   
0  2022-11-03T17:15:12.944842Z          fill    1.45      1        sell   
0  2022-11-03T17:15:24.140151Z          fill    1.46      1         buy   
0  2022-11-03T17:15:35.492387Z          fill    1.45      1        sell   
0  2022-11-03T17:16:04.982603Z          fill    1.46      1         buy   
0  2022-11-03T17:16:12.554947Z          fill    1.45      1        sell   
0  2022-11-03T17:16:21.082499Z          fill    1.46      1         buy   
0  2022-11-03T17:16:29.288924Z          fill    1.45      1        sell   
0  2022-11-04T13:32:48.666567Z          fill    1.46   9437         buy   
0  2022-11-04T13:57:52.242378Z          fill  0.9585  20894         buy   
0  2022-11-04T14:23:55.017199Z          fill  0.9632  20894        sell   
0  2022-11-04T19:09:08.788909Z          fill   0.967  14302         buy   
0   2022-11-04T13:32:54.58189Z          fill   12.56    829  sell_short   
0  2022-11-04T13:39:41.624365Z          fill   12.79    829         buy   
0  2022-11-04T13:42:50.176096Z          fill   12.55   1117         buy   
0   2022-11-04T13:52:03.38155Z          fill   12.34   1117        sell   
0   2022-11-04T13:33:35.32141Z          fill    20.2    379  sell_short   
0  2022-11-04T13:40:57.076834Z          fill   20.14    379         buy   

 symbol leaves_qty                              order_id cum_qty  \
0    APA          0  ec25773f-6e5a-46f3-b4a9-4b3e2f97d418     358   
0    APA          0  7cce527c-0913-4531-8d13-2451cb81d5f2     358   
0   AUPH          0  90b3e818-905b-412b-b39f-bd7de7bbe4dc    3892   
0   AUPH          0  1f2e7ebd-0625-4af6-8004-b44b9a47a06f    3892   
0    CNQ          0  53d9c97a-874c-48d7-9cc0-c9e4287dab4c     214   
0    CNQ          0  4e5deedb-819e-4c9d-bdd6-c19fa94d9597     214   
0   ETRN          0  13f40cbe-7869-46ec-beb0-3962535996db    1525   
0   ETRN          0  5f3476bd-c965-4b93-8ab4-abb090ac2977    1525   
0   ETRN          0  2e03471e-8b00-496f-801f-0af96865b306    2219   
0    HIG          0  f28d8ac1-fffa-46cb-a1f6-11b75bd477aa     248   
0    OWL        111  85784265-d552-401c-af2e-1e6f224f68e0    1509   
0    OWL          0  85784265-d552-401c-af2e-1e6f224f68e0    1620   
0    OWL          0  ea364bcf-6e3a-4899-beb1-2660f7cffc4c    1620   
0   REAL          0  417ae403-f8c0-4a1b-ba22-d617d891c2f8       1   
0   REAL          0  1bddbae9-dec7-4dce-a73c-12bd47c82413       1   
0   REAL          0  ab6b0d05-32cb-4039-ac04-e079bb7883b7       1   
0   REAL          0  eead3be4-921e-4c58-a65b-02f1f9ed4880       1   
0   REAL          0  db5cd066-14fc-4afc-9718-9fb653d55895       1   
0   REAL          0  6d95893d-483c-40a0-9082-6439c950a5ec       1   
0   REAL          0  b7f8be05-fa7a-4c1b-9876-e83eebaf88bf       1   
0   REAL          0  b1940fb9-0c38-407c-a39c-0b8609c05fdf       1   
0   REAL          0  1b51a642-cb9f-4a56-84c5-030ba06a5597       1   
0   REAL          0  314c63f3-95aa-4890-ac06-a1faa19d4d74       1   
0   REAL          0  7b3a799f-4b17-40cf-8744-398e81a6e259    9437   
0   SKLZ          0  38b469a2-41f3-4c11-a7a3-f87ab5bc1a1d   20894   
0   SKLZ          0  b51df672-87cc-42dc-984b-fc5a20ba0eba   20894   
0   SKLZ          0  cf68dc34-e9b6-4008-870b-bd87804d55a1   14302   
0   STEM          0  7468f358-2cfb-4ed5-a717-8e54c483472c     829   
0   STEM          0  b1374b2d-4c31-46c8-909f-326646edb624     829   
0   STEM          0  88363c7e-cdf9-479a-82d5-c25637449199    1117   
0   STEM          0  3b257519-a973-4558-a380-9d0ceb275418    1117   
0      X          0  780f58ce-f4f0-4c6b-8584-a96aed3a0220     379   
0      X          0  c878da26-90be-4d00-befa-79c00e4980c2     379   

      order_status  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0  partially_filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  
0            filled  

as you can see i have some trades that are partially filled. has anyone made a script to gain some insights into these trades? specifically win/lose percentage?

import pandas as pd
df = pd.DataFrame()



for activity in api.list_orders("closed"):
    df1 = pd.DataFrame(activity._raw, index=[0])
    df = pd.concat([df,df1])
df = df[df["status"] != "canceled"]
df =df.sort_values(["symbol","filled_at"])
df=df.drop(columns=['id','client_order_id','updated_at','submitted_at','replaced_by','replaces','asset_id','asset_class','created_at','expired_at','canceled_at','failed_at'])
df=df.drop(columns=['replaced_at','order_class','order_type','type','time_in_force','limit_price','stop_price','extended_hours','legs','subtag','source','notional','hwm','trail_percent','trail_price','status'])

positions = pd.DataFrame(columns=['symbol','side','entry_price','exit_price'])
k=0
for sym in df.symbol.unique():
    df_s = df[df['symbol'] == sym]
    if len(df_s.index) % 2 == 1:
        df_s=df_s.loc[:-1]
    df_s =df_s.reset_index(drop=True)
    
    
    for index, row in df_s.iterrows():
        
        if index % 2 == 0:
            positions.loc[k] = [
            sym,
            row.side,
            row.filled_avg_price,
            df_s.iloc[index+1].filled_avg_price]
            k+=1
    
print(positions)
win = 0
loss= 0
for index, row in positions.iterrows():
    if row.side == "long":
        if row.entry_price < row.exit_price:
            win +=1
        else:
            loss +=1
    else:
        if row.entry_price > row.exit_price:
            win +=1
        else:
            loss +=1
precent_won = (win/(win+loss))*100
print(f"precent_won:{precent_won}")

i have solved it.

2 Likes