buyprice = float(buyprice) PL = lastClose - buyprice PL_diff = PL / lastClose PL_diffP = PL_diff * 100 PL_diffP = str("%.2f" % PL_diffP + "%") return PL_diffP print(getcurr_price()) price_result.append((i, getcurr_price())) price_resultDF = pd.DataFrame(price_result) print("last trend : " + str(lastTrend) + "& second Trend : " + str(secondTrend)) print("last RSI : " + str(lastRSI)) #retrieves right decimal to create orders symbols = client.get_symbols() symbols = pd.DataFrame(symbols) sell_increment = symbols.loc[symbols['symbol'] == i, 'baseIncrement'].values[0] sell_increment = str(sell_increment) sell_increment_len = sell_increment[::-1].find('.') print(sell_increment_len) print(sell_increment) precision = sell_increment_len try: sellsize = account.loc[account['currency'] == i[:-5], 'available'].values[0] sellsize = float(sellsize) sellsize = "{:.{}f}".format(sellsize, precision) sellsizeT = str(sellsize) except IndexError:
class KucoinApi(PyexAPI): """kucoin API interface. """ logger = logging.getLogger() def __init__(self, api_server: str, api_key: str, secret_key: str, api_passphrase: str, timeout: float, requests_params=None): assert (isinstance(api_server, str)) assert (isinstance(api_key, str)) assert (isinstance(secret_key, str)) assert (isinstance(api_passphrase, str)) assert (isinstance(timeout, float)) self.api_server = api_server self.api_key = api_key self.secret_key = secret_key self.timeout = timeout self.client = Client(api_key, secret_key, api_passphrase) def get_symbols(self): return self.client.get_symbols() def ticker(self, pair: str): assert (isinstance(pair, str)) return self.client.get_ticker(pair) def get_balances(self): return self.client.get_accounts() def get_coin_info(self, coin: str): assert (isinstance(coin, str)) return self.client.get_currency(coin) def order_book(self, pair: str, limit=None): assert (isinstance(pair, str)) return self.client.get_order_book(pair) def get_orders(self, pair: str) -> List[Order]: assert (isinstance(pair, str)) orders = self.client.get_orders(pair, 'active') return list( map(lambda item: Order.to_order(item, pair), orders['items'])) def place_order(self, pair: str, is_sell: bool, price: Wad, amount: Wad) -> str: assert (isinstance(pair, str)) assert (isinstance(is_sell, bool)) assert (isinstance(price, Wad)) assert (isinstance(amount, Wad)) side = self.client.SIDE_SELL if is_sell else self.client.SIDE_BUY self.logger.info(f"Placing order ({side}, amount {amount} of {pair}," f" price {price})...") result = self.client.create_limit_order(pair, side, str(price), str(amount)) order_id = result['orderId'] self.logger.info(f"Placed order as #{order_id}") return order_id def cancel_order(self, order_id: str, is_sell: bool, pair: str): assert (isinstance(order_id, str)) assert (isinstance(is_sell, bool)) assert (isinstance(pair, str)) side = self.client.SIDE_SELL if is_sell else self.client.SIDE_BUY self.logger.info(f"Cancelling order #{order_id} of type {side}...") try: self.client.cancel_order(order_id) self.logger.info(f"Canceled order #{order_id}...") return True except Exception as e: self.logger.error(f"Failed to cancel order #{order_id}... {e}") return False def get_trades(self, pair: str, page_number: int = 1) -> List[Trade]: assert (isinstance(pair, str)) assert (isinstance(page_number, int)) page_number = page_number - 1 limit = 100 result = self.client.get_fills(symbol=pair, page=page_number, page_size=limit) return list( map(lambda item: Trade.from_dict(pair, item), result['items'])) def get_all_trades(self, pair: str, page_number: int = 1) -> List[Trade]: assert (isinstance(pair, str)) assert (page_number == 1) result = self.client.get_trade_histories(pair) return list(map(lambda item: Trade.from_list(pair, item), result))