<commit_before>"""
Task:
Do fancy shit.
"""

# Import Built-Ins
import logging
import socket
import time

# Import Third-Party
from ..api.gdax import API

# Import Homebrew

log = logging.getLogger(__name__)


class Client:
    def __init__(self, server_addr, key=None):
        self.__server_addr = server_addr
        self.__key = key

    def send(self, message):
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        #sock.sendto(json.dumps(message).encode('ascii'), self.__server_addr)
        print(message)

    def listen(self, endpoint, q={}, private=False, post=False):
        api = API()

        while True:
            print("listening!")
            if private:
                api.load_key(self.__key)
                resp = api.query_private(endpoint, q, post)
            else:
                resp = api.query_public(endpoint, q, post)
            self.send(resp)
            time.sleep(5)


if __name__ == '__main__':
    uix = Client(('localhost', 6666), './gdax.key')
    uix.listen('accounts', private=True, post=False)<commit_msg>added orderbook func; adjusted class layout based on new base class<commit_after>"""
Task:
Do fancy shit.
"""

# Import Built-Ins
import logging
import socket
import time
import json

# Import Third-Party
from bitex.api.gdax import API
from bitex.http.client import Client

# Import Homebrew

log = logging.getLogger(__name__)


class GdaxHTTP(Client):
    def __init__(self, server_addr, key='', secret='', key_file=''):
        api = API(key, secret)
        if key_file:
            api.load_key(key_file)
        super(GdaxHTTP, self).__init__(server_addr, api, 'GDAX')

    def send(self, message):
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.sendto(json.dumps(message).encode('ascii'), self._receiver)
        super(GdaxHTTP, self).send(message)

    def format_ob(self, input, pair):
        ask_p, ask_v, _ = input['asks'][0]
        bid_p, bid_v, _ = input['bids'][0]
        formatted = [[None, 'Ask Price', ask_p],
                     [None, 'Ask Vol', ask_v],
                     [None, 'Bid Price', bid_p],
                     [None, 'Bid Vol', bid_v]]
        return formatted

    def orderbook(self, pair, count=0):
        q = {'pair': pair}
        if count:
            q['count'] = count

        sent = time.time()
        resp = self._query('/products/%s/book' % pair, q)
        received = time.time()
        formatted = self.format_ob(resp, pair)
        for i in formatted:
            self.send(super(GdaxHTTP, self)._format(pair, sent, received, *i))


if __name__ == '__main__':
    uix = GdaxHTTP(('localhost', 6666))
    uix.orderbook('BTC-USD')
{'fraction_non_alphanumeric': 0.13226527570789867, 'fraction_numerical': 0.004470938897168405, 'mean_word_length': 2.5098039215686274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3053124', 'n_tokens_mistral': 887, 'n_tokens_neox': 850, 'n_words': 210}