Skip to content

Instantly share code, notes, and snippets.

@vindard
Created October 13, 2022 15:16
Show Gist options
  • Save vindard/1dd21def6d61315c99c697258596d2bd to your computer and use it in GitHub Desktop.
Save vindard/1dd21def6d61315c99c697258596d2bd to your computer and use it in GitHub Desktop.
Sketching out all the different conversion methods we can get from stablesats
import math
btc = 10_000_000
usd = 200_000
btcusd = btc/usd
def cents_from_sats(sats, rate):
return sats / btcusd
def sats_from_cents(cents):
return cents * btcusd
immediate = 0.001
future = 0.0012
def sub_spread(spread_type): return 1 - spread_type
def add_spread(spread_type): return 1 + spread_type
# CENTS FROM SATS
def cents_from_sats_immediate_buy(sats):
return math.floor(cents_from_sats(sats) * sub_spread(immediate))
def cents_from_sats_immediate_sell(sats):
return math.ceil(cents_from_sats(sats) * add_spread(immediate))
def cents_from_sats_future_buy(sats):
return math.floor(cents_from_sats(sats) * sub_spread(future))
def cents_from_sats_future_sell(sats):
return math.ceil(cents_from_sats(sats) * add_spread(future))
# SATS FROM CENTS
def sats_from_cents_immediate_buy(cents):
return math.ceil(sats_from_cents(cents) * add_spread(immediate))
def sats_from_cents_immediate_sell(cents):
return math.floor(sats_from_cents(cents) * sub_spread(immediate))
def sats_from_cents_future_buy(cents):
return math.ceil(sats_from_cents(cents) * add_spread(future))
def sats_from_cents_future_sell(cents):
return math.floor(sats_from_cents(cents) * sub_spread(future))
def run_sats(sats):
return {
"cents_from_sats_immediate_buy": cents_from_sats_immediate_buy(sats),
"cents_from_sats_immediate_sell": cents_from_sats_immediate_sell(sats),
"cents_from_sats_future_buy": cents_from_sats_future_buy(sats),
"cents_from_sats_future_sell": cents_from_sats_future_sell(sats),
}
def run_cents(cents):
return {
"sats_from_cents_immediate_buy": sats_from_cents_immediate_buy(cents),
"sats_from_cents_immediate_sell": sats_from_cents_immediate_sell(cents),
"sats_from_cents_future_buy": sats_from_cents_future_buy(cents),
"sats_from_cents_future_sell": sats_from_cents_future_sell(cents),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment