-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
223 additions
and
7 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
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,3 @@ | ||
__all__ = ['bot'] | ||
|
||
from .bot import Bot |
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,21 @@ | ||
from grapheneexchange import GrapheneExchange | ||
|
||
|
||
class Bot(): | ||
|
||
def __init__(self, config, **kwargs): | ||
|
||
self.config = config | ||
self.dex = GrapheneExchange(config, safe_mode=True) | ||
|
||
# Initialize all bots | ||
self.bots = {} | ||
for name in config.bots: | ||
self.bots[name] = config.bots[name]["bot"](config=self.config, | ||
name=name, | ||
dex=self.dex) | ||
self.bots[name].init() | ||
|
||
def execute(self): | ||
for name in self.bots: | ||
self.bots[name].cancel_mine() |
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,72 @@ | ||
from grapheneexchange import GrapheneExchange | ||
import json | ||
|
||
|
||
class BaseStrategy(): | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.state = None | ||
|
||
for arg in args : | ||
if isinstance(arg, GrapheneExchange): | ||
self.dex = arg | ||
for key in kwargs: | ||
setattr(self, key, kwargs[key]) | ||
|
||
if "name" not in kwargs: | ||
raise ValueError("Missing parameter 'name'!") | ||
self.filename = "data_%s.json" % self.name | ||
|
||
self.settings = self.config.bots[self.name] | ||
self.orders = [] | ||
|
||
def init(self) : | ||
print("Initializing %s" % self.name) | ||
|
||
def tick(self) : | ||
pass | ||
|
||
def cancel_all(self) : | ||
orders = self.dex.returnOpenOrders() | ||
for m in orders: | ||
for order in orders[m]: | ||
self.dex.cancel(order["orderNumber"]) | ||
|
||
def cancel_mine(self) : | ||
myOrders = [] | ||
for i, d in enumerate(self.orders): | ||
o = {} | ||
o["for_sale"] = d["amount_to_sell"] | ||
myOrders.append(o) | ||
|
||
orders = self.dex.returnOpenOrders() | ||
for m in orders: | ||
for order in orders[m]: | ||
for stored_order in myOrders: | ||
print("==========") | ||
print(stored_order["for_sale"]) | ||
print(order["amount_to_sell"]) | ||
# #self.dex.cancel(order["orderNumber"]) | ||
|
||
def save_orders(self, orders): | ||
for o in orders["operations"] : | ||
self.orders.append(o[1]) | ||
|
||
def place(self) : | ||
pass | ||
|
||
def getState(self): | ||
return self.state | ||
|
||
def setState(self, state): | ||
self.state = state | ||
|
||
def store(self): | ||
state = self.state() | ||
with open(self.filename, 'w') as fp: | ||
json.dump(state, fp) | ||
|
||
def restore(self): | ||
with open(self.filename, 'r') as fp: | ||
state = json.load(fp) | ||
self.setState(state) |
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,44 @@ | ||
from .basestrategy import BaseStrategy | ||
|
||
""" | ||
""" | ||
|
||
|
||
class BridgeMaker(BaseStrategy): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
def place(self) : | ||
print("Placing Orders") | ||
buy_price = 1 - self.settings["spread_percentage"] / 200 | ||
sell_price = 1 + self.settings["spread_percentage"] / 200 | ||
|
||
#: Amount of Funds available for trading (per asset) | ||
balances = self.dex.returnBalances() | ||
asset_ids = [] | ||
amounts = {} | ||
for market in self.config.watch_markets : | ||
quote, base = market.split(self.config.market_separator) | ||
asset_ids.append(base) | ||
asset_ids.append(quote) | ||
assets_unique = list(set(asset_ids)) | ||
for a in assets_unique: | ||
if a in balances : | ||
amounts[a] = balances[a] * self.settings["volume_percentage"] / 100 / asset_ids.count(a) | ||
|
||
print("Placing Orders:") | ||
orders = [] | ||
for m in self.config.watch_markets: | ||
quote, base = m.split(self.config.market_separator) | ||
if quote in amounts : | ||
print(" - Selling %f %s for %s @%f" % (amounts[quote], quote, base, sell_price)) | ||
tx = self.dex.sell(m, sell_price, amounts[quote]) | ||
self.add_order(tx) | ||
elif base in amounts : | ||
print(" - Buying %f %s with %s @%f" % (amounts[base], base, quote, buy_price)) | ||
tx = self.dex.buy(m, buy_price, amounts[base] * buy_price) | ||
self.add_order(tx) | ||
else: | ||
continue | ||
self.update_orders() |
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,39 @@ | ||
from bot.strategies.bridgemaker import BridgeMaker | ||
from bot import Bot | ||
|
||
|
||
class Config(): | ||
wallet_host = "localhost" | ||
wallet_port = 8092 | ||
wallet_user = "" | ||
wallet_password = "" | ||
witness_url = "ws://10.0.0.16:8090/" | ||
witness_user = "" | ||
witness_password = "" | ||
watch_markets = ["BTC : TRADE.BTC", | ||
"BTC : OPENBTC", | ||
"OPENBTC : TRADE.BTC", | ||
"OPENDASH : TRADE.DASH", | ||
"OPENDOGE : TRADE.DOGE", | ||
"OPENLTC : TRADE.LTC", | ||
"OPENMUSE : TRADE.MUSE", | ||
"OPENNBT : TRADE.NBT", | ||
"OPENPPC : TRADE.PPC", | ||
"OPENUSD : USD", | ||
] | ||
market_separator = " : " | ||
|
||
bots = {} | ||
bots["BridgeMaker"] = {"bot" : BridgeMaker, | ||
"markets" : ["BTC : TRADE.BTC", | ||
"BTC : OPENBTC"], | ||
"spread_percentage" : 5, | ||
"volume_percentage" : 50, | ||
} | ||
account = "btc-bridge-maker" | ||
|
||
if __name__ == '__main__': | ||
bot = Bot(Config) | ||
bot.bots["BridgeMaker"].save_orders({'ref_block_num': 4383, 'expiration': '2016-01-13T13:47:57', 'extensions': [], 'signatures': ['1f53fd4e4717218ac0ef47c6fa144b48378a7ad234e89cb97aed514f16acc042d631458748aee5a5ed86467b0580661c614769fd75207831285dab56d4130aa58f'], 'operations': [[1, {'extensions': [], 'seller': '1.2.100237', 'fill_or_kill': False, 'fee': {'amount': 1000000, 'asset_id': '1.3.0'}, 'min_to_receive': {'amount': 58479, 'asset_id': '1.3.103'}, 'expiration': '2016-01-20T13:47:29', 'amount_to_sell': {'amount': 57017, 'asset_id': '1.3.569'}}]], 'ref_block_prefix': 3665477119}) | ||
bot.bots["BridgeMaker"].save_orders({'ref_block_num': 4383, 'expiration': '2016-01-13T13:47:57', 'extensions': [], 'signatures': ['20285813f0fcab111a7d790d0ec2ad44add31dc9510a593248bd84e8b3abe347295cc51f7c8cb1851933b5229c3e8ef5eaadb3eb1101a52f028c70bf7c082595d4'], 'operations': [[1, {'extensions': [], 'seller': '1.2.100237', 'fill_or_kill': False, 'fee': {'amount': 1000000, 'asset_id': '1.3.0'}, 'min_to_receive': {'amount': 61478, 'asset_id': '1.3.350'}, 'expiration': '2016-01-20T13:47:29', 'amount_to_sell': {'amount': 59979, 'asset_id': '1.3.569'}}]], 'ref_block_prefix': 3665477119}) | ||
bot.execute() |