From 08bac4c332b23d89c52e1d3b19f06de2eb2ac406 Mon Sep 17 00:00:00 2001 From: clay richardson Date: Sat, 6 May 2017 22:35:02 -0700 Subject: [PATCH 1/2] Adding "seq" kwargs to events, this fixes #4 From: https://poloniex.com/support/api/ """ The dictionary portion of each market message ("kwargs" in the Node.js example) will contain a sequence number with the key "seq". In order to keep your order book consistent, you will need to ensure that messages are applied in the order of their sequence numbers, even if they arrive out of order. In some markets, if there is no update for more than 1 second, a heartbeat message consisting of an empty argument list and the latest sequence number will be sent. These will go out once per second, but if there is no update for more than 60 seconds, the heartbeat interval will be reduced to 8 seconds until the next update. Several order book and trade history updates will often arrive in a single message. Be sure to loop through the entire array, otherwise you will miss some updates. """ --- poloniex/api/async.py | 5 +++-- poloniex/wamp/client.py | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/poloniex/api/async.py b/poloniex/api/async.py index 50110b6..0134f98 100644 --- a/poloniex/api/async.py +++ b/poloniex/api/async.py @@ -47,9 +47,10 @@ async def decorator(data): def trades_wrapper(topic, handler): - async def decorator(data): - for event in data: + async def decorator(event_args, event_kwargs): + for event in event_args: event["currency_pair"] = topic + event.update(event_kwargs) if inspect.isgeneratorfunction(handler): await handler(**event) diff --git a/poloniex/wamp/client.py b/poloniex/wamp/client.py index f9d517f..b78d261 100644 --- a/poloniex/wamp/client.py +++ b/poloniex/wamp/client.py @@ -62,7 +62,10 @@ async def _on_event(self, event): subscription = self.subscriptions[subscription_id] handler = subscription['handler'] - await handler(event.args) + if event.kwargs is not None: + await handler(event.args, event.kwargs) + else: + await handler(event.args) async def _on_subscribed(self, msg): request_id = msg.request From 944a79504553475daf72b43430e1909e2fd1b0ba Mon Sep 17 00:00:00 2001 From: clay richardson Date: Sun, 7 May 2017 00:18:38 -0700 Subject: [PATCH 2/2] Updated CURRENCY_PAIRS constant from poloniex javascript Pulled from var currencyPairArray on https://poloniex.com/exchange Current as of Sun May 7 07:11:23 UTC 2017 --- poloniex/constants.py | 107 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 93 insertions(+), 14 deletions(-) diff --git a/poloniex/constants.py b/poloniex/constants.py index 94ef35e..5200892 100644 --- a/poloniex/constants.py +++ b/poloniex/constants.py @@ -1,21 +1,100 @@ __author__ = 'andrey.samokhvalov21@yandex.ru' CHART_DATA_PERIODS = [300, 900, 1800, 7200, 14400, 86400] + +# Pulled from var currencyPairArray on https://poloniex.com/exchange +# Current as of Sun May 7 07:11:23 UTC 2017 CURRENCY_PAIRS = [ - 'BTC_HUC', 'BTC_CNMT', 'BTC_UNITY', 'BTC_BITS', 'BTC_SWARM', 'BTC_NXT', 'BTC_GMC', 'BTC_BITCNY', 'BTC_BLOCK', - 'XMR_LTC', 'BTC_EMC2', 'BTC_POT', 'BTC_DOGE', 'BTC_RIC', 'BTC_XCR', 'BTC_SC', 'BTC_RDD', 'BTC_PIGGY', 'BTC_EXP', - 'BTC_XPM', 'USDT_ETH', 'BTC_SYNC', 'BTC_XPB', 'BTC_PPC', 'BTC_XCH', 'BTC_ABY', 'BTC_MINT', 'USDT_DASH', 'BTC_XRP', - 'BTC_DIEM', 'XMR_DSH', 'BTC_XEM', 'USDT_XMR', 'BTC_VTC', 'BTC_XDP', 'BTC_STR', 'BTC_GRS', 'BTC_DGB', 'BTC_FLT', - 'BTC_XC', 'BTC_HZ', 'BTC_CLAM', 'USDT_XRP', 'BTC_XBC', 'XMR_HYP', 'BTC_NOTE', 'BTC_INDEX', 'BTC_MMNXT', 'BTC_NAUT', - 'USDT_LTC', 'BTC_SYS', 'USDT_STR', 'BTC_FLO', 'BTC_MYR', 'XMR_BTCD', 'BTC_BBR', 'XMR_BLK', 'BTC_RBY', 'BTC_LTBC', - 'BTC_MAID', 'BTC_1CR', 'BTC_BTM', 'BTC_GEMZ', 'BTC_NOXT', 'BTC_FCT', 'BTC_OMNI', 'BTC_FLDC', 'BTC_VRC', 'XMR_DASH', - 'BTC_XUSD', 'BTC_MMC', 'BTC_BTS', 'BTC_PTS', 'BTC_EXE', 'BTC_IOC', 'BTC_SDC', 'BTC_QORA', 'XMR_MNTA', 'BTC_XMG', - 'BTC_C2', 'XMR_XDN', 'BTC_BELA', 'BTC_BITUSD', 'XMR_NXT', 'BTC_BURST', 'BTC_MRS', 'USDT_BTC', 'BTC_BCN', 'BTC_XMR', - 'BTC_GRC', 'BTC_CURE', 'BTC_NEOS', 'BTC_BTCD', 'BTC_QBK', 'BTC_NOBL', 'BTC_MCN', 'XMR_BBR', 'BTC_XCN', 'BTC_NBT', - 'BTC_XDN', 'BTC_YACC', 'BTC_QTL', 'BTC_LQD', 'BTC_NAV', 'BTC_NMC', 'BTC_NSR', 'BTC_MIL', 'BTC_FIBRE', 'BTC_WDC', - 'BTC_ADN', 'BTC_ARCH', 'BTC_VIA', 'XMR_BCN', 'XMR_DIEM', 'BTC_GEO', 'BTC_XCP', 'BTC_BLK', 'BTC_ETH', 'BTC_DASH', - 'XMR_IFC', 'BTC_XST', 'BTC_SILK', 'XMR_QORA', 'BTC_BCY', 'BTC_VNL', 'XMR_MAID', 'USDT_NXT', 'BTC_CGA', 'BTC_PINK', - 'BTC_SJCX', 'BTC_LTC', 'BTC_GAP', 'BTC_HYP', 'BTC_DAO', 'BTC_LSK' + "BTC_AMP", + "BTC_ARDR", + "BTC_BCN", + "BTC_BCY", + "BTC_BELA", + "BTC_BLK", + "BTC_BTCD", + "BTC_BTM", + "BTC_BTS", + "BTC_BURST", + "BTC_CLAM", + "BTC_DASH", + "BTC_DCR", + "BTC_DGB", + "BTC_DOGE", + "BTC_EMC2", + "BTC_ETC", + "BTC_ETH", + "BTC_EXP", + "BTC_FCT", + "BTC_FLDC", + "BTC_FLO", + "BTC_GAME", + "BTC_GNO", + "BTC_GNT", + "BTC_GRC", + "BTC_HUC", + "BTC_LBC", + "BTC_LSK", + "BTC_LTC", + "BTC_MAID", + "BTC_NAUT", + "BTC_NAV", + "BTC_NEOS", + "BTC_NMC", + "BTC_NOTE", + "BTC_NXC", + "BTC_NXT", + "BTC_OMNI", + "BTC_PASC", + "BTC_PINK", + "BTC_POT", + "BTC_PPC", + "BTC_RADS", + "BTC_REP", + "BTC_RIC", + "BTC_SBD", + "BTC_SC", + "BTC_SJCX", + "BTC_STEEM", + "BTC_STR", + "BTC_STRAT", + "BTC_SYS", + "BTC_VIA", + "BTC_VRC", + "BTC_VTC", + "BTC_XBC", + "BTC_XCP", + "BTC_XEM", + "BTC_XMR", + "BTC_XPM", + "BTC_XRP", + "BTC_XVC", + "BTC_ZEC", + "ETH_ETC", + "ETH_GNO", + "ETH_GNT", + "ETH_LSK", + "ETH_REP", + "ETH_STEEM", + "ETH_ZEC", + "USDT_BTC", + "USDT_DASH", + "USDT_ETC", + "USDT_ETH", + "USDT_LTC", + "USDT_NXT", + "USDT_REP", + "USDT_STR", + "USDT_XMR", + "USDT_XRP", + "USDT_ZEC", + "XMR_BCN", + "XMR_BLK", + "XMR_BTCD", + "XMR_DASH", + "XMR_LTC", + "XMR_MAID", + "XMR_NXT", + "XMR_ZEC" ] AVAILABLE_SUBSCRIPTIONS = CURRENCY_PAIRS[:]