forked from TradeGuild/trade-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request TradeGuild#7 from GitGuild/experimental
MVP
- Loading branch information
Showing
16 changed files
with
1,373 additions
and
824 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,87 @@ | ||
makebase = if [ ! -d ~/.tapp ]; \ | ||
PYTHON_VERSION=2.7 # not used... | ||
SHELL = /bin/bash # for pushd, but would probably be better to avoid this | ||
PREREQDIR=. | ||
|
||
makelog = if [ ! -d /var/log/trademanager/ ]; \ | ||
then \ | ||
sudo mkdir /var/log/trademanager/; \ | ||
fi | ||
|
||
makerun = if [ ! -d /var/run/trademanager/ ]; \ | ||
then \ | ||
mkdir ~/.tapp; \ | ||
sudo mkdir /var/run/trademanager/; \ | ||
fi | ||
|
||
makedirs = if [ ! -d ~/.tapp/trademanager ]; \ | ||
installledger = if [ ! -d $(1)/ledger ]; \ | ||
then \ | ||
mkdir ~/.tapp/trademanager; \ | ||
mkdir ~/.tapp/test; \ | ||
cp cfg.ini ~/.tapp/trademanager; \ | ||
cp cfg.ini ~/.tapp/test; \ | ||
git clone git://github.com/ledger/ledger.git $(1)/ledger; \ | ||
pushd $(1)/ledger; \ | ||
if [ $(VIRTUAL_ENV) ]; \ | ||
then \ | ||
./acprep --prefix=$(VIRTUAL_ENV) --python update; \ | ||
else \ | ||
./acprep --python update; \ | ||
fi; \ | ||
make; \ | ||
make install; \ | ||
popd; \ | ||
fi | ||
|
||
installprereqs = if [ ! -d $(1)ledger ]; \ | ||
git clone git://github.com/ledger/ledger.git \ | ||
pushd $(1)ledger \ | ||
./acprep --python update \ | ||
popd \ | ||
export PYTHONPATH=$PYTHONPATH:$(readlink -f $(1)ledger) \ | ||
if [ ! -d $(1)libsecp256k1 ]; \ | ||
git clone git://github.com/bitcoin/secp256k1.git libsecp256k1 \ | ||
pushd $(1)libsecp256k1 \ | ||
git checkout d7eb1ae96dfe9d497a26b3e7ff8b6f58e61e400a \ | ||
./autogen.sh \ | ||
./configure --enable-module-recovery --enable-module-ecdh --enable-module-schnorr \ | ||
make \ | ||
make install \ | ||
popd \ | ||
INCLUDE_DIR=$(readlink -f $(1)libsecp256k1/include) \ | ||
LIB_DIR=$(readlink -f $(1)libsecp256k1/.libs) \ | ||
LD_LIBRARY_PATH=$(readlink -f $(1)libsecp256k1/.libs) | ||
installsecp256k1 = if [ ! -d $(1)/libsecp256k1 ]; \ | ||
then \ | ||
git clone git://github.com/bitcoin/secp256k1.git $(1)/libsecp256k1; \ | ||
pushd $(1)/libsecp256k1; \ | ||
git checkout d7eb1ae96dfe9d497a26b3e7ff8b6f58e61e400a; \ | ||
./autogen.sh; \ | ||
if [ $(VIRTUAL_ENV) ]; \ | ||
then \ | ||
./configure --enable-module-recovery --enable-module-ecdh --enable-module-schnorr --prefix=$(VIRTUAL_ENV); \ | ||
else \ | ||
./configure --enable-module-recovery --enable-module-ecdh --enable-module-schnorr; \ | ||
fi; \ | ||
make; \ | ||
make install; \ | ||
popd; \ | ||
fi | ||
|
||
installlocalgit= if [ -d $(1) ]; \ | ||
then \ | ||
pushd $(1); \ | ||
python setup.py install; \ | ||
popd; \ | ||
else \ | ||
git clone $(2) $(1); \ | ||
pushd $(1); \ | ||
python setup.py install; \ | ||
popd; \ | ||
fi | ||
|
||
makeclean = rm -rf .cache build dist *.egg-info test/__pycache__ \ | ||
rm -rf test/*.pyc *.egg *~ *pyc test/*~ .eggs \ | ||
rm -f .coverage* | ||
|
||
build: | ||
python setup.py build | ||
|
||
hackpendingPRs: | ||
$(call installlocalgit, $(shell readlink -f ../../tapp/tappmq/ https://github.com/GitGuild/tappmq.git)) | ||
$(call installlocalgit, $(shell readlink -f ../../tapp/sqlalchemy-models/ https://github.com/GitGuild/sqlalchemy-models.git)) | ||
|
||
dependencies: | ||
$(call installledger, $(PREREQDIR)) | ||
$(call installsecp256k1, $(PREREQDIR)) | ||
|
||
install: | ||
$(call makebase, "") | ||
$(call makedirs, "") | ||
#if [ $(target) ] \ | ||
#then \ | ||
# $(call installprereqs, $(target)) \ | ||
#else \ | ||
# $(call installprereqs, ./) \ | ||
#fi | ||
$(call makelog, "") | ||
$(call makerun, "") | ||
python setup.py -v install | ||
|
||
clean: | ||
rm -rf .cache build dist *.egg-info test/__pycache__ | ||
rm -rf test/*.pyc *.egg *~ *pyc test/*~ .eggs | ||
rm -f .coverage* | ||
$(call makeclean, "") | ||
|
||
purge: | ||
rm -rf .cache build dist *.egg-info test/__pycache__ | ||
rm -rf test/*.pyc *.egg *~ *pyc test/*~ .eggs | ||
rm -f .coverage* | ||
rm -rf ~/.tapp/trademanager | ||
rm -rf ~/.tapp/test | ||
$(call makeclean, "") | ||
sudo rm -rf /var/run/trademanager | ||
sudo rm -rf /var/log/trademanager | ||
rm -rf $(PREREQDIR)/ledger | ||
rm -rf $(PREREQDIR)/libsecp256k1 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
""" | ||
Ready to go plans for managing your trades. | ||
WARNING: Use at your own risk! | ||
No promise of financial gain is made, and any losses from use of this software are your responsibility. | ||
""" | ||
import time | ||
from ledger import Amount | ||
from tappmq.tappmq import get_running_workers | ||
from trade_manager.plugin import get_balances, get_market_vol_shares, get_usd_value, red, create_order, sync_balances | ||
|
||
MINMM = Amount("5 USD") | ||
MINORDER = Amount("1 USD") | ||
|
||
|
||
def fib_fan(side, amount, ticker, session): | ||
def calc_price(sid, index, offset): | ||
if sid == 'ask': | ||
return index * (Amount("1 %s" % index.commodity) + Amount("%s %s" % (offset, index.commodity)) / 100) | ||
else: | ||
return index * (Amount("1 %s" % index.commodity) - Amount("%s %s" % (offset, index.commodity)) / 100) | ||
|
||
usdamount = get_usd_value(amount) | ||
if usdamount <= MINORDER: | ||
print "ignoring dusty order %s worth %s" % (usdamount, usdamount) | ||
return | ||
fibseq = [1, 2, 3, 5, 8, 13] | ||
index = ticker.calculate_index() | ||
base = ticker.market.split("_")[0] | ||
if usdamount / Amount("{0} USD".format(len(fibseq))) <= MINORDER: | ||
price = calc_price(side, index, fibseq[int(round(len(fibseq) / 2))]) | ||
if side == 'bid': | ||
amount = Amount("{0:.8f} {1}".format(amount.to_double(), base)) / \ | ||
Amount("{0:.8f} {1}".format(index.to_double(), base)) | ||
# usdval = get_usd_value(amount) | ||
# print "{0} {1} @ {2:0.6f} {3} worth ${4:0.2f})".format(side, amount, price.to_double(), ticker.market, | ||
# usdval.to_double()) | ||
create_order(ticker.exchange, price=price, amount=amount, market=ticker.market, side=side, session=session) | ||
else: | ||
if side == 'bid': | ||
amount = Amount("{0:.8f} {1}".format((amount / len(fibseq)).to_double(), base)) / \ | ||
Amount("{0:.8f} {1}".format(index.to_double(), base)) | ||
else: | ||
amount /= len(fibseq) | ||
for fib in fibseq: | ||
price = calc_price(side, index, fib) | ||
create_order(ticker.exchange, price=price, amount=amount, market=ticker.market, side=side, session=session) | ||
# usdval = get_usd_value(amount) * price / index | ||
# print "{0} {1} @ {2:0.6f} {3} worth ${4:0.2f})".format(side, amount, price.to_double(), | ||
# ticker.market, usdval.to_double()) | ||
sync_balances(ticker.exchange) | ||
|
||
|
||
def mm(exchange, callback, session): | ||
print "__________%s mm %s__________" % (exchange, time.asctime(time.gmtime(time.time()))) | ||
bals = get_balances(exchange, session=session) | ||
if bals is not None: | ||
available = bals[1] | ||
for amount in available: | ||
comm = str(amount.commodity) | ||
try: | ||
value = get_usd_value(amount) | ||
except TypeError as e: | ||
print e | ||
continue | ||
if value <= MINMM: | ||
print "ignoring dusty %s worth %s" % (amount, value) | ||
continue | ||
vshares = get_market_vol_shares(exchange, comm) | ||
for market in vshares: | ||
if market == 'total': | ||
continue | ||
vshare = vshares[market]['vol_share'] | ||
if market.find(comm) == 0: # amount is base, so we sell | ||
tosell = amount * Amount("%s %s" % (vshare, comm)) | ||
tosellval = get_usd_value(tosell) | ||
# print "sell {0} out of {1} on {2} ({3:0.2f}% worth ${4:0.2f})".format(tosell, amount, market, | ||
# vshare * 100, | ||
# tosellval.to_double()) | ||
callback('ask', tosell, vshares[market]['ticker'], session) | ||
if market.find(comm) >= 3: # amount is quote, so we buy | ||
base = market.split("_")[1] | ||
tobuy = Amount("%s %s" % (amount, base)) * Amount("%s %s" % (vshare, base)) | ||
tobuyval = get_usd_value(tobuy) | ||
# print "spend {0} out of {1} on {2} ({3:0.2f}% worth ${4:0.2f})".format(tobuy, amount, market, | ||
# vshare * 100, | ||
# tobuyval.to_double()) | ||
callback('bid', tobuy, vshares[market]['ticker'], session) | ||
|
||
|
||
if __name__ == "__main__": | ||
from trade_manager import ses, EXCHANGES, ses, ses | ||
|
||
for exch in get_running_workers(EXCHANGES, red=red): | ||
mm(exch, fib_fan, ses) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[db] | ||
SA_ENGINE_URI: postgresql://postgres@trading | ||
|
||
[log] | ||
LOGFILE: | ||
LOGLEVEL: INFO | ||
|
||
[helper] | ||
KEY: pubkey | ||
SECRET: secret | ||
active_markets: ["BTC_USD", "DASH_BTC"] | ||
userpubkey: 1asdfasdfasdf | ||
|
||
[poloniex] | ||
KEY: key | ||
SECRET: secret | ||
active_markets: ["BTC_USD", "DASH_BTC", "DASH_USD", "ETH_BTC", "ETH_USD", "LTC_BTC", "LTC_USD", "LSK_BTC", "FCT_BTC", "LBC_BTC", "ETC_BTC", "ETC_USD", "OMNI_BTC"] | ||
|
||
[bitfinex] | ||
KEY: key | ||
SECRET: secret | ||
active_markets: ["BTC_USD", "ETH_USD", "ETH_BTC", "LTC_BTC", "LTC_USD", "BFX_USD", "BFX_BTC", "ETC_BTC", "ETC_USD"] | ||
|
||
[kraken] | ||
KEY: key | ||
SECRET: secret | ||
active_markets: ["BTC_USD", "ETH_USD", "ETH_BTC", "ETC_BTC", "ETC_USD"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
[unix_http_server] | ||
file = /tmp/supervisor_tm.sock | ||
|
||
[supervisorctl] | ||
serverurl = unix:///tmp/supervisor_tm.sock | ||
|
||
[rpcinterface:supervisor] | ||
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface | ||
|
||
[supervisord] | ||
logfile = /var/log/trademanager/supervisord.log | ||
childlogdir = /var/log/trademanager/ | ||
pidfile = /var/run/trademanager/supervisord.pid | ||
loglevel = debug | ||
|
||
[group:bitfinex] | ||
programs=bitfinexm,bitfinexl | ||
|
||
[program:bitfinexm] | ||
command=bitfinexm | ||
autorestart=true | ||
stopasgroup=true | ||
autostart=false | ||
|
||
[program:bitfinexl] | ||
command=bitfinexl | ||
autorestart=true | ||
stopasgroup=true | ||
autostart=false | ||
|
||
[program:kraken] | ||
command=krakenm | ||
autorestart=true | ||
stopasgroup=true | ||
autostart=false | ||
|
||
[group:poloniex] | ||
programs=poloniexm,poloniexl | ||
|
||
[program:poloniexm] | ||
command=poloniexm | ||
autorestart=true | ||
stopasgroup=true | ||
autostart=false | ||
|
||
[program:poloniexl] | ||
command=poloniexl | ||
autorestart=true | ||
stopasgroup=true | ||
autostart=false | ||
|
||
[eventlistener:trade_listener] | ||
command=tapplistener | ||
events=PROCESS_STATE | ||
buffer_size=100 |
Oops, something went wrong.