-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from olned/coinbase
Coinbase Pro added
- Loading branch information
Showing
25 changed files
with
636 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python | ||
import asyncio | ||
import logging | ||
|
||
from ssc2ce import Coinbase | ||
|
||
logging.basicConfig(format='%(asctime)s %(name)s %(funcName)s %(levelname)s %(message)s', level=logging.INFO) | ||
logger = logging.getLogger("bitfinex-basic-example") | ||
|
||
|
||
def handle_message(message: str): | ||
logger.info(message) | ||
|
||
|
||
conn = Coinbase() | ||
conn.on_message = handle_message | ||
|
||
|
||
async def subscribe(): | ||
await conn.ws.send_json({ | ||
"type": "subscribe", | ||
"product_ids": [ | ||
"BTC-USD", | ||
"ETH-BTC" | ||
], | ||
"channels": [ | ||
"level2", | ||
"heartbeat" | ||
] | ||
}) | ||
|
||
|
||
def handle_heartbeat(data: dict) -> bool: | ||
global last_time | ||
last_time = data["time"] | ||
logger.info(f"{repr(data)}") | ||
return True | ||
|
||
|
||
conn.on_connect_ws = subscribe | ||
|
||
|
||
def stop(): | ||
asyncio.ensure_future(conn.stop()) | ||
|
||
|
||
loop = asyncio.get_event_loop() | ||
loop.call_later(3600, stop) | ||
|
||
try: | ||
loop.run_until_complete(conn.run_receiver()) | ||
except KeyboardInterrupt: | ||
logger.info("Application closed by KeyboardInterrupt.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env python | ||
import asyncio | ||
import json | ||
import logging | ||
from ssc2ce import Coinbase | ||
|
||
conn = Coinbase(False) | ||
|
||
pending = {} | ||
|
||
logging.basicConfig(format='%(asctime)s %(name)s %(funcName)s %(levelname)s %(message)s', level=logging.INFO) | ||
logger = logging.getLogger("deribit-writer") | ||
|
||
instruments = [] | ||
|
||
|
||
async def subscribe_books(): | ||
await conn.ws.send_json({ | ||
"type": "subscribe", | ||
"product_ids": instruments, | ||
"channels": [ | ||
"level2", | ||
"heartbeat" | ||
] | ||
}) | ||
|
||
|
||
output = open("coinbase_dump.txt", "w") | ||
|
||
|
||
def dump(msg: str): | ||
output.write(msg) | ||
output.write('\n') | ||
|
||
|
||
def stop(): | ||
asyncio.ensure_future(conn.ws.close()) | ||
|
||
|
||
async def run(): | ||
# from pprint import pprint | ||
all_products = [x for x in await conn.get_products()] | ||
# pprint(all_products) | ||
|
||
my_products = {x['id']: x for x in all_products if x['quote_currency'] == 'EUR'} | ||
base_currencies = [x['base_currency'] for x in my_products.values()] | ||
|
||
for product in all_products: | ||
if product["id"] in my_products: | ||
continue | ||
|
||
if product['quote_currency'] in base_currencies: | ||
my_products[product["id"]] = product | ||
|
||
global instruments | ||
instruments += list(my_products.keys()) | ||
await conn.run_receiver() | ||
|
||
conn.on_before_handling = dump | ||
conn.on_connect_ws = subscribe_books | ||
|
||
loop = asyncio.get_event_loop() | ||
loop.call_later(3600, stop) | ||
|
||
try: | ||
loop.run_until_complete(run()) | ||
except KeyboardInterrupt: | ||
print("Application closed by KeyboardInterrupt.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import asyncio | ||
import logging | ||
import argparse | ||
from time import time | ||
|
||
from examples.book_watcher import BookWatcher | ||
|
||
import sys | ||
|
||
from ssc2ce import create_parser | ||
|
||
logging.basicConfig(format='%(asctime)s %(name)s %(funcName)s %(levelname)s %(message)s', level=logging.INFO) | ||
logger = logging.getLogger("deribit-parser") | ||
|
||
|
||
class FileController: | ||
def __init__(self, exchange: str, is_cpp: bool): | ||
|
||
self.parser = create_parser(exchange, is_cpp) | ||
if self.parser is None: | ||
exit(1) | ||
|
||
self.counter = 0 | ||
self.watcher = BookWatcher(self.parser, False) | ||
|
||
def run(self, filename: str): | ||
start = time() | ||
i = 0 | ||
with open(filename) as f: | ||
for line in f: | ||
i += 1 | ||
if not self.parser.parse(line): | ||
self.handle_message(line) | ||
|
||
logger.info(f"{i} in {time() - start} sec. {self.counter}") | ||
|
||
def handle_message(self, message: str) -> None: | ||
self.counter += 1 | ||
# logger.info(message[:-1]) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser('ssc2ce parser example.') | ||
parser.add_argument('exchange', | ||
type=str, | ||
help='...') | ||
parser.add_argument('file', | ||
type=str, | ||
help='...') | ||
parser.add_argument('-c', '--cpp', | ||
dest='is_cpp', | ||
action='store_true', | ||
default=False, | ||
help='...') | ||
|
||
args = parser.parse_args() | ||
|
||
FileController(args.exchange, args.is_cpp).run(args.file) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
setuptools.setup( | ||
name='ssc2ce', | ||
version="0.12.2", | ||
version="0.13.0", | ||
author='Oleg Nedbaylo', | ||
author_email='[email protected]', | ||
description='A Set of Simple Connectors for access To Cryptocurrency Exchanges', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
from .deribit import Deribit | ||
from .deribit import Deribit, DeribitParser, DeribitL2Book | ||
from .common import AuthType | ||
from .bitfinex import Bitfinex | ||
|
||
from .bitfinex import Bitfinex, BitfinexL2Book | ||
from .coinbase_pro import Coinbase, CoinbaseParser, CoinbaseL2Book | ||
from .factory import create_parser | ||
from pkg_resources import get_distribution, DistributionNotFound | ||
|
||
try: | ||
__version__ = get_distribution(__name__).version | ||
except DistributionNotFound: | ||
# package is not installed | ||
pass | ||
pass |
Oops, something went wrong.