Skip to content

Commit

Permalink
🦑 fix(order): kraken 🦑 (#218)
Browse files Browse the repository at this point in the history
* get full order details

* simplify csv

* #patch

* add notes for supporting multiple exchanges

* lint

* add proper side for test kraken trade execution

* get_test_side
  • Loading branch information
suchak1 authored Jan 4, 2023
1 parent fdcab07 commit 8b509ce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
13 changes: 10 additions & 3 deletions hyperdrive/Exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import hashlib
import requests
import urllib.parse
from collections import OrderedDict
from binance import Client
from binance.helpers import round_step_size
from dotenv import load_dotenv, find_dotenv
Expand Down Expand Up @@ -185,7 +184,7 @@ def get_trades(self, trade_ids):
return trades

def standardize_order(self, order, trades):
std = OrderedDict()
std = {}
std['symbol'] = order['descr']['pair']
std['orderId'] = order['order_id']
std['transactTime'] = int(
Expand All @@ -205,7 +204,7 @@ def standardize_order(self, order, trades):
std['side'] = side

def standardize_trade(trade):
std_trade = OrderedDict()
std_trade = {}
std_trade['price'] = str(round(float(trade['price']), 10))
std_trade['qty'] = trade['vol']
std_trade['commission'] = trade['fee']
Expand All @@ -215,6 +214,14 @@ def standardize_trade(trade):
std['fills'] = fills
return std

def get_test_side(self, base, quote):
pair = f'{base}{quote}'
pair_info = self.get_asset_pair(pair)
balance = float(self.get_balance()[base])
min_order = float(pair_info['ordermin'])
side = 'buy' if balance < min_order else 'sell'
return side


class Binance(CEX):
def __init__(self, key=None, secret=None, testnet=False):
Expand Down
8 changes: 6 additions & 2 deletions scripts/execute_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,24 @@
base = 'XXBT'
quote = 'ZUSD'
spend_ratio = 0.0005 if test else 1
if test:
side = kr.get_test_side(base, quote)

order = kr.order(base, quote, side, spend_ratio, test)
if not test:
order = kr.get_order(order['txid'])
trades = kr.get_trades(order['trades'])
order = kr.standardize_order(order, trades)
order['exchange'] = C.KRAKEN

order_df = pd.json_normalize(order)

# to keep track of multiple orders (from multiple exchanges),
# order_df = pd.concat(bin_order_df, kr_order_df)
yesterday = (
datetime.utcnow().date() -
timedelta(days=1)
).strftime(C.DATE_FMT)
order_df[C.TIME] = [yesterday]
order_df[C.TIME] = [yesterday for _ in range(len(order_df))]

orders = md.reader.update_df(orders_path, order_df, C.TIME, C.DATE_FMT)
md.writer.update_csv(orders_path, orders)
6 changes: 1 addition & 5 deletions test/test_Exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ def test_init(self):
def test_order(self):
base = 'XXBT'
quote = 'ZUSD'
pair = f'{base}{quote}'
pair_info = kr.get_asset_pair(pair)
balance = float(kr.get_balance()[base])
min_order = float(pair_info['ordermin'])
side = 'buy' if balance < min_order else 'sell'
side = kr.get_test_side(base, quote)
kr.order(base, quote, side, 0.0005, test=True)

def test_standardize_order(self):
Expand Down

0 comments on commit 8b509ce

Please sign in to comment.