def init(conf, **kwargs): """ Initialize the Bot Infrastructure and setup connection to the network """ global dex, bots, config botProtocol = BotProtocol # Take the configuration variables and put them in the current # instance of BotProtocol. This step is required to let # GrapheneExchange know most of our variables as well! # We will also be able to hook into websocket messages from # within the configuration file! [ setattr(botProtocol, key, conf.__dict__[key]) for key in conf.__dict__.keys() ] # Additionally store the whole configuration config = conf # Connect to the DEX dex = GrapheneExchange(botProtocol, safe_mode=config.safe_mode) if dex.rpc.is_locked(): raise Exception("Your wallet is LOCKED! Please unlock it manually!") # Initialize all bots for index, name in enumerate(config.bots, 1): botClass = config.bots[name]["bot"] bots[name] = botClass(config=config, name=name, dex=dex, index=index) # Maybe the strategy/bot has some additional customized # initialized besides the basestrategy's __init__() bots[name].init()
def __init__(self, config): class Config(): pass for client in config: if (client['client'] == 'bts') or (client['client'] == 'trans.bot') or (client['client'] == 'alpha-go'): btsConfig = Config() #btsConfig.witness_url = client['WITNESS_URL'] btsConfig.witness_url = 'wss://ws.gdex.top' #btsConfig.witness_url = 'wss://bit.btsabc.org/ws' #btsConfig.witness_url = 'wss://bts.transwiser.com/ws' btsConfig.witnes_user = "" btsConfig.witness_password = "" #btsConfig.watch_markets = ["USD_OPEN.ETH", "OPEN.ETH_USD", "CNY_OPEN.ETH","OPEN.ETH_CNY","USD_OPEN.BTC","OPEN.BTC_USD", "CNY_OPEN.BTC","OPEN.BTC_CNY","CNY_BTS", "BTS_CNY","EUR_BTS", "BTS_EUR", "USD_BTS", "BTS_USD", "EUR_USD", "USD_EUR","EUR_CNY", "CNY_EUR","USD_CNY", "CNY_USD", "USD_OPEN.USDT", "OPEN.USDT_USD"] btsConfig.watch_markets = [ "GDEX.BTC_GDEX.HPB", "GDEX.HPB_GDEX.BTC", "USD_GDEX.EOS", "GDEX.EOS_USD", "CNY_GDEX.EOS", "GDEX.EOS_CNY", "USD_GDEX.ETH", "GDEX.ETH_USD", "CNY_GDEX.ETH", "GDEX.ETH_CNY", "USD_GDEX.BTC", "GDEX.BTC_USD", "CNY_GDEX.BTC", "GDEX.BTC_CNY", "BTS_GDEX.BTC", "GDEX.BTC_BTS", "USD_GDEX.EOS", "GDEX.EOS_USD", "CNY_GDEX.EOS", "GDEX.EOS_CNY", "USD_GDEX.ETH", "GDEX.ETH_USD", "CNY_GDEX.ETH", "GDEX.ETH_CNY" ] btsConfig.market_separator = "_" btsConfig.account = client['ACCOUNT'] btsConfig.wif = client['SECRET_KEY'] if client['client'] == 'bts': self.btsConfig = btsConfig self.btsClient = GrapheneExchange(self.btsConfig, safe_mode=False) if client['client'] == 'trans.bot': self.botConfig = btsConfig self.botClient = GrapheneExchange(self.botConfig, safe_mode=False) if client['client'] == 'alpha-go': self.goConfig = btsConfig self.goClient = GrapheneExchange(self.goConfig, safe_mode=False)
def __init__(self, *args, **kwargs) : super().__init__(*args, **kwargs) conn = GrapheneRawTemplate markets = [] for base in self.bases: for quote in self.quotes: if quote == base: continue markets.append("%s:%s" % (quote, base)) conn.watch_markets = markets if (not hasattr(self, "wallet_host") or not hasattr(self, "wallet_port") or not hasattr(self, "witness_url")): raise Exception("BitShares FeedSource requires 'wallet_host', 'wallet_port' and witness_url'!") setattr(conn, "wallet_host", self.wallet_host) setattr(conn, "wallet_port", self.wallet_port) setattr(conn, "witness_url", self.witness_url) setattr(conn, "account", config.producer_name) self.dex = GrapheneExchange(conn, safe_mode=False)
def init(conf, **kwargs): """ Initialize the Bot Infrastructure and setup connection to the network """ global dex, bots, config config = BotProtocol # Take the configuration variables and put them in the current # instance of BotProtocol. This step is required to let # GrapheneExchange know most of our variables as well! # We will also be able to hook into websocket messages from # within the configuration file! [setattr(config, key, conf[key]) for key in conf.keys()] if not hasattr(config, "prefix") or not config.prefix: log.debug("Setting default network (BTS)") config.prefix = "BTS" # Construct watch_markets attribute from all bots: watch_markets = set() for name in config.bots: watch_markets = watch_markets.union(config.bots[name].get( "markets", [])) setattr(config, "watch_markets", watch_markets) # Construct watch_assets attribute from all bots: watch_assets = set() for name in config.bots: watch_assets = watch_assets.union(config.bots[name].get("assets", [])) setattr(config, "watch_assets", watch_assets) # Connect to the DEX dex = GrapheneExchange(config, safe_mode=config.safe_mode, prefix=config.prefix) # Initialize all bots for index, name in enumerate(config.bots, 1): log.debug("Initializing bot %s" % name) if "module" not in config.bots[name]: raise ValueError("No 'module' defined for bot %s" % name) klass = getattr(importlib.import_module(config.bots[name]["module"]), config.bots[name]["bot"]) bots[name] = klass(config=config, name=name, dex=dex, index=index) # Maybe the strategy/bot has some additional customized # initialized besides the basestrategy's __init__() log.debug("Calling %s.init()" % name) bots[name].loadMarket(notify=False) bots[name].init() bots[name].store()
def __init__(self, witness_url, account, secret_key, watch_markets=None): if watch_markets is None: watch_markets = ["CNY_BTS", "BTS_CNY"] class Config: pass _bts_config = Config() _bts_config.witness_url = witness_url _bts_config.witness_user = "" _bts_config.witness_password = "" _bts_config.watch_markets = watch_markets _bts_config.market_separator = "_" _bts_config.account = account _bts_config.wif = secret_key self.exchange = GrapheneExchange(_bts_config, safe_mode=False)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) conn = GrapheneRawTemplate markets = [] for base in self.bases: for quote in self.quotes: if quote == base: continue markets.append("%s:%s" % (quote, base)) conn.watch_markets = markets if not hasattr(self, "wallet_host") or not hasattr(self, "wallet_port") or not hasattr(self, "witness_url"): raise Exception("BitShares FeedSource requires 'wallet_host', 'wallet_port' and witness_url'!") setattr(conn, "wallet_host", self.wallet_host) setattr(conn, "wallet_port", self.wallet_port) setattr(conn, "witness_url", self.witness_url) setattr(conn, "account", config.producer_name) self.dex = GrapheneExchange(conn, safe_mode=False)
class Graphene(FeedSource): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) conn = GrapheneRawTemplate markets = [] for base in self.bases: for quote in self.quotes: if quote == base: continue markets.append("%s:%s" % (quote, base)) conn.watch_markets = markets if (not hasattr(self, "wallet_host") or not hasattr(self, "wallet_port") or not hasattr(self, "witness_url")): raise Exception( "BitShares FeedSource requires 'wallet_host', 'wallet_port' and witness_url'!" ) setattr(conn, "wallet_host", self.wallet_host) setattr(conn, "wallet_port", self.wallet_port) setattr(conn, "witness_url", self.witness_url) setattr(conn, "account", config.producer_name) self.dex = GrapheneExchange(conn, safe_mode=False) def _fetch(self): feed = {} try: ticker = self.dex.returnTicker() for market in ticker: quote, base = market.split(":") if hasattr(self, "quoteNames") and quote in self.quoteNames: quote = self.quoteNames[quote] feed[base] = {} if (float(ticker[market]["last"])) > 0 and float( ticker[market]["quoteVolume"]) > 0: feed[base][quote] = { "price": (float(ticker[market]["last"])), "volume": (float(ticker[market]["quoteVolume"]) * self.scaleVolumeBy) } feed[base]["response"] = ticker[market] except Exception as e: raise Exception("\nError fetching results from {1}! ({0})".format( str(e), type(self).__name__)) return feed
class Graphene(FeedSource): def __init__(self, *args, **kwargs) : super().__init__(*args, **kwargs) conn = GrapheneRawTemplate markets = [] for base in self.bases: for quote in self.quotes: if quote == base: continue markets.append("%s:%s" % (quote, base)) conn.watch_markets = markets if (not hasattr(self, "wallet_host") or not hasattr(self, "wallet_port") or not hasattr(self, "witness_url")): raise Exception("BitShares FeedSource requires 'wallet_host', 'wallet_port' and witness_url'!") setattr(conn, "wallet_host", self.wallet_host) setattr(conn, "wallet_port", self.wallet_port) setattr(conn, "witness_url", self.witness_url) setattr(conn, "account", config.producer_name) self.dex = GrapheneExchange(conn, safe_mode=False) def fetch(self): feed = {} try : ticker = self.dex.returnTicker() for market in ticker: quote, base = market.split(":") if hasattr(self, "quoteNames") and quote in self.quoteNames: quote = self.quoteNames[quote] feed[base] = {} if (float(ticker[market]["last"])) > 0 and float(ticker[market]["quoteVolume"]) > 0: feed[base][quote] = {"price" : (float(ticker[market]["last"])), "volume" : (float(ticker[market]["quoteVolume"]) * self.scaleVolumeBy)} feed[base]["response"] = ticker[market] except Exception as e: print("\nError fetching results from {1}! ({0})".format(str(e), type(self).__name__)) if not self.allowFailure: sys.exit("\nExiting due to exchange importance!") return return feed
def __init__(self): f = open("config.json", 'r') config = json.loads(f.read()) f.close() for client in config: if client['client'] == 'bts': class Config(): pass btsConfig = Config() btsConfig.witness_url = client['WITNESS_URL'] btsConfig.witnes_user = "" btsConfig.witness_password = "" btsConfig.watch_markets = ["CNY_BTS", "BTS_CNY"] btsConfig.market_separator = "_" btsConfig.account = client['ACCOUNT'] btsConfig.wif = client['SECRET_KEY'] self.btsConfig = btsConfig self.btsClient = GrapheneExchange(btsConfig, safe_mode=False) if client['client'] == 'yunbi': self.yunbiClient = yunbi.client.Client(client['ACCESS_KEY'], client['SECRET_KEY']) if client['client'] == 'btc38': self.btc38Client = btc38.client.Client(client['ACCESS_KEY'], client['SECRET_KEY'], client['ACCOUNT_ID']) if client['client'] == 'mysql': self.mysqlClient = pymysql.connect(host=client['host'], user=client['user'], password=client['password'], database=client['database'])
witness_url = "wss://bitshares.openledger.info/ws" watch_markets = ["USD:BTS", "EUR:BTS", "GOLD:BTS", "SILVER:BTS", "CNY:BTS", "BTC:BTS", ] market_separator = ":" account = "committee-trade" proposer = "xeroc" if __name__ == '__main__': config = Config dex = GrapheneExchange(config, safe_mode=False) graphene = dex.rpc # Get current fees core_asset = graphene.get_asset("1.3.0") committee_account = dex.rpc.get_account("committee-trade") proposals = dex.ws.get_proposed_transactions(committee_account["id"]) r = dex.returnTicker() for proposal in proposals: print("Proposal: %s" % proposal["id"]) prop_op = proposal["proposed_transaction"]["operations"] if len(prop_op) > 1 :
witness_url = "wss://bitshares.openledger.info/ws/" # witness_url = "ws://10.0.0.16:8090/" # witness_url = "ws://testnet.bitshares.eu/ws" witness_user = "" witness_password = "" watch_markets = [ "USD_BTS", "CNY_BTS", "GOLD_BTS", "SILVER_BTS", "EUR_BTS", "BTC_BTS" ] # watch_markets = ["PEG.RANDOM_TEST"] market_separator = "_" account = "xeroc" if __name__ == '__main__': dex = GrapheneExchange(Config, safe_mode=True) ticker = dex.returnTicker() for a in ticker: quote, base = a.split(Config.market_separator) premium = math.fabs( (ticker[a]["last"] / ticker[a]["settlement_price"] - 1) * 100) premium_bid = ( (ticker[a]["highestBid"] / ticker[a]["settlement_price"] - 1) * 100) premium_ask = ( (ticker[a]["lowestAsk"] / ticker[a]["settlement_price"] - 1) * 100) premium = math.fabs( (ticker[a]["last"] / ticker[a]["settlement_price"] - 1) * 100) price_mid = (ticker[a]["highestBid"] + ticker[a]["lowestAsk"]) / 2.0 spread = math.fabs(ticker[a]["highestBid"] - ticker[a]["lowestAsk"]) cer_premium = (ticker[a]["settlement_price"] /
watch_markets = [ "USD:BTS", "EUR:BTS", "GOLD:BTS", "SILVER:BTS", "CNY:BTS", "BTC:BTS", ] market_separator = ":" account = "committee-trade" proposer = "xeroc" if __name__ == "__main__": config = Config dex = GrapheneExchange(config, safe_mode=False) graphene = dex.rpc # Get current fees core_asset = graphene.get_asset("1.3.0") committee_account = dex.rpc.get_account("committee-trade") proposals = dex.ws.get_proposed_transactions(committee_account["id"]) r = dex.returnTicker() for proposal in proposals: print("Proposal: %s" % proposal["id"]) prop_op = proposal["proposed_transaction"]["operations"] for op in prop_op:
def connect_client(config): return GrapheneExchange(config, safe_mode=False)
from grapheneexchange import GrapheneExchange from pprint import pprint import config if __name__ == "__main__": dex = GrapheneExchange(config, safe_mode=False, propose_only=True) r = dex.returnTicker() balances = dex.returnBalances() for m in config.watch_markets: quote, base = m.split(config.market_separator) if quote == "BTS": continue settlement_price = r[m]["settlement_price"] highestBid = r[m]["highestBid"] print("Settlement %7s: %12.3f" % (quote, r[m]["settlement_price"])) print("Highest Bid %7s: %12.3f" % (quote, r[m]["highestBid"])) if quote in config.amount_premium: for a in config.amount_premium[quote]: sell_price = settlement_price * (1 + a["premium"] / 100) amount = balances[quote] * a["volume_percentage"] / 100 # do not sell below the highest bid! if sell_price < highestBid: print( "Highest bid is higher than sell price! Changing sell price" ) sell_price = highestBid premium = (sell_price / settlement_price - 1) * 100
from grapheneexchange import GrapheneExchange from pprint import pprint class config(): wallet_host = "localhost" wallet_port = 8092 witness_url = "wss://bitshares.openledger.info/ws" watch_markets = ["BTS:USD"] # market: quote:base .. trade:quote .. price: base/quote market_separator = ":" account = "live-coding" dex = GrapheneExchange(config, safe_mode=False, propose_only=False) pprint(dex.returnTicker()) # pprint(dex.returnBalances()) # pprint(dex.returnTradeHistory(limit=5)) # lowestAsk = dex.returnTicker()["USD:BTS"]["lowestAsk"] # pprint(dex.buy("USD:BTS", lowestAsk*0.99, 1)) # pprint(dex.sell("USD:BTS", lowestAsk*1.10, 1)) ## FIXME ## pprint(dex.returnOpenOrders()) # pprint(dex.cancel("1.7.189477")) #pprint(dex.borrow(10, "USD", 3.0))
from grapheneexchange import GrapheneExchange from graphenebase.transactions import getOperationNameForId import math import config if __name__ == '__main__': dex = GrapheneExchange(config, safe_mode=False) graphene = dex.rpc # Get current fees core_asset = graphene.get_asset("1.3.0") committee_account = dex.rpc.get_account("committee-account") proposals = dex.ws.get_proposed_transactions(committee_account["id"]) for proposal in proposals: print("Proposal: %s" % proposal["id"]) prop_op = proposal["proposed_transaction"]["operations"] if len(prop_op) > 1 : print(" - [Warning] This proposal has more than 1 operation") for op in prop_op : if op[0] == 31: fees = op[1]["new_parameters"]["current_fees"]["parameters"] scale = int(op[1]["new_parameters"]["current_fees"]["scale"]) / 1e4 # Get ticker/current price ticker = dex.returnTicker()[config.watch_markets[0]]
from grapheneexchange import GrapheneExchange from pprint import pprint import config if __name__ == '__main__': dex = GrapheneExchange(config, safe_mode=False, propose_only=True) r = dex.returnTicker() balances = dex.returnBalances() for m in config.watch_markets: quote, base = m.split(config.market_separator) if quote == "BTS" : continue settlement_price = r[m]["settlement_price"] highestBid = r[m]["highestBid"] print("Settlement %7s: %12.3f" % (quote, r[m]["settlement_price"])) print("Highest Bid %7s: %12.3f" % (quote, r[m]["highestBid"])) if quote in config.amount_premium: for a in config.amount_premium[quote]: sell_price = settlement_price * (1 + a["premium"] / 100) amount = balances[quote] * a["volume_percentage"] / 100 # do not sell below the highest bid! if sell_price < highestBid : print("Highest bid is higher than sell price! Changing sell price") sell_price = highestBid premium = (sell_price / settlement_price - 1) * 100
wallet_host = "localhost" wallet_port = 8090 wallet_user = "" wallet_password = "" witness_url = "ws://localhost:11011" witness_user = "" witness_password = "" watch_markets = ["PEG.LAST:TEST"] market_separator = ":" if __name__ == '__main__': config = Config graphene = GrapheneClient(config) dex = GrapheneExchange(config) asset_symbol = "PEG.LAST" producers = [ "init0", "init1", "init2", "init3", "init4", "init5", "init6", "init7", "init8", "init9", "init10" ] ticker = None try: ticker = dex.returnTicker() except: pass if not ticker or config.watch_markets[0] not in ticker: price = 1.0
class config(): wallet_host = "localhost" wallet_port = 8092 witness_url = "wss://bitshares.openledger.info/ws" watch_markets = [ "BTS:USD" ] # market: quote:base .. trade:quote .. price: base/quote market_separator = ":" account = "live-coding" dex = GrapheneExchange(config, safe_mode=False, propose_only=False) pprint(dex.returnTicker()) # pprint(dex.returnBalances()) # pprint(dex.returnTradeHistory(limit=5)) # lowestAsk = dex.returnTicker()["USD:BTS"]["lowestAsk"] # pprint(dex.buy("USD:BTS", lowestAsk*0.99, 1)) # pprint(dex.sell("USD:BTS", lowestAsk*1.10, 1)) ## FIXME ## pprint(dex.returnOpenOrders()) # pprint(dex.cancel("1.7.189477"))