def trade(self, exchange, fund_id, side, amount, price): nonce = str(int(time.time() * 1e6)) print(amount) amount = round(amount, 8) if exchange == "trt": url = "https://api.therocktrading.com/v1/funds/" + fund_id + "/orders" payload_trt = { "fund_id": "BTCEUR", "side": side, "amount": amount, "price": 0 } signature = hmac.new(self.secret_trt.encode(), msg=(str(nonce) + url).encode(), digestmod=hashlib.sha512).hexdigest() _headers = { 'User-Agent': 'PyRock v1', "Content-Type": "application/json", "X-TRT-KEY": self.apikey_trt, "X-TRT-SIGN": signature, "X-TRT-NONCE": nonce } resp = requests.post(url, data=json.dumps(payload_trt), headers=_headers) try: return json.loads(resp.text) except KeyError: return "ERROR" elif exchange == "krk": api = krakenex.API(self.apikey_krk, self.secret_krk) k = KrakenAPI(api) resp = k.add_standard_order(fund_id, side, "limit", str(amount), str(price)) resp = str(resp).replace("\'", "\"") return resp elif exchange == "bnb": if side == "buy": order = self.client.order_limit_buy(symbol=fund_id, quantity=round(amount, 8), price=price) elif side == "sell": order = self.client.order_limit_sell(symbol=fund_id, quantity=round(amount, 8), price=price) return dict(order)
api.load_key(key) api.query_private(method="Balance") k = KrakenAPI(api) k.get_account_balance() k.get_trades_history() ohlc, last = k.get_ohlc_data("BCHUSD") print(ohlc) print(last) # open trade descr = k.add_standard_order(pair="XBTEUR", type="buy", ordertype="market", volume=0.002) descr k.get_open_orders(trades=True) k.get_tradable_asset_pairs() response = api.query_private('AddOrder', { 'pair': 'XXBTZEUR', 'type': 'buy', 'ordertype': 'market', 'volume': '0.002' }) response = api.query_private('AddOrder', { 'pair': 'XXBTZEUR', 'type': 'sell',
def __trade(self, exchange, fund_id, side, amount, price=0, order_type=None): print(exchange, fund_id, side, amount) nonce = str(int(time.time() * 1e6)) amount = round(amount, 8) try: if side == 'sell': price = price - 50 elif side == 'buy': price = price + 50 if order_type == "limit": price = price except TypeError: price = 0 pass if exchange == "TRT": url = "https://api.therocktrading.com/v1/funds/" + fund_id + "/orders" payload_TRT = { "fund_id": self.pair, "side": side, "amount": amount, "price": price } print(payload_TRT) signature = hmac.new(self.secret_TRT.encode(), msg=(str(nonce) + url).encode(), digestmod=hashlib.sha512).hexdigest() _headers = { 'User-Agent': 'PyRock v1', "Content-Type": "application/json", "X-TRT-KEY": self.apikey_TRT, "X-TRT-SIGN": signature, "X-TRT-NONCE": nonce } resp = requests.post(url, data=json.dumps(payload_TRT), headers=_headers) try: return json.loads(resp.text) except KeyError: return "ERROR" elif exchange == "krk": api = krakenex.API(self.apikey_krk, self.secret_krk) k = KrakenAPI(api) resp = k.add_standard_order(fund_id, side, "limit", str(amount), str(price)) resp = str(resp).replace("\'", "\"") return resp elif exchange == "BNB": if side == "buy": order = self.client.order_market_buy( symbol=fund_id, quantity=round(math.trunc(amount * 1000) / 1000, 5)) elif side == "sell": order = self.client.order_market_sell( symbol=fund_id, quantity=round(math.trunc(amount * 1000) / 1000, 5)) return dict(order)