A martingale script for Epicdice

in epicdice •  5 years ago  (edited)

I had been experimenting with martingale. Mostly over 60 or under 45, sometimes with different numbers. Didn't work out well for me but in case somebody needs it, here is a simple script does the job.

import json
import re
import sys
import time

from steem import Steem
from steem.amount import Amount
from steem.transactionbuilder import TransactionBuilder
from steembase import operations

sys.setrecursionlimit(50000)

# config
s = Steem(
    nodes=["https://api.steemit.com"],
    keys=["<active_key>"])

player = "<player_username>"

start_amount = 0.100
start_bid_type = "Below"
start_bid = 45


def parse_memo(memo):
    json_data = re.findall('(\{.*\})', memo)[0]
    json_data = json.loads(json_data)
    return json_data["TransactionId"], json_data["BlockNumber"]


def get_bid_op(block_id, trx_id, s):
    try:
        b = s.get_block(block_id)
    except Exception as e:
        return get_bid_op(block_id, trx_id, s)
    if not b:
        return get_bid_op(block_id, trx_id, s)

    for tx in b["transactions"]:
        if tx["transaction_id"] == trx_id:
            return tx["operations"][0][1]


def check_result_tx(start_block, s):
    found_tx = False
    while not found_tx:
        try:
            b = s.get_block(start_block)
        except Exception as e:
            return check_result_tx(start_block, s)
        if not b:
            return check_result_tx(start_block, s)
        for tx in b["transactions"]:
            for op_type, op_value in tx["operations"]:
                if op_type != "transfer":
                    continue
                if op_value["from"] != "epicdice":
                    continue

                if op_value["to"] != player:
                    continue
                bid_tx, bid_block = parse_memo(op_value["memo"])
                bid_op = get_bid_op(bid_block, bid_tx, s)
                win = 'Won' in op_value["memo"]
                return win, op_value["amount"], bid_op["amount"]
        start_block = start_block + 1
        time.sleep(0.1)


def broadcast_transfer(bid_type, bid_number, bid_amount):
    ops = [
        operations.Transfer(**{
            "from": player,
            "to": "epicdice",
            "amount": bid_amount,
            "memo": f"{bid_type} {bid_number}"
        }),
    ]
    tb = TransactionBuilder(steemd_instance=s)
    tb.appendOps(ops)
    tb.appendSigner(player, "active")
    tb.sign()
    response = s.broadcast_transaction_synchronous(tb.json())
    block_num = response.get("block_num")

    return block_num


def martingale(amount=None, bid_type=None, bid=None, total_win_amount=0,
               total_loss_amount=0, stop_loss=33.9, bid_no=1, total_wagered=0):
    amount = amount or start_amount
    bid_type = bid_type or start_bid_type
    bid = bid or start_bid
    if amount > stop_loss:
        return martingale(total_win_amount=total_win_amount,
                          total_loss_amount=total_loss_amount, bid_no=bid_no, total_wagered=total_wagered)

    profit = round((total_win_amount - total_loss_amount), 3)
    total_wagered = round(total_wagered, 3)
    print(
        f"Bid: #{bid_no} {amount} STEEM ({bid_type} {bid})"
        f" [Profit: {profit} STEEM] [Total Wagered: {total_wagered} STEEM]")

    block_id = broadcast_transfer(bid_type, bid, f"{amount} STEEM")
    win, payout_amount, bid_amount = check_result_tx(block_id, s)
    payout_amount = Amount(payout_amount)
    bid_amount = Amount(bid_amount)
    total_wagered += bid_amount.amount
    bid_no += 1
    total_win_amount += payout_amount.amount
    total_loss_amount += bid_amount.amount
    if win:
        return martingale(
            total_win_amount=total_win_amount,
            total_loss_amount=total_loss_amount,
            bid=bid,
            bid_no=bid_no, total_wagered=total_wagered)
    else:
        bid = start_bid
        amount = (amount * 2)
        amount = round(amount, 3)
        return martingale(amount=amount, bid_type=bid_type, bid=bid,
                          total_win_amount=total_win_amount,
                          total_loss_amount=total_loss_amount, bid_no=bid_no, total_wagered=total_wagered)


martingale()

Once you run it, you will see an output like this:

Bid: #1 0.1 STEEM (Below 50) [Profit: 0 STEEM] [Total Wagered: 0 STEEM]
Bid: #2 0.1 STEEM (Below 50) [Profit: 0.1 STEEM] [Total Wagered: 0.1 STEEM]
Bid: #3 0.1 STEEM (Below 50) [Profit: 0.2 STEEM] [Total Wagered: 0.2 STEEM]

It requires steem-python and probably Python3.6+.

It's not the best, but it works. For example, if follows the recursive approach instead of an iterative approach. (laziness, I love it.) Make sure you audit the code before actually using it. If you don't have the skills to audit it, don't use it.. Even though I didn't encounter any bug while wagering 20k+ STEEM with this, there is no warranty. Use it at your own risk.

As a final note, if you didn't try Epicdice yet, try registering with my referer link so I can grab a couple of extra drinks this Friday. 😇

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Upon first glance I approve of your Martingale Script. The more people using it, the better for all div holders!

Posted using Partiko Android

✌️