Skip to content

Code Reference

Class for accessing PancakeSwap Lottery V2 smart-contract information.

Source code in pancakeswap_lottery/lotteryv2.py
  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
class LotteryV2:
    """Class for accessing PancakeSwap Lottery V2 smart-contract information."""

    def __init__(self, provider="https://bsc-dataseed.binance.org"):
        """Initialize the object

        Attributes:
            provider (str): Web3 HTTPProvider.

                Defaults to https://bsc-dataseed.binance.org

        Examples:
            lottery = LotteryV2()
        """
        self.w3 = Web3(Web3.HTTPProvider(provider))

        contract_addresses = {
            "PancakeSwapLottery": "0x5aF6D33DE2ccEC94efb1bDF8f92Bd58085432d2c",
            "CakeToken": "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82",
        }

        self.lottery_contract = self._load_contract(
            abi_name="PancakeSwapLottery",
            address=contract_addresses["PancakeSwapLottery"],
        )

        self.token_contract = self._load_contract(
            abi_name="CakeToken", address=contract_addresses["CakeToken"]
        )

        self.decimals = 10**18

    def _load_contract(self, abi_name, address):
        return self.w3.eth.contract(address=address, abi=load_abi(abi_name))

    def _status(self, statusid):
        status = {
            1: "Open",
            2: "_Unknown_",
            3: "Claimed",
        }

        return status[statusid]

    def view_lottery(self, lotteryround):
        data = self.lottery_contract.functions.viewLottery(lotteryround).call()

        d = {
            "status": self._status(data[0]),
            "startTime": datetime.fromtimestamp(data[1]),
            "endTime": datetime.fromtimestamp(data[2]),
            "priceTicketInCake": data[3] / self.decimals,
            "discountDivisor": data[4],
            "rewardsBreakdown": data[5],
            "treasuryFee": data[6],
            "cakePerBracket": {
                "match_1": round(data[7][0] / self.decimals),
                "match_2": round(data[7][1] / self.decimals),
                "match_3": round(data[7][2] / self.decimals),
                "match_4": round(data[7][3] / self.decimals),
                "match_5": round(data[7][4] / self.decimals),
                "match_6": round(data[7][5] / self.decimals),
            },
            "countWinnersPerBracket": {
                "match_1": data[8][0],
                "match_2": data[8][1],
                "match_3": data[8][2],
                "match_4": data[8][3],
                "match_5": data[8][4],
                "match_6": data[8][5],
            },
            "firstTicketId": data[9],
            "firstTicketIdNextLottery": data[10],
            "amountCollectedInCake": data[11] / self.decimals,
            "finalNumber": data[12],
        }

        return d

    def current_round(self):
        """Get current lottery round number

        Examples:
            >>> lottery.current_round()
            8
        """
        return self.lottery_contract.functions.currentLotteryId().call()

    def current_ticket(self):
        """Get current ticket id

        Examples:
            >>> lottery.current_ticket()
            38963
        """
        return self.lottery_contract.functions.currentTicketId().call()

    def prize_pool(self, lotteryround=None):
        """Get total prize pool size in CAKE

        Args:
            lotteryround (:obj:`int`, optional): Lottery round

        Examples:
            >>> lottery.prize_pool()
            141947
        """

        if not lotteryround:
            lotteryround = self.current_round()

        data = self.view_lottery(lotteryround)
        amount = data.get("amountCollectedInCake")

        return round(amount)

    def draw_date(self, lotteryround=None):
        """Get lottery draw date

        Args:
            lotteryround (:obj:`int`, optional): Lottery round

        Examples:
            >>> lottery.draw_date()
            141947
        """

        if not lotteryround:
            lotteryround = self.current_round()

        lottery = self.view_lottery(lotteryround)
        lotter_date = lottery.get("endTime")

        return lotter_date

    def prize_pool_allocation(self, lotteryround=None):
        """Get prize pool allocation in CAKE

        Allocation percentages:
        - Match first 1: 1%
        - Match first 2: 3%
        - Match first 3: 6%
        - Match first 4: 10%
        - Match first 5: 20%
        - Match first 6: 40%
        - Burn Pool: 20%

        Args:
            lotteryround (:obj:`int`, optional): Lottery round

        Examples:
            >>> lottery.prize_pool_allocation()
            {
                'match_1': 1419,
                'match_2': 4258,
                'match_3': 8517,
                'match_4': 14195,
                'match_5': 28389,
                'match_6': 56779,
                'burn': 28389
            }
        """
        if not lotteryround:
            lotteryround = self.current_round()

        data = self.view_lottery(lotteryround)
        prize_pool = data.get("amountCollectedInCake")

        d = {
            "match_1": round(prize_pool * 0.01),
            "match_2": round(prize_pool * 0.03),
            "match_3": round(prize_pool * 0.06),
            "match_4": round(prize_pool * 0.1),
            "match_5": round(prize_pool * 0.2),
            "match_6": round(prize_pool * 0.4),
            "burn": round(prize_pool * 0.2),
        }

        return d

    def ticket_price(self, lotteryround=None):
        """Get ticket price in CAKE

        Args:
            lotteryround (:obj:`int`, optional): Lottery round

        Examples:
            >>> lottery.ticket_price()
            0.34
        """

        if not lotteryround:
            lotteryround = self.current_round()

        lottery = self.view_lottery(lotteryround)
        price = lottery.get("priceTicketInCake")

        return price

    def status(self, lotteryround=None):
        """Get status of lottery round

        Args:
            lotteryround (:obj:`int`, optional): Lottery round

        Examples:
            >>> lottery.status()
            Open
        """

        if not lotteryround:
            lotteryround = self.current_round()

        data = self.view_lottery(lotteryround)
        lottery_status = data.get("status")

        return lottery_status

    def winners_per_bracket(self, lotteryround):
        """Get number of winners per prize bracket

        Args:
            lotteryround (int): Lottery round

        Examples:
            >>> lottery.winners_per_bracket(lotteryround=16)
            {
                'match_1': 19133,
                'match_2': 1921,
                'match_3': 188,
                'match_4': 21,
                'match_5': 1,
                'match_6': 1
            }
        """

        data = self.view_lottery(lotteryround)
        d = data.get("countWinnersPerBracket")

        return d

    def cake_per_bracket(self, lotteryround):
        """Get amount of CAKE won per ticket in each prize bracket

        Args:
            lotteryround (int): Lottery round

        Examples:
            >>> lottery.cake_per_bracket(lotteryround=16)
            {
                'match_1': 0.10150861284172895,
                'match_2': 3.0330519877680375,
                'match_3': 61.98396668619574,
                'match_4': 924.8401378575238,
                'match_5': 38843.285790016,
                'match_6': 77686.571580032
            }
        """

        data = self.view_lottery(lotteryround)
        d = data.get("cakePerBracket")

        return d

    def winning_probability(self, numbers_matched=None):
        """Get percentage probability of winning the lottery

        Args:
            numbers_matched (:obj:`int`, optional): Number of winning numbers matched

        Examples:
            >>> lottery.winning_probability()
            {
                'match_1': 10.0,
                'match_2': 1.0,
                'match_3': 0.1,
                'match_4': 0.01,
                'match_5': 0.001,
                'match_6': 0.0001
            }
        """
        possible_numbers = 10
        matchballs = [1, 2, 3, 4, 5, 6]
        probability_pct = {}

        if numbers_matched:
            if numbers_matched not in range(1, 7):
                return "Pick a number between 1 and 6"

            e = possible_numbers**numbers_matched
            odds = 1 / e * 100

            return float(f"{odds:.4f}")

        for matchball in matchballs:
            e = possible_numbers**matchball
            odds = 1 / e * 100
            probability_pct.update({f"match_{matchball}": float(f"{odds:.4f}")})

        return probability_pct

    def winning_numbers(self, lotteryround):
        """Get winning numbers for lottery round

        Args:
            lotteryround (int): Lottery round

        Examples:
            >>> lottery.winning_numbers(lotteryround=16)
            0
        """
        data = self.view_lottery(lotteryround)
        final_number = str(data.get("finalNumber"))
        final_number = final_number[::-1][:-1]

        return final_number

    def ticket_winnings(self, lotteryround, ticketid):
        """Get lottery winnings (CAKE) for a given ticket and round

        Args:
            lotteryround (int): Lottery round
            ticketid (int): Ticket id

        Examples:
            >>> lottery.ticket_winnings(lotteryround=15, ticketid=567093)
            865.536634168
        """
        winnings = 0
        brackets = [0, 1, 2, 3, 4, 5]

        for bracket in brackets:
            data = self.lottery_contract.functions.viewRewardsForTicketId(
                lotteryround, ticketid, bracket
            ).call()

            if data > 0:
                winnings = data / self.decimals

        return winnings

    def address_winnings(self, address, lotteryround):
        """Get lottery winnings (CAKE) for a given address and round

        Args:
            address (str): BSC address
            lotteryround (int): Lottery round

        Examples:
            >>> lottery.address_winnings("0x621D6ee5FA9634d86396C13fAaD6A7827606A6d7", lotteryround=16)
            {'tickets': 8, 'ticketids': [634970, 634971, 634972, 634973, 634974, 634975, 634976, 634977], 'winning_tickets': [634970, 634971]}
        """
        userinfo = self.lottery_contract.functions.viewUserInfoForLotteryId(
            self.w3.to_checksum_address(address),
            lotteryround,
            0,
            100,
        ).call()

        count = 0
        winning_tickets = []

        for i in userinfo[2]:
            if i is True:
                winning_tickets.append(userinfo[0][count])
            count += 1

        d = {
            "tickets": userinfo[3],
            "ticketids": userinfo[0],
            "winning_tickets": winning_tickets,
        }

        return d

    def total_tickets(self, lotteryround):
        """Get total number of tickets in lottery round

        Args:
            lotteryround (int): Lottery round

        Examples:
            >>> lottery.total_tickets(lotteryround=23)
            0
        """
        current_round = self.current_round()

        if lotteryround > current_round:
            return 0

        data = self.view_lottery(lotteryround)
        first_ticket_id = data.get("firstTicketId")
        last_ticket_id = data.get("firstTicketIdNextLottery")

        return int(last_ticket_id - first_ticket_id)

