cwendt94 / espn-api

ESPN Fantasy API! (Football, Basketball)
MIT License
613 stars 198 forks source link

Add accepted trade activity to fantasy basketball activity list #500

Open joseulisesmena opened 10 months ago

joseulisesmena commented 10 months ago

Sport

Basketball

Summary

As a user of the API wrapper for fantasy basketball leagues, I'd like to receive accepted trades in the activities feed in addition to completed trades.

I've used this API wrapper to create a Discord bot that notifies my fantasy league-mates about when transactions are happening in the league. One limitation of the activity feed is that it only pulls completed transactions, not accepted trades which remain under review. As a result, my bot will lag behind on trades that have been accepted by the managers but which are still under league review and require voting/approval. I would expect the action to be 'TRADE ACCEPTED' or the like and to precede the later 'TRADED' action which is currently in the feed. Happy to UAT this when implemented. Thanks!

cwendt94 commented 10 months ago

I think thats a great idea. I currently don't have any accepted trades in a couple of my leagues to find the id of the activity. It should be as easy as adding the trade accepted id to the constant map and then it will show up. If your league has some trades I can show you were to view the API response and can add that information for me to check out.

joseulisesmena commented 10 months ago

Thanks for the reply. I also thought it would be as easy as adding a trade accepted ID to the constant map and I'm no longer sure of that. I poked around in the developer tools for the webapp and determined the page was populating based on a response from this endpoint:

https://lm-api-reads.fantasy.espn.com/apis/v3/games/fba/seasons/2024/segments/0/leagues/leagueID?view=mPendingTransactions&view=mSettings&view=mStatus&view=mMatchupScore&view=mTeam&view=modular&view=mNav

This is what the response JSON looks like for the pending trade:

   "pendingTransactions": [
    {
      "acceptedDate": 1701498946647,
      "bidAmount": 0,
      "executionType": "EXECUTE",
      "expirationDate": 1701610188656,
      "id": "c732d187-3020-41a1-88a5-e86626ce64b9",
      "isActingAsTeamOwner": false,
      "isLeagueManager": false,
      "isPending": true,
      "items": [
        {
          "fromLineupSlotId": 12,
          "fromTeamId": 8,
          "isKeeper": false,
          "overallPickNumber": 0,
          "playerId": 4432174,
          "toLineupSlotId": -1,
          "toTeamId": 9,
          "type": "TRADE"
        },
        {
          "fromLineupSlotId": 12,
          "fromTeamId": 9,
          "isKeeper": false,
          "overallPickNumber": 0,
          "playerId": 4278078,
          "toLineupSlotId": -1,
          "toTeamId": 8,
          "type": "TRADE"
        }
      ],

Team 8 is trading Cam Thomas to team 9 for PJ Washington. When I run the espn_api recent activity functions in debug mode, the latest date I see in the response JSON is 1701474990770 (Friday, December 1, 2023 6:56:30.770 PM [GMT-05:00]); the above transaction pending is dated 1701498946647 (Saturday, December 2, 2023 1:35:46.647 AM [GMT-05:00]). This seems to be also available in the team view in a slightly different form.

In the espn_api package, this is the request url I saw in the debug output: https://fantasy.espn.com/apis/v3/games/fba/seasons/2024/segments/0/leagues/leagueID/communication/

I also did not see the pending transaction in this API call in the webapp: https://lm-api-communication.fantasy.espn.com/apis/v3/games/fba/seasons/2024/segments/0/leagues/leagueid/communication/?view=kona_league_communication

So based on my read of your repo, this may be a separate call to a different endpoint than the normal recent_activity call.

Usage was simple:

league = League(league_id=lid, year=2024, espn_s2=s2, swid=sw,debug=True)
activities = league.recent_activity(size=25)
cwendt94 commented 10 months ago

I actually just got a pending trade in one of my leagues as well. Yeah so you are correct that pending is in a different area then communication/league activity.

I see the data can be populated in the team object and on its own. I believe the pending transaction could also represent weekly wavier claims. Would it work for you if the pending transaction was added to the Team class and represented there?