Skip to content

Commit

Permalink
Remove history
Browse files Browse the repository at this point in the history
  • Loading branch information
brainfrog committed Mar 10, 2018
1 parent 16175bd commit 66635cb
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 125 deletions.
20 changes: 0 additions & 20 deletions kraken_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class Kraken(krakenex.API):
_assets = {}
_trades = []

def __init__(self, keyfile="kraken.key", retries=0):
super().__init__()
Expand Down Expand Up @@ -187,22 +186,3 @@ def api_state():
for name in comp_inner_cont.find_all(class_="name"):
if "API" in name.get_text():
return comp_inner_cont.find(class_="component-status").get_text().strip()

def trades_history(self):
# Send request to Kraken to get trades history
res_trades = self.query("TradesHistory", private=True)

if res_trades["error"]:
return False, res_trades["error"][0]

for trade_id, trade_details in res_trades["result"]["trades"].items():
self._trades.append(trade_details)

if self._trades:
# Sort trades on executed time
self._trades = sorted(self._trades, key=lambda k: k['time'], reverse=True)

return True, self._trades

def get_trades(self):
return self._trades
105 changes: 0 additions & 105 deletions telegram_kraken_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ class WorkflowEnum(Enum):
VALUE_CURRENCY = auto()
BOT_SUB_CMD = auto()
CHART_CURRENCY = auto()
HISTORY_NEXT = auto()
FUNDING_CURRENCY = auto()
FUNDING_CHOOSE = auto()
WITHDRAW_WALLET = auto()
WITHDRAW_VOLUME = auto()
WITHDRAW_CONFIRM = auto()
SETTINGS_CHANGE = auto()
SETTINGS_SAVE = auto()
SETTINGS_CONFIRM = auto()
Expand All @@ -98,9 +92,6 @@ class KeyboardEnum(Enum):
UPDATE = auto()
RESTART = auto()
SHUTDOWN = auto()
NEXT = auto()
DEPOSIT = auto()
WITHDRAW = auto()
SETTINGS = auto()
API_STATE = auto()
MARKET_PRICE = auto()
Expand Down Expand Up @@ -949,88 +940,6 @@ def start_cmd(bot, update):
update.message.reply_text(msg, reply_markup=keyboard_cmds())


# Returns a string representation of a trade. Looks like this:
# sell 0.03752345 ETH-EUR @ limit 267.5 on 2017-08-22 22:18:22
def get_trade_str(trade):
from_asset, to_asset = assets_from_pair(trade["pair"])

if from_asset and to_asset:
pair = assets[from_asset]["altname"] + "-" + assets[to_asset]["altname"]
else:
pair = trade["pair"]

# Build the string representation of the trade
trade_str = (trade["type"] + " " +
trim_zeros(trade["vol"]) + " " +
pair + " @ limit " +
trim_zeros(trade["price"]) + " on " +
datetime_from_timestamp(trade["time"]))

return trade_str


def trades_to_msg(trades):
msg = ""
# Get number of first items in list (latest trades)
for items in range(config["history_items"]):
newest_trade = next(iter(trades), None)

one, two = assets_from_pair(newest_trade["pair"])

# It's a fiat currency
if two.startswith("Z"):
total_value = "{0:.2f}".format(float(newest_trade["price"]) * float(newest_trade["vol"]))
# It's a digital currency
else:
total_value = "{0:.8f}".format(float(newest_trade["price"]) * float(newest_trade["vol"]))

msg += get_trade_str(newest_trade) + " (Value: " + total_value + " " + assets[two]["altname"] + ")\n"

# Remove the first item in the trades list
trades.remove(newest_trade)

return msg


# Shows executed trades with volume and price
@restrict_access
def history_cmd(bot, update):
update.message.reply_text(emo_wa + " Retrieving finalized trades...")

trades = get_api_result(kraken.trades_history(), update)

if trades:
buttons = [
KeyboardButton(KeyboardEnum.NEXT.clean()),
KeyboardButton(KeyboardEnum.CANCEL.clean())
]

msg = trades_to_msg(trades)
reply_mrk = ReplyKeyboardMarkup(build_menu(buttons, n_cols=2), resize_keyboard=True)
update.message.reply_text(bold(msg), reply_markup=reply_mrk, parse_mode=ParseMode.MARKDOWN)

return WorkflowEnum.HISTORY_NEXT
else:
update.message.reply_text("No item in trade history", reply_markup=keyboard_cmds())

return ConversationHandler.END


# Save if BUY, SELL or ALL trade history and choose how many entries to list
def history_next(bot, update):
trades = kraken.get_trades()
if trades:
msg = trades_to_msg(trades)
update.message.reply_text(bold(msg), parse_mode=ParseMode.MARKDOWN)

return WorkflowEnum.HISTORY_NEXT
else:
msg = bold("Trade history is empty")
update.message.reply_text(emo_fi + " " + msg, reply_markup=keyboard_cmds(), parse_mode=ParseMode.MARKDOWN)

return ConversationHandler.END


# Shows sub-commands to control the bot
@restrict_access
def bot_cmd(bot, update):
Expand Down Expand Up @@ -1361,7 +1270,6 @@ def keyboard_cmds():
KeyboardButton("/price"),
KeyboardButton("/value"),
KeyboardButton("/chart"),
KeyboardButton("/history"),
KeyboardButton("/bot")
]

Expand Down Expand Up @@ -1671,19 +1579,6 @@ def handle_telegram_error(bot, update, error):
dispatcher.add_handler(CommandHandler("start", start_cmd))


# HISTORY conversation handler
history_handler = ConversationHandler(
entry_points=[CommandHandler('history', history_cmd)],
states={
WorkflowEnum.HISTORY_NEXT:
[RegexHandler(comp("^(NEXT)$"), history_next),
RegexHandler(comp("^(CANCEL)$"), cancel)]
},
fallbacks=[CommandHandler('cancel', cancel)]
)
dispatcher.add_handler(history_handler)


# CHART conversation handler
chart_handler = ConversationHandler(
entry_points=[CommandHandler('chart', chart_cmd)],
Expand Down

0 comments on commit 66635cb

Please sign in to comment.