__init__(provider='https://bsc-dataseed.binance.org')

Initialize the object

Attributes:

Name Type Description
provider str

Web3 HTTPProvider.

Defaults to https://bsc-dataseed.binance.org

Examples:

lottery = LotteryV2()

Source code in pancakeswap_lottery/lotteryv2.py
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
def __init__(self, provider="https://bsc-dataseed.binance.org"):
    """Initialize the object

    Attributes:
        provider (str): Web3 HTTPProvider.

            Defaults to https://bsc-dataseed.binance.org

    Examples:
        lottery = LotteryV2()
    """
    self.w3 = Web3(Web3.HTTPProvider(provider))

    contract_addresses = {
        "PancakeSwapLottery": "0x5aF6D33DE2ccEC94efb1bDF8f92Bd58085432d2c",
        "CakeToken": "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82",
    }

    self.lottery_contract = self._load_contract(
        abi_name="PancakeSwapLottery",
        address=contract_addresses["PancakeSwapLottery"],
    )

    self.token_contract = self._load_contract(
        abi_name="CakeToken", address=contract_addresses["CakeToken"]
    )

    self.decimals = 10**18

address_winnings(address, lotteryround)

Get lottery winnings (CAKE) for a given address and round

Parameters:

Name Type Description Default
address str

BSC address

required
lotteryround int

Lottery round

required

Examples:

>>> lottery.address_winnings("0x621D6ee5FA9634d86396C13fAaD6A7827606A6d7", lotteryround=16)
{'tickets': 8, 'ticketids': [634970, 634971, 634972, 634973, 634974, 634975, 634976, 634977], 'winning_tickets': [634970, 634971]}
Source code in pancakeswap_lottery/lotteryv2.py
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
def address_winnings(self, address, lotteryround):
    """Get lottery winnings (CAKE) for a given address and round

    Args:
        address (str): BSC address
        lotteryround (int): Lottery round

    Examples:
        >>> lottery.address_winnings("0x621D6ee5FA9634d86396C13fAaD6A7827606A6d7", lotteryround=16)
        {'tickets': 8, 'ticketids': [634970, 634971, 634972, 634973, 634974, 634975, 634976, 634977], 'winning_tickets': [634970, 634971]}
    """
    userinfo = self.lottery_contract.functions.viewUserInfoForLotteryId(
        self.w3.to_checksum_address(address),
        lotteryround,
        0,
        100,
    ).call()

    count = 0
    winning_tickets = []

    for i in userinfo[2]:
        if i is True:
            winning_tickets.append(userinfo[0][count])
        count += 1

    d = {
        "tickets": userinfo[3],
        "ticketids": userinfo[0],
        "winning_tickets": winning_tickets,
    }

    return d

