Add API route for getting a user's bets
This commit is contained in:
parent
2dce3e15a1
commit
0ec5670ec2
|
@ -567,6 +567,54 @@ $ curl https://manifold.markets/api/v0/market/{marketId}/resolve -X POST \
|
|||
]}'
|
||||
```
|
||||
|
||||
### `GET /v0/user/[username]/bets`
|
||||
|
||||
Gets a list of bets made by the user.
|
||||
|
||||
Requires no authorization.
|
||||
|
||||
- Example request
|
||||
```
|
||||
https://manifold.markets/api/v0/user/ManifoldMarkets/bets
|
||||
```
|
||||
- Response type: A `Bet[]`.
|
||||
|
||||
- <details><summary>Example response</summary><p>
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"probAfter": 0.44418877319153904,
|
||||
"shares": -645.8346334931828,
|
||||
"outcome": "YES",
|
||||
"contractId": "tgB1XmvFXZNhjr3xMNLp",
|
||||
"sale": {
|
||||
"betId": "RcOtarI3d1DUUTjiE0rx",
|
||||
"amount": 474.9999999999998
|
||||
},
|
||||
"createdTime": 1644602886293,
|
||||
"userId": "94YYTk1AFWfbWMpfYcvnnwI1veP2",
|
||||
"probBefore": 0.7229189477449224,
|
||||
"id": "x9eNmCaqQeXW8AgJ8Zmp",
|
||||
"amount": -499.9999999999998
|
||||
},
|
||||
{
|
||||
"probAfter": 0.9901970375647697,
|
||||
"contractId": "zdeaYVAfHlo9jKzWh57J",
|
||||
"outcome": "YES",
|
||||
"amount": 1,
|
||||
"id": "8PqxKYwXCcLYoXy2m2Nm",
|
||||
"shares": 1.0049875638533763,
|
||||
"userId": "94YYTk1AFWfbWMpfYcvnnwI1veP2",
|
||||
"probBefore": 0.9900000000000001,
|
||||
"createdTime": 1644705818872
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
</p>
|
||||
</details>
|
||||
|
||||
## Changelog
|
||||
|
||||
- 2022-06-08: Add paging to markets endpoint
|
||||
|
|
25
web/pages/api/v0/user/[username]/bets/index.ts
Normal file
25
web/pages/api/v0/user/[username]/bets/index.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors'
|
||||
import { Bet, getUserBets } from 'web/lib/firebase/bets'
|
||||
import { getUserByUsername } from 'web/lib/firebase/users'
|
||||
import { ApiError } from '../../../_types'
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<Bet[] | ApiError>
|
||||
) {
|
||||
await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
|
||||
const { username } = req.query
|
||||
|
||||
const user = await getUserByUsername(username as string)
|
||||
|
||||
if (!user) {
|
||||
res.status(404).json({ error: 'User not found' })
|
||||
return
|
||||
}
|
||||
|
||||
const bets = await getUserBets(user.id, { includeRedemptions: false })
|
||||
|
||||
res.setHeader('Cache-Control', 'max-age=0')
|
||||
return res.status(200).json(bets)
|
||||
}
|
Loading…
Reference in New Issue
Block a user