Skip to content

Commit

Permalink
[API] Fixed Markets and callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Jan 5, 2016
1 parent 1ba89b2 commit 3c7b2ca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
18 changes: 11 additions & 7 deletions grapheneapi/grapheneclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,8 @@ def __init__(self, config):
self.market_separator = config.market_separator
else:
self.market_separator = ":"
if ("watch_markets" in available_features and
"onMarketUpdate" in available_features):
self.markets = []
if ("watch_markets" in available_features):
self.markets = {}
for market in config.watch_markets:
[quote_symbol, base_symbol] = market.split(self.market_separator)
try:
Expand All @@ -379,10 +378,15 @@ def __init__(self, config):
raise Exception("Couldn't load assets for market %s"
% market)
if "id" in quote and "id" in base:
self.markets.append({"name" : market,
"quote" : quote["id"],
"base" : base["id"],
"callback": config.onMarketUpdate})
if "onMarketUpdate" in available_features:
self.markets.update({
market : {"quote" : quote["id"],
"base" : base["id"],
"callback": config.onMarketUpdate}})
else: # No callbacks
self.markets.update({
market : {"quote" : quote["id"],
"base" : base["id"]}})
else:
log.warn("Market assets could not be found: %s"
% market)
Expand Down
4 changes: 2 additions & 2 deletions grapheneapi/graphenews.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def __init__(self, url, username, password,
self.host = host
self.port = port
self.proto = proto
self.proto.username = self.username
self.proto.password = self.password
self.proto.username = username
self.proto.password = password
self.factory = None

def setObjectCallbacks(self, callbacks) :
Expand Down
7 changes: 5 additions & 2 deletions grapheneapi/graphenewsprotocol.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from functools import partial

try:
from autobahn.asyncio.websocket import WebSocketClientProtocol
except ImportError:
Expand Down Expand Up @@ -120,7 +121,8 @@ def subscribe_to_accounts(self, account_ids, *args):
def subscribe_to_markets(self, dummy=None):
""" Subscribe to the markets as defined in ``self.markets``.
"""
for market in self.markets:
for m in self.markets:
market = self.markets[m]
self.request_id += 1
self.wsexec([0, "subscribe_to_market",
[self.request_id,
Expand Down Expand Up @@ -197,7 +199,8 @@ def dispatchNotice(self, notice):

" Market notifications "
if inst == "1" and _type == "7":
for market in self.markets:
for m in self.markets:
market = self.markets[m]
if(((market["quote"] == notice["sell_price"]["quote"]["asset_id"] and
market["base"] == notice["sell_price"]["base"]["asset_id"]) or
(market["base"] == notice["sell_price"]["quote"]["asset_id"] and
Expand Down

0 comments on commit 3c7b2ca

Please sign in to comment.