cake_per_bracket(lotteryround)

Get amount of CAKE won per ticket in each prize bracket

Parameters:

Name Type Description Default
lotteryround int

Lottery round

required

Examples:

>>> lottery.cake_per_bracket(lotteryround=16)
{
    'match_1': 0.10150861284172895,
    'match_2': 3.0330519877680375,
    'match_3': 61.98396668619574,
    'match_4': 924.8401378575238,
    'match_5': 38843.285790016,
    'match_6': 77686.571580032
}
Source code in pancakeswap_lottery/lotteryv2.py
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
def cake_per_bracket(self, lotteryround):
    """Get amount of CAKE won per ticket in each prize bracket

    Args:
        lotteryround (int): Lottery round

    Examples:
        >>> lottery.cake_per_bracket(lotteryround=16)
        {
            'match_1': 0.10150861284172895,
            'match_2': 3.0330519877680375,
            'match_3': 61.98396668619574,
            'match_4': 924.8401378575238,
            'match_5': 38843.285790016,
            'match_6': 77686.571580032
        }
    """

    data = self.view_lottery(lotteryround)
    d = data.get("cakePerBracket")

    return d

current_round()

Get current lottery round number

Examples:

>>> lottery.current_round()
8
Source code in pancakeswap_lottery/lotteryv2.py
87
88
89
90
91
92
93
94
def current_round(self):
    """Get current lottery round number

    Examples:
        >>> lottery.current_round()
        8
    """
    return self.lottery_contract.functions.currentLotteryId().call()

current_ticket()

Get current ticket id

Examples:

>>> lottery.current_ticket()
38963
Source code in pancakeswap_lottery/lotteryv2.py
 96
 97
 98
 99
100
101
102
103
def current_ticket(self):
    """Get current ticket id

    Examples:
        >>> lottery.current_ticket()
        38963
    """
    return self.lottery_contract.functions.currentTicketId().call()

draw_date(lotteryround=None)

Get lottery draw date

Parameters:

Name Type Description Default
lotteryround

obj:int, optional): Lottery round

None

Examples:

>>> lottery.draw_date()
141947
Source code in pancakeswap_lottery/lotteryv2.py
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
def draw_date(self, lotteryround=None):
    """Get lottery draw date

    Args:
        lotteryround (:obj:`int`, optional): Lottery round

    Examples:
        >>> lottery.draw_date()
        141947
    """

    if not lotteryround:
        lotteryround = self.current_round()

    lottery = self.view_lottery(lotteryround)
    lotter_date = lottery.get("endTime")

    return lotter_date

prize_pool(lotteryround=None)

Get total prize pool size in CAKE

Parameters:

Name Type Description Default
lotteryround

obj:int, optional): Lottery round

None

Examples:

>>> lottery.prize_pool()
141947
Source code in pancakeswap_lottery/lotteryv2.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
def prize_pool(self, lotteryround=None):
    """Get total prize pool size in CAKE

    Args:
        lotteryround (:obj:`int`, optional): Lottery round

    Examples:
        >>> lottery.prize_pool()
        141947
    """

    if not lotteryround:
        lotteryround = self.current_round()

    data = self.view_lottery(lotteryround)
    amount = data.get("amountCollectedInCake")

    return round(amount)

