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
import abc | |
class TradeDetails(metaclass=abc.ABCMeta): | |
def __init__(self, start_price: float, symbol: str, amount: float, currency: str = "USD"): | |
self.start_price = start_price | |
self.symbol = symbol.upper() | |
self.amount = amount | |
self.currency = currency |
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 fasttrade.model.trade import TradeDetails | |
class LongTrade(TradeDetails): | |
def __init__(self, start_price: float, symbol: str, amount: float, percent_change: float = 0.5, | |
currency: str = "USD") -> None: | |
super().__init__(start_price, symbol, amount, currency) | |
self.end_price = start_price * (1 + percent_change / 100) |
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 fasttrade.model.trade import TradeDetails | |
class ShortTrade(TradeDetails): | |
def __init__(self, start_price: float, symbol: str, amount: float, percent_change: float = 0.5, | |
currency: str = "USD") -> None: | |
super().__init__(start_price, symbol, amount, currency) | |
self.end_price = start_price * (1 - percent_change / 100) | |
@property |
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 ccxt import Exchange, OrderNotFound | |
class CryptoExchange: | |
def __init__(self, exchange: Exchange): | |
self.exchange = exchange | |
self.exchange.load_markets() | |
@property |
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
import asyncio | |
import logging | |
from ccxt import ExchangeError | |
from model.longtrade import LongTrade | |
from model.shorttrade import ShortTrade | |
class TradeExecutor: |
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
import logging | |
import os | |
import ccxt | |
from core.exchange import CryptoExchange | |
from core.telegrambot import TelegramBot | |
from core.tradeexcutor import TradeExecutor | |
if __name__ == '__main__': |
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
TITLES = ['idx', 'type', 'remaining', 'symbol', 'price'] | |
SPACING = [4, 6, 8, 10, 8] | |
def format_open_orders(orders) -> str: | |
def join_line(ln): | |
return ' | '.join(str(item).center(SPACING[i]) for i, item in enumerate(ln)) | |
title_line = join_line(TITLES) | |
lines = [title_line] |
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
async def _wait_order_complete(self, order_id): | |
status = 'open' | |
order = None | |
while status is 'open': | |
await asyncio.sleep(self.check_timeout) | |
order = self.exchange.fetch_order(order_id) | |
status = order['status'] | |
logging.info(f'Finished order {order_id} with {status} status') |
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
class TelegramBot: | |
class PrivateUserFiler(BaseFilter): | |
def __init__(self, user_id): | |
self.user_id = int(user_id) | |
def filter(self, message): | |
return message.from_user.id == self.user_id | |
def __init__(self, token: str, allowed_user_id, trade_executor: TradeExecutor): | |
self.updater = Updater(token=token) |
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
def _prepare(self): | |
# Create our handlers | |
def show_help(bot, update): | |
update.effective_message.reply_text('Type /trade to show options ') | |
def show_options(bot, update): | |
button_list = [ | |
[InlineKeyboardButton("Short trade", callback_data=SHORT_TRADE), |
OlderNewer