Skip to content
This repository was archived by the owner on May 8, 2021. It is now read-only.

Commit b8f1039

Browse files
commit
1 parent 56ca333 commit b8f1039

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

libkloudtrader/algorithm.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,16 @@ def backtest(strategy: str,
7878
#print(locals()[a](symbol, start_date, end_date))
7979

8080

81-
def live_trade(strategy_name: str,
81+
def live_trade(strategy: str,
8282
symbol_bucket: list,
8383
data_feed_type: str,
84-
states: list = ['open', 'postmarket', 'close'],
84+
exempted_states: list = ['close'],
8585
batch_size: int = 1000,
8686
feed_delay: float = 0.0,
8787
fake_feed: bool = False):
8888
try:
8989
logger.info("{} is now entering the live markets. 📈\n".format(
90-
strategy_name.__name__))
90+
strategy.__name__))
9191
if isinstance(symbol_bucket, list):
9292
symbol_bucket = np.array(symbol_bucket)
9393
elif type(symbol_bucket) not in (numpy.ndarray, list):
@@ -100,22 +100,22 @@ def live_trade(strategy_name: str,
100100
if data_feed_type in ("CRYPTO_live_feed", 'CRYPTO_live_feed_level2'):
101101
feed_delay = 2
102102
data_feed = Data_Types[data_feed_type].value
103-
while stocks.intraday_status()['state'] in states:
103+
while stocks.intraday_status()['state'] not in exempted_states:
104104
batch = processing.Buffer(batch_size, dtype=object)
105105
while len(batch) < batch_size:
106106
for symbol in symbol_bucket:
107107
batch.append(data_feed(symbol, fake_feed=fake_feed))
108108
data_batch = pd.DataFrame(batch)
109-
locals()['strategy_name'](data_batch)
109+
locals()['strategy'](data_batch)
110110
if len(batch) == batch_size:
111111
batch.popleft()
112112
time.sleep(feed_delay)
113113
except (KeyboardInterrupt, SystemExit):
114114
print('\n')
115115
logger.critical("User's keyboard prompt stopped {}".format(
116-
strategy_name.__name__))
116+
strategy.__name__))
117117
except Exception as exception:
118-
logger.critical('Exiting {}...‼️'.format(strategy_name.__name__))
118+
logger.critical('Exiting {}...‼️'.format(strategy.__name__))
119119
logger.error(
120120
'Oops! Something went wrong while your algorithm was being deployed to live markets. ⚠️'
121121
)

libkloudtrader/crypto.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ def ohlcv(symbol: str,
148148
raise exception
149149

150150

151-
def latest_trades(symbol: str,
152-
number_of_data_points: int = 1,
153-
exchange: str = CRYPTO_EXCHANGE,
154-
rate_limit: bool = True):
151+
def trades(symbol: str,
152+
number_of_data_points: int = 1,
153+
exchange: str = CRYPTO_EXCHANGE,
154+
rate_limit: bool = True):
155155
"""Get recent trades for a particular trading symbol."""
156156
try:
157157
check_exchange_existence(exchange=exchange)

libkloudtrader/crypto_operations.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ async def getOHLCV(symbol: str, start: str, end: str, interval: str,
410410
minutes=1)) / int(interval_value[interval]) + 1
411411
since = int(converted_start.timestamp() * 1000)
412412
else:
413+
await exchange_class.close()
413414
InvalidTimeInterval("Invalid Time Interval")
414415
data = await exchange_class.fetchOHLCV(symbol, interval, since,
415416
int(limit))
@@ -427,15 +428,16 @@ async def getOHLCV(symbol: str, start: str, end: str, interval: str,
427428
'volume': data[values][5]
428429
}
429430
final_list.append(new_list)
430-
await exchange_class.close()
431431
if dataframe:
432432
import pandas
433433
columns = ['time', 'open', 'high', 'low', 'close', 'volume']
434434
df = pandas.DataFrame(final_list, columns=columns)
435435
df['datetime'] = pandas.to_datetime(df['time'])
436436
df.set_index(['datetime'], inplace=True)
437437
del df['time']
438+
await exchange_class.close()
438439
return df
440+
await exchange_class.close()
439441
return final_list
440442
raise FunctionalityNotSupported(
441443
"Functionality not available for this exchange.")

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"numpy",
1818
"empyrical",
1919
"asyncio",
20-
"ccxt @ git+ssh://git@github.com/kloudtrader/kloudtrader_ccxt#egg=ccxt"
20+
"ccxt @ git+https://github.com/kloudtrader/kloudtrader_ccxt#egg=ccxt"
2121
],
2222
)

1.py renamed to sma_live.py

File renamed without changes.

tests/test_crypto.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ def test_invalid_date_format(self):
8585
class Test_trades:
8686
def test_return_type(self):
8787
'''test return type'''
88-
data=crypto.latest_trades('ETH/BTC',exchange="binance",number_of_data_points=5)
88+
data=crypto.trades('ETH/BTC',exchange="binance",number_of_data_points=5)
8989
assert isinstance(data,list) and not 'message' in data
9090

9191
def test_number_data_points(self):
9292
'''test number of data points'''
93-
data=crypto.latest_trades('ETH/BTC',exchange="binance",number_of_data_points=5)
93+
data=crypto.trades('ETH/BTC',exchange="binance",number_of_data_points=5)
9494
assert len(data)==5
9595

9696
class Test_order_book:

0 commit comments

Comments
 (0)