• PyByte
  • Posts
  • How FTX used Python code to lie

How FTX used Python code to lie

PyByte 0.2

from PyByte import whats_new, trick_of_the_week, get_inspired, fun_or_funny

# Welcome to the PyByte!

👋 Hey, and thanks for joining PyByte, a quick way to inject Python into your week!

whats_new()

Did you know that Python is open source?

Lots of individuals have contributed to Python over the years. I recently met someone who contributed to the Flask package back in it’s early days (we’re talking the 90s 💾).

Meta (formerly Facebook) published an article about how they contributed heavily to last week’s release of 3.12.

The interesting thing to me reading this is Meta uses Python code in the Instagram workflow. They admit that the primary reason for introducing Immortal Objects (one of the new features) was to decrease memory consumption, specifically for the Instagram web-server when it forks (creates a copy of itself).

Python is the #2 used language in the world, so it shouldn’t be too surprising that a big company like Meta would contribute to it’s development.

trick_of_the_week()

Use the gif library to animate your matplotlib plot. Even if you don’t use matplotlib, you have to admit this is cool. 🤯

import pandas as pd
from matplotlib import pyplot as plt
import random

import gif


START = pd.Timestamp("2019-04-20")
END = pd.Timestamp("2020-05-01")


data = [random.uniform(0.5, 10) for _ in range(378)]

df = pd.DataFrame({"date": pd.date_range(start=START, end=END), "time": data})


@gif.frame
def plot(date):
    d = df[df["date"] <= date]
    fig, ax = plt.subplots(figsize=(5, 3), dpi=100)
    plt.plot(d["date"], d["time"])
    ax.set_xlim([START, END])
    ax.set_ylim([0, 10])
    ax.set_xticks([date])
    ax.set_yticks([0, 2, 4, 6, 8, 10])
    ax.set_xticklabels([date.strftime("%b '%y")])
    ax.set_yticklabels([0, 2, 4, 6, 8, "\n10\nhours"])


frames = []
for date in df["date"]:
    frame = plot(date)
    frames.append(frame)

gif.save(frames, "phone.gif", duration=35)

get_inspired()

Your identity is fundamentally two things: it’s 1) the story or narrative you have for yourself, and it’s 2) the standards or commitments you hold for yourself…

Elevating and committing to specific standards is how you evolve your identity.

Dr. Benjamin Hardy (10x is easier than 2x)

How to elevate your standards using the 4Cs 📈 (according to Dan Sullivan):

  1. Commitment: Dedicate yourself fully to a specific goal or purpose.

  2. Courage: Face fears and challenges head-on, despite uncertainties.

  3. Capability: Develop and hone the skills necessary to achieve your goals.

  4. Confidence: Gain trust in oneself through continuous success and experience.

fun_or_funny() X 2

Someone compared Data Analytics to being a parent and the parallel is uncanny… 🤔 the comments had a bunch more insights.

What do you think?

Accurate?

Also.. it was discovered this week that FTX used Python to commit fraud. I told you Python was popular 🙃 

Here is the actual code they used. As you can see, they used numpy to generate a random number around 7500 to generate a fake number in an insurance fund…

def _get_change() -> Decimal:
    daily_volume = current_session().query(func.sum(Trade.size * Trade.price)).filter(
        Trade.created_at > datetime.now() - timedelta(days=1)).scalar() or Decimal()
    return f2d(numpy.random.normal(7500, 3000)) * daily_volume / Decimal('1e9')

@always_run_in_transaction(ro=False)
def update_public_insurance_fund():
    change = _get_change()
    sess = current_session()
    public_insurance_fund = PublicInsuranceFund.get(sess)
    sess.add(PublicInsuranceFundChange(public_insurance_fund=public_insurance_fund, size=change))
    public_insurance_fund.size += change
    sess.commit()

See you next week 👋

Joel