prize_pool_allocation(lotteryround=None)

Get prize pool allocation in CAKE

Allocation percentages: - Match first 1: 1% - Match first 2: 3% - Match first 3: 6% - Match first 4: 10% - Match first 5: 20% - Match first 6: 40% - Burn Pool: 20%

Parameters:

Name Type Description Default
lotteryround

obj:int, optional): Lottery round

None

Examples:

>>> lottery.prize_pool_allocation()
{
    'match_1': 1419,
    'match_2': 4258,
    'match_3': 8517,
    'match_4': 14195,
    'match_5': 28389,
    'match_6': 56779,
    'burn': 28389
}
Source code in pancakeswap_lottery/lotteryv2.py
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
def prize_pool_allocation(self, lotteryround=None):
    """Get prize pool allocation in CAKE

    Allocation percentages:
    - Match first 1: 1%
    - Match first 2: 3%
    - Match first 3: 6%
    - Match first 4: 10%
    - Match first 5: 20%
    - Match first 6: 40%
    - Burn Pool: 20%

    Args:
        lotteryround (:obj:`int`, optional): Lottery round

    Examples:
        >>> lottery.prize_pool_allocation()
        {
            'match_1': 1419,
            'match_2': 4258,
            'match_3': 8517,
            'match_4': 14195,
            'match_5': 28389,
            'match_6': 56779,
            'burn': 28389
        }
    """
    if not lotteryround:
        lotteryround = self.current_round()

    data = self.view_lottery(lotteryround)
    prize_pool = data.get("amountCollectedInCake")

    d = {
        "match_1": round(prize_pool * 0.01),
        "match_2": round(prize_pool * 0.03),
        "match_3": round(prize_pool * 0.06),
        "match_4": round(prize_pool * 0.1),
        "match_5": round(prize_pool * 0.2),
        "match_6": round(prize_pool * 0.4),
        "burn": round(prize_pool * 0.2),
    }

    return d

status(lotteryround=None)

Get status of lottery round

Parameters:

Name Type Description Default
lotteryround

obj:int, optional): Lottery round

None

Examples:

>>> lottery.status()
Open
Source code in pancakeswap_lottery/lotteryv2.py
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
def status(self, lotteryround=None):
    """Get status of lottery round

    Args:
        lotteryround (:obj:`int`, optional): Lottery round

    Examples:
        >>> lottery.status()
        Open
    """

    if not lotteryround:
        lotteryround = self.current_round()

    data = self.view_lottery(lotteryround)
    lottery_status = data.get("status")

    return lottery_status

ticket_price(lotteryround=None)

Get ticket price in CAKE

Parameters:

Name Type Description Default
lotteryround

obj:int, optional): Lottery round

None

Examples:

>>> lottery.ticket_price()
0.34
Source code in pancakeswap_lottery/lotteryv2.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
def ticket_price(self, lotteryround=None):
    """Get ticket price in CAKE

    Args:
        lotteryround (:obj:`int`, optional): Lottery round

    Examples:
        >>> lottery.ticket_price()
        0.34
    """

    if not lotteryround:
        lotteryround = self.current_round()

    lottery = self.view_lottery(lotteryround)
    price = lottery.get("priceTicketInCake")

    return price

ticket_winnings(lotteryround, ticketid)

Get lottery winnings (CAKE) for a given ticket and round

Parameters:

Name Type Description Default
lotteryround int

Lottery round

required
ticketid int

Ticket id

required

Examples:

>>> lottery.ticket_winnings(lotteryround=15, ticketid=567093)
865.536634168
Source code in pancakeswap_lottery/lotteryv2.py
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
def ticket_winnings(self, lotteryround, ticketid):
    """Get lottery winnings (CAKE) for a given ticket and round

    Args:
        lotteryround (int): Lottery round
        ticketid (int): Ticket id

    Examples:
        >>> lottery.ticket_winnings(lotteryround=15, ticketid=567093)
        865.536634168
    """
    winnings = 0
    brackets = [0, 1, 2, 3, 4, 5]

    for bracket in brackets:
        data = self.lottery_contract.functions.viewRewardsForTicketId(
            lotteryround, ticketid, bracket
        ).call()

        if data > 0:
            winnings = data / self.decimals

    return winnings

total_tickets(lotteryround)

Get total number of tickets in lottery round

Parameters:

Name Type Description Default
lotteryround int

Lottery round

required

Examples:

>>> lottery.total_tickets(lotteryround=23)
0
Source code in pancakeswap_lottery/lotteryv2.py
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
def total_tickets(self, lotteryround):
    """Get total number of tickets in lottery round

    Args:
        lotteryround (int): Lottery round

    Examples:
        >>> lottery.total_tickets(lotteryround=23)
        0
    """
    current_round = self.current_round()

    if lotteryround > current_round:
        return 0

    data = self.view_lottery(lotteryround)
    first_ticket_id = data.get("firstTicketId")
    last_ticket_id = data.get("firstTicketIdNextLottery")

    return int(last_ticket_id - first_ticket_id)

winners_per_bracket(lotteryround)

Get number of winners per prize bracket

Parameters:

Name Type Description Default
lotteryround int

Lottery round

required

Examples:

>>> lottery.winners_per_bracket(lotteryround=16)
{
    'match_1': 19133,
    'match_2': 1921,
    'match_3': 188,
    'match_4': 21,
    'match_5': 1,
    'match_6': 1
}
Source code in pancakeswap_lottery/lotteryv2.py
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
def winners_per_bracket(self, lotteryround):
    """Get number of winners per prize bracket

    Args:
        lotteryround (int): Lottery round

    Examples:
        >>> lottery.winners_per_bracket(lotteryround=16)
        {
            'match_1': 19133,
            'match_2': 1921,
            'match_3': 188,
            'match_4': 21,
            'match_5': 1,
            'match_6': 1
        }
    """

    data = self.view_lottery(lotteryround)
    d = data.get("countWinnersPerBracket")

    return d

winning_numbers(lotteryround)

Get winning numbers for lottery round

Parameters:

Name Type Description Default
lotteryround int

Lottery round

required

Examples:

>>> lottery.winning_numbers(lotteryround=16)
0
Source code in pancakeswap_lottery/lotteryv2.py
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
def winning_numbers(self, lotteryround):
    """Get winning numbers for lottery round

    Args:
        lotteryround (int): Lottery round

    Examples:
        >>> lottery.winning_numbers(lotteryround=16)
        0
    """
    data = self.view_lottery(lotteryround)
    final_number = str(data.get("finalNumber"))
    final_number = final_number[::-1][:-1]

    return final_number

winning_probability(numbers_matched=None)

Get percentage probability of winning the lottery

Parameters:

Name Type Description Default
numbers_matched

obj:int, optional): Number of winning numbers matched

None

Examples:

>>> lottery.winning_probability()
{
    'match_1': 10.0,
    'match_2': 1.0,
    'match_3': 0.1,
    'match_4': 0.01,
    'match_5': 0.001,
    'match_6': 0.0001
}
Source code in pancakeswap_lottery/lotteryv2.py
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
def winning_probability(self, numbers_matched=None):
    """Get percentage probability of winning the lottery

    Args:
        numbers_matched (:obj:`int`, optional): Number of winning numbers matched

    Examples:
        >>> lottery.winning_probability()
        {
            'match_1': 10.0,
            'match_2': 1.0,
            'match_3': 0.1,
            'match_4': 0.01,
            'match_5': 0.001,
            'match_6': 0.0001
        }
    """
    possible_numbers = 10
    matchballs = [1, 2, 3, 4, 5, 6]
    probability_pct = {}

    if numbers_matched:
        if numbers_matched not in range(1, 7):
            return "Pick a number between 1 and 6"

        e = possible_numbers**numbers_matched
        odds = 1 / e * 100

        return float(f"{odds:.4f}")

    for matchball in matchballs:
        e = possible_numbers**matchball
        odds = 1 / e * 100
        probability_pct.update({f"match_{matchball}": float(f"{odds:.4f}")})

    return probability_pct