Last active
May 11, 2021 02:27
-
-
Save mariorz/5d3c9f9fbe693b40fa3c6492ea323e87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from decimal import Decimal | |
import itertools | |
import coinbasepro as cbp | |
def compute_coinbase_attack_cost(): | |
client = cbp.PublicClient() | |
#get last 10000 trades, for good measure | |
trades = list(itertools.islice(client.get_product_trades('DAI-USDC'), 10000)) | |
#filter for off-price trades | |
relevant = [t for t in trades if t['price'] > Decimal('1.02')] | |
#sanity check time-frames | |
print(f"{relevant[-1]['time']} -- {relevant[0]['time']}") | |
#compute total value paid, and total cost | |
sum_paid = sum([t['price']*t['size']) for t in relevant]) | |
sum_value = sum([t['size'] for t in relevant]) | |
cost = sum_paid - sum_value | |
print(f"Sum paid: {sum_paid}") | |
print(f"Sum value: {sum_value}") | |
print(f"Attack cost: {cost}") | |
# >>> import compcb | |
# >>> compcb.compute_coinbase_attack_cost() | |
# 2020-11-26 08:36:42.813000 -- 2020-11-26 09:07:02.573000 | |
# Sum paid: 381453.1254952848200000 | |
# Sum value: 359692.471640000 | |
# Attack cost: 21760.6538552848200000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment