Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use yapic.json instead of json for 1.5x to 2x performance gain #237

Merged
merged 3 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cryptofeed/backends/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
associated with this software.
'''
import logging
import json
from yapic import json
import itertools

from cryptofeed.backends.http import HTTPCallback
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/backends/kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
associated with this software.
'''
import asyncio
import json
from yapic import json

from aiokafka import AIOKafkaProducer

Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/backends/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
associated with this software.
'''
from datetime import datetime as dt
import json
from yapic import json

import asyncpg

Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/backends/rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json
import asyncio

import aio_pika
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/backends/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json

import aioredis

Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/backends/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'''
import logging
import asyncio
import json
from yapic import json
from textwrap import wrap

from cryptofeed.backends.backend import BackendBookCallback, BackendBookDeltaCallback, BackendFundingCallback, BackendTickerCallback, BackendTradeCallback, BackendOpenInterestCallback
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/backends/zmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json

import zmq
import zmq.asyncio
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json
import logging
from decimal import Decimal
from collections import defaultdict
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/bitcoincom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json
import logging
from decimal import Decimal

Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/bitfinex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json
import logging
from decimal import Decimal
from collections import defaultdict
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/bitmax.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json
import logging
from decimal import Decimal

Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/bitmex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json
import logging
from collections import defaultdict
from decimal import Decimal
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/bitstamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json
import logging
from decimal import Decimal
import asyncio
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/bittrex.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import json
from yapic import json
from decimal import Decimal
import requests
import zlib
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/bybit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
associated with this software.
'''
import logging
import json
from yapic import json
from decimal import Decimal

from sortedcontainers import SortedDict as sd
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/coinbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
associated with this software.
'''
import asyncio
import json
from yapic import json
import logging
from decimal import Decimal
import time
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/deribit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import json
from yapic import json
import requests

from cryptofeed.feed import Feed
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/dsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json
import logging
from decimal import Decimal

Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/exx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json
import logging
from decimal import Decimal

Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/ftx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json
import logging
from decimal import Decimal

Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json
import logging
from decimal import Decimal

Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/hitbtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json
import logging
from decimal import Decimal

Expand Down
4 changes: 2 additions & 2 deletions cryptofeed/exchange/huobi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
associated with this software.
'''
import logging
import json
from yapic import json
from decimal import Decimal
import zlib

Expand Down Expand Up @@ -74,7 +74,7 @@ async def _trade(self, msg: dict, timestamp: float):

async def message_handler(self, msg: str, timestamp: float):
# unzip message
msg = zlib.decompress(msg, 16 + zlib.MAX_WBITS)
msg = zlib.decompress(msg, 16 + zlib.MAX_WBITS).decode(encoding='utf-8', errors='strict')
Copy link
Owner

@bmoscon bmoscon Apr 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vincentmele looks like the library has been updated to do byte parsing, so you should be able to remove this and require the latest version of the library in setup.py

msg = json.loads(msg, parse_float=Decimal)

# Huobi sends a ping evert 5 seconds and will disconnect us if we do not respond to it
Expand Down
4 changes: 2 additions & 2 deletions cryptofeed/exchange/huobi_dm.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

'''
import logging
import json
from yapic import json
from decimal import Decimal
import zlib

Expand Down Expand Up @@ -113,7 +113,7 @@ async def _trade(self, msg: dict, timestamp: float):

async def message_handler(self, msg: str, timestamp: float):
# unzip message
msg = zlib.decompress(msg, 16 + zlib.MAX_WBITS)
msg = zlib.decompress(msg, 16 + zlib.MAX_WBITS).decode(encoding='utf-8', errors='strict')
msg = json.loads(msg, parse_float=Decimal)

# Huobi sends a ping evert 5 seconds and will disconnect us if we do not respond to it
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/kraken.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json
import logging
from decimal import Decimal

Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/kraken_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json
import logging
import requests
from decimal import Decimal
Expand Down
4 changes: 2 additions & 2 deletions cryptofeed/exchange/okcoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json
import logging
from decimal import Decimal
import zlib
Expand Down Expand Up @@ -134,7 +134,7 @@ async def _book(self, msg: dict, timestamp: float):
async def message_handler(self, msg: str, timestamp: float):
# DEFLATE compression, no header
msg = zlib.decompress(msg, -15)
msg = json.loads(msg, parse_float=Decimal)
msg = json.loads(msg, parse_float=Decimal).decode(encoding='utf-8', errors='strict')

if 'event' in msg:
if msg['event'] == 'error':
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/poloniex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Please see the LICENSE file for the terms and conditions
associated with this software.
'''
import json
from yapic import json
import logging
from decimal import Decimal
import time
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/exchange/upbit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import json
from yapic import json
from decimal import Decimal

import requests
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/rest/bitfinex.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'''
import time
from time import sleep
import json
from yapic import json
import hashlib
import hmac
import logging
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/rest/coinbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
associated with this software.
'''
import time
import json
from yapic import json
import hashlib
import hmac
import requests
Expand Down
2 changes: 1 addition & 1 deletion cryptofeed/rest/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import hashlib
import hmac
import requests
import json
from yapic import json
import base64
import logging
from decimal import Decimal
Expand Down
2 changes: 1 addition & 1 deletion docs/exchange.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async def _trade(self, msg):

async def message_handler(self, msg, timestamp):
# unzip message
msg = zlib.decompress(msg, 16+zlib.MAX_WBITS)
msg = zlib.decompress(msg, 16+zlib.MAX_WBITS).decode(encoding='utf-8', errors='strict')
msg = json.loads(msg, parse_float=Decimal)

# Huobi sends a ping evert 5 seconds and will disconnect us if we do not respond to it
Expand Down
2 changes: 1 addition & 1 deletion examples/demo_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'''
import asyncio
from multiprocessing import Process
import json
from yapic import json
from decimal import Decimal

from cryptofeed.backends.socket import TradeSocket, BookDeltaSocket, BookSocket
Expand Down
2 changes: 1 addition & 1 deletion examples/demo_udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'''
from multiprocessing import Process
import socket
import json
from yapic import json

from cryptofeed.backends.socket import TradeSocket, BookSocket, BookDeltaSocket
from cryptofeed import FeedHandler
Expand Down
2 changes: 1 addition & 1 deletion examples/demo_uds.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'''
import asyncio
from multiprocessing import Process
import json
from yapic import json
from decimal import Decimal
import os

Expand Down
2 changes: 1 addition & 1 deletion examples/demo_zmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
associated with this software.
'''
from multiprocessing import Process
import json
from yapic import json

from cryptofeed.backends.zmq import BookZMQ, TickerZMQ
from cryptofeed import FeedHandler
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def run_tests(self):
"aiohttp",
"aiodns",
"cchardet",
"aiofile"
"aiofile",
'yapic.json'
],
extras_require={
'redis': ['aioredis'],
Expand Down
2 changes: 1 addition & 1 deletion tools/check_raw_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
associated with this software.
'''
import sys
import json
from yapic import json


def main(filename):
Expand Down
2 changes: 1 addition & 1 deletion tools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'''
from urllib.request import urlopen
import requests
import json
from yapic import json


"""
Expand Down