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

Commit 8b6b06f

Browse files
committed
updates
1 parent 6e7b643 commit 8b6b06f

File tree

6 files changed

+49
-20
lines changed

6 files changed

+49
-20
lines changed

Makefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
CONFIG=./config/sandbox_gemini.cfg
2+
EXCHANGE=gemini
3+
CURRENCY=USD
4+
25

36
runconfig: ## Clean and make target, run target
47
python3 -m algocoin --config=$(CONFIG)
@@ -9,15 +12,22 @@ run: clean ## Clean and make target, run target
912
sandbox: ## Clean and make target, run target
1013
python3 -m algocoin --sandbox --verbose=$(VERBOSE) -exchange=$(EXCHANGE)
1114

12-
fetch_data: ## Fetch data
13-
. scripts/fetchdata.sh --exchange=$(EXCHANGE) --currency=$(CURRENCY)
15+
data: ## Fetch data for EXCHANGE
16+
. scripts/fetchdata.sh $(EXCHANGE) $(CURRENCY)
17+
18+
fetch_data: ## Fetch data for EXCHANGE
19+
. scripts/fetchdata.sh $(EXCHANGE) $(CURRENCY)
20+
21+
backtest_config: ## Clean and make target, run backtest
22+
python3 -m algocoin --config=./config/backtest_gemini.cfg
1423

1524
backtest: ## Clean and make target, run backtest
1625
python3 -m algocoin --backtest --verbose=$(VERBOSE) --exchange=$(EXCHANGE)
1726

1827
backtest_inline: ## Clean and make target, run backtest, plot in terminal
1928
bash -c "export MPLBACKEND=\"module://itermplot\"; export ITERMPLOT=\"rv\"; python3 -m algocoin backtest $(VERBOSE) $(EXCHANGE)"
2029

30+
2131
tests: ## Clean and Make unit tests
2232
python3 -m nose -v algocoin/tests --with-coverage --cover-erase --cover-package=`find algocoin -name "*.py" | sed "s=\./==g" | sed "s=/=.=g" | sed "s/.py//g" | tr '\n' ',' | rev | cut -c2- | rev`
2333

@@ -52,4 +62,4 @@ help:
5262
print-%:
5363
@echo '$*=$($*)'
5464

55-
.PHONY: clean run sandbox backtest test tests test_verbose help install docs
65+
.PHONY: clean run runconfig sandbox backtest backtest_config test tests test_verbose help install docs data

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,32 @@ Let's make sure everything worked out by running a sample strategy on the GDAX s
9292
python3 -m algocoin --sandbox
9393
```
9494

95-
### Writing an algorithm
95+
### Writing a trading strategy
96+
Trading strategies implement the `TradingStrategy` abstract class in `algocoin.lib.strategy`. This has a number of required methods for handling messages:
97+
98+
- onBuy
99+
- onSell
100+
- onTrade
101+
- onChange
102+
- onDone
103+
- onError
104+
- onOpen
105+
- onReceived
106+
107+
There are also a variety of optional methods for more granular control over risk/execution/backtesting, such as `slippage`, `transactionCost`, `onHalt`, `onContinue`, etc.
96108

97109
### Backtesting
110+
An instance of `TradingStrategy` class is able to run live or against a set of historical trade/quote data. When instantiating a `TradingEngine` object with a `TradingEngineConfig` object, the `TradingEngineConfig` has a `type` which can be set to `live`, `sandbox`, or `backtest`. Some additional methods are then usable on the `TradingStrategy`, including the `onAnalyze` method which allows you to visualize algorithm performance.
111+
98112

99113
#### Getting Data
114+
Historical data is relatively sparse, but the provided `fetchdata.sh` script will help grab historical data from bitcoincharts.com.
100115

101116
### Sandboxes
117+
Currently only the Gemini sandbox is supported, the other exchanges have discontinued theirs. To run in sandbox, set `TradingEngineConfig.type` to Sandbox.
102118

103119
### Live Trading
120+
When you want to run live, set `TradingEngineConfig.type` to Live. You will want to become familiar with the risk and execution engines, as these control things like max drawdown, max risk accrual, execution eagerness, etc.
104121

105122
---
106123

algocoin/lib/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def _parse_live_options(argv, config: TradingEngineConfig) -> None:
122122
if argv.get('exchange'):
123123
config.exchange_options.exchange_type = str_to_exchange(argv['exchange'])
124124
elif argv.get('exchanges'):
125-
config.exchange_options.exchange_types = [str_to_exchange(x) for x in argv['exchanges'].split(',') if x]
125+
config.exchange_options.exchange_types = [str_to_exchange(x) for x in argv['exchanges'].split() if x]
126126
else:
127127
config.exchange_options.exchange_type = str_to_exchange('')
128128
log.critical('No Exchange set, using default: %s', config.exchange_options.exchange_type)
@@ -134,7 +134,7 @@ def _parse_sandbox_options(argv, config) -> None:
134134
if argv.get('exchange'):
135135
config.exchange_options.exchange_type = str_to_exchange(argv['exchange'])
136136
elif argv.get('exchanges'):
137-
config.exchange_options.exchange_types = [str_to_exchange(x) for x in argv['exchanges'].split(',') if x]
137+
config.exchange_options.exchange_types = [str_to_exchange(x) for x in argv['exchanges'].split() if x]
138138
else:
139139
config.exchange_options.exchange_type = str_to_exchange('')
140140
log.critical('No Exchange set, using default: %s', config.exchange_options.exchange_type)
@@ -148,7 +148,7 @@ def _parse_backtest_options(argv, config) -> None:
148148
config.backtest_options.file = exchange_to_file(str_to_exchange(argv['exchange']))
149149
config.exchange_options.exchange_type = str_to_exchange(argv['exchange'])
150150
elif argv.get('exchanges'):
151-
config.exchange_options.exchange_types = [str_to_exchange(x) for x in argv['exchanges'].split(',') if x]
151+
config.exchange_options.exchange_types = [str_to_exchange(x) for x in argv['exchanges'].split() if x]
152152
else:
153153
config.exchange_options.exchange_type = str_to_exchange('')
154154
log.critical('No Exchange set, using default: %s', config.exchange_options.exchange_type)

config/backtest_gemini.cfg

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
[general]
2-
verbose=1
3-
print=1
2+
verbose=0
3+
print=0
44
TradingType=backtest
55

66
[exchange]
77
exchange=gemini
88

99
[strategy]
1010
strategies =
11-
SMACrossesStrategyWithRegressionFollow, 15, 25
12-
SMACrossesStrategy, 15, 25
11+
algocoin.lib.strategies.test_strat.TestStrategy,
12+
algocoin.lib.strategies.sma_crosses_strategy.SMACrossesStrategy, 15, 25
1313

1414
[risk]
15-
max_drawdown = 100.0 # Max strat drawdown before liquidation
16-
max_risk = 100.0 # Max to risk on any trade
15+
max_drawdown = 100.0
16+
max_risk = 100.0
17+
total_funds = 10.0

config/live_gemini.cfg

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
[general]
2-
verbose=1
3-
print=1
2+
verbose=0
3+
print=0
44
TradingType=live
55

66
[exchange]
77
exchange=gemini
88

99
[strategy]
1010
strategies =
11-
SMACrossesStrategyWithRegressionFollow, 15, 25
12-
SMACrossesStrategy, 15, 25
11+
algocoin.lib.strategies.test_strat.TestStrategy,
12+
algocoin.lib.strategies.sma_crosses_strategy.SMACrossesStrategy, 15, 25
1313

1414
[risk]
15-
max_drawdown = 10.0 # Max strat drawdown before liquidation, 10%
16-
max_risk = 10.0 # Max to risk on any trade, 10%
15+
max_drawdown = 100.0
16+
max_risk = 100.0
17+
total_funds = 10.0

scripts/fetchdata.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
BASE_URL="http://api.bitcoincharts.com/v1/csv/"
33

44
function help_and_quit {
5-
echo "usage: fetchdata -e <bitfinex/bitstamp/coinbase/itbit/kraken/hitbtc/lake> -c <USD>"
5+
echo "usage: fetchdata <bitfinex/bitstamp/coinbase/itbit/kraken/hitbtc/lake> <USD>"
66
exit
77
}
88

0 commit comments

Comments
 (0)