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

Commit 857a5d1

Browse files
committed
incidentals
1 parent 04568f8 commit 857a5d1

File tree

5 files changed

+48
-31
lines changed

5 files changed

+48
-31
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ docs: ## Build the sphinx docs
3737
make -C docs html
3838

3939
clean: ## clean the repository
40-
find . -name "__pycache__" -exec rm -rf {} \;
41-
find . -name "*.pyc" -exec rm -rf {} \;
40+
find . -name "__pycache__" | xargs rm -rf
41+
find . -name "*.pyc" | xargs rm -rf
4242
rm -rf .coverage cover htmlcov logs build dist *.egg-info
4343

4444
install: ## install the package

algocoin/lib/exchanges/gdax.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
from websocket import create_connection
44
from ..config import ExchangeConfig
5+
from ..define import EXCHANGE_ORDER_ENDPOINT
56
from ..enums import TradingType, ExchangeType
67
from ..exchange import Exchange
78
from ..structs import TradeRequest, TradeResponse, Account
@@ -26,10 +27,11 @@ def __init__(self, options: ExchangeConfig) -> None:
2627

2728
elif options.trading_type == TradingType.SANDBOX:
2829
self._key, self._secret, self._passphrase = get_keys_from_environment('GDAX_SANDBOX')
30+
import ipdb; ipdb.set_trace()
2931
self._client = gdax.AuthenticatedClient(self._key,
3032
self._secret,
3133
self._passphrase,
32-
api_url=self._oe_url
34+
api_url=EXCHANGE_ORDER_ENDPOINT(ExchangeType.GDAX, TradingType.SANDBOX)
3335
)
3436

3537
val = self._client.get_accounts() if hasattr(self, '_client') else []

algocoin/lib/parser.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _parse_strategy(strategy, config) -> None:
8282
def _parse_risk(risk, config) -> None:
8383
config.risk_options.max_drawdown = float(risk.get('max_drawdown', config.risk_options.max_drawdown))
8484
config.risk_options.max_risk = float(risk.get('max_drawdown', config.risk_options.max_risk))
85-
config.risk_options.total_funds = float(risk.get('max_drawdown', config.risk_options.total_funds))
85+
config.risk_options.total_funds = float(risk.get('total_funds', config.risk_options.total_funds))
8686

8787

8888
def _parse_default(default, config) -> None:
@@ -114,28 +114,39 @@ def _parse_args_to_dict(argv: list) -> dict:
114114

115115
def _parse_live_options(argv, config: TradingEngineConfig) -> None:
116116
log.critical("WARNING: Live trading. money will be lost ;^)")
117-
config.exchange_options.exchange_type = \
118-
str_to_exchange(argv.get('exchange', ''))
117+
if argv.get('exchange'):
118+
config.exchange_options.exchange_type = str_to_exchange(argv['exchange'])
119+
elif argv.get('exchanges'):
120+
config.exchange_options.exchange_types = [str_to_exchange(x) for x in argv['exchanges'].split(',') if x]
121+
else:
122+
config.exchange_options.exchange_type = str_to_exchange('')
123+
log.critical('No Exchange set, using default: %s', config.exchange_options.exchange_type)
119124

120125

121126
def _parse_sandbox_options(argv, config) -> None:
122127
log.critical("Sandbox trading")
123-
config.exchange_options.exchange_type = \
124-
str_to_exchange(argv.get('exchange', ''))
128+
if argv.get('exchange'):
129+
config.exchange_options.exchange_type = str_to_exchange(argv['exchange'])
130+
elif argv.get('exchanges'):
131+
config.exchange_options.exchange_types = [str_to_exchange(x) for x in argv['exchanges'].split(',') if x]
132+
else:
133+
config.exchange_options.exchange_type = str_to_exchange('')
134+
log.critical('No Exchange set, using default: %s', config.exchange_options.exchange_type)
125135

126136

127137
def _parse_backtest_options(argv, config) -> None:
128138
log.critical("Backtesting")
129139

130140
config.backtest_options = BacktestConfig()
131141

132-
config.backtest_options.file = \
133-
exchange_to_file(str_to_exchange(argv.get('exchange', '')))
134-
135-
config.exchange_options.exchange_type = \
136-
str_to_exchange(argv.get('exchange', ''))
137-
138-
config.risk_options.total_funds = 20000.0 # FIXME
142+
if argv.get('exchange'):
143+
config.backtest_options.file = exchange_to_file(str_to_exchange(argv['exchange']))
144+
config.exchange_options.exchange_type = str_to_exchange(argv['exchange'])
145+
elif argv.get('exchanges'):
146+
config.exchange_options.exchange_types = [str_to_exchange(x) for x in argv['exchanges'].split(',') if x]
147+
else:
148+
config.exchange_options.exchange_type = str_to_exchange('')
149+
log.critical('No Exchange set, using default: %s', config.exchange_options.exchange_type)
139150

140151

141152
def parse_command_line_config(argv: list) -> TradingEngineConfig:

algocoin/lib/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,13 @@ def config(cls):
7272
isinstance(v[0][0], type) and \
7373
isinstance(v[1], list):
7474
# v is a pair, ([type], [instance?])
75-
if len(v[1]) > 0 and isinstance(v[1][0], v[0][0]): # TODO check all
75+
if len(v[1]) > 0 and isinstance(v[1][0], v[0][0]): # TODO check all
7676
v = create_pair(k, v[0][0], v[1], container=list)
7777
vars.append(k)
7878
elif v[1] == []:
7979
v = create_pair(k, v[0][0], v[1], container=list)
8080
vars.append(k)
8181
else:
82-
print(v)
8382
raise Exception('Unexpected list instance: %s' % v[1][0])
8483

8584
new_cls_dict[k] = v

algocoin/trading.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Callable
22
from .backtest import Backtest
3-
from .lib.callback import Callback, Print
3+
from .lib.callback import Print
44
from .lib.config import TradingEngineConfig
55
from .lib.enums import TradingType, Side, CurrencyType, TradeResult, OrderType
66
from .execution import Execution
@@ -15,19 +15,28 @@ class TradingEngine(object):
1515
def __init__(self, options: TradingEngineConfig) -> None:
1616
# running live?
1717
self._live = options.type == TradingType.LIVE
18+
1819
# running sandbox?
1920
self._sandbox = options.type == TradingType.SANDBOX
21+
2022
# running backtest?
2123
self._backtest = options.type == TradingType.BACKTEST
2224

23-
# running print callback for debug?
24-
self._print = options.print
25-
2625
# the strategies to run
2726
self._strats = []
2827

29-
self._ex = ex_type_to_ex(options.exchange_options.exchange_type)(options.exchange_options) if self._live or self._sandbox else None
30-
# self._exchanges = [ex_type_to_ex(o.exchange_options.exchange_type)(o.exchange_options) if self._live or self._sandbox else None for o in options]
28+
# instantiate exchange instance
29+
if options.exchange_options.exchange_types:
30+
# multiple exchanges
31+
# TODO
32+
# FIXME
33+
self._ex = [ex_type_to_ex(o)(options.exchange_options) if self._live or self._sandbox else None for o in options.exchange_options.exchange_types]
34+
# FIXME
35+
# TODO
36+
37+
else:
38+
# single exchange
39+
self._ex = ex_type_to_ex(options.exchange_options.exchange_type)(options.exchange_options) if self._live or self._sandbox else None
3140

3241
self._exchanges = []
3342

@@ -56,18 +65,14 @@ def __init__(self, options: TradingEngineConfig) -> None:
5665
# sanity check
5766
assert not (self._live and self._sandbox and self._backtest)
5867

59-
if self._print:
68+
# running print callback for debug?
69+
if options.print:
6070
log.warn('WARNING: Running in print mode')
6171

72+
# register a printer callback that prints every message
6273
if self._live or self._sandbox:
6374
self._ex.registerCallback(
64-
Print(onTrade=True,
65-
onReceived=True,
66-
onOpen=True,
67-
onDone=True,
68-
onChange=True,
69-
onError=False))
70-
75+
Print(onTrade=True, onReceived=True, onOpen=True, onDone=True, onChange=True, onError=False))
7176
if self._backtest:
7277
self._bt.registerCallback(Print())
7378

0 commit comments

Comments
 (0)