Commit d6e401a1 by rakesh.pv

factory

parents
from abc import ABC, abstractmethod
class SellStrategy(ABC):
@abstractmethod
def sell_crypto(self, x: float, y: float):
"""sells crypto and returns new x"""
class SellAll(SellStrategy):
def sell_crypto(self, x: float, y: float):
btc = 0
usdt = x * y
return {"btc": btc, "usdt": usdt}
class SellHalf(SellStrategy):
def sell_crypto(self, x: float, y: float):
btc = x / 2
usdt = (x / 2) * y
return {"btc": btc, "usdt": usdt}
class SellLittle(SellStrategy):
def sell_crypto(self, x: float, y: float):
btc = x * 0.9
usdt = (x * 0.1) * y
return {"btc": btc, "usdt": usdt}
class TradingApp:
assets = {"btc": 100, "usdt": 0}
y = 30000
def sell_order(self, sell_decision: SellStrategy):
self.assets = sell_decision.sell_crypto(self.assets["btc"], self.y)
return self.assets
A = TradingApp()
assets = A.sell_order(SellAll())
print(assets)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment