-
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 #21 from olned/cex.io
v0.14.0
- Loading branch information
Showing
60 changed files
with
1,109 additions
and
220 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CEX_API_KEY= | ||
CEX_SECRET= | ||
CEX_UID= | ||
COINBASE_PRO_KEY= | ||
COINBASE_PRO_SECRET= | ||
COINBASE_PRO_PASSPHRASE= | ||
DERIBIT_CLIENT_ID= | ||
DERIBIT_CLIENT_SECRET= |
Empty file.
Empty file.
File renamed without changes.
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,3 @@ | ||
CEX_API_KEY=YOUR_KEY | ||
CEX_SECRET=YOUR_SECRET | ||
CEX_UID=YOUR_PASSPHRASE |
Empty file.
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,72 @@ | ||
#!/usr/bin/env python | ||
import asyncio | ||
import logging | ||
import os | ||
|
||
import aiohttp | ||
from ssc2ce import Cex | ||
from dotenv import load_dotenv | ||
|
||
logging.basicConfig(format='%(asctime)s %(name)s %(funcName)s %(levelname)s %(message)s', level=logging.INFO) | ||
logger = logging.getLogger("bitfinex-basic-example") | ||
|
||
env_path = os.path.join(os.path.dirname(__file__), '.env') | ||
load_dotenv(env_path) | ||
|
||
auth_param = dict(apiKey=os.environ.get('CEX_API_KEY'), | ||
secret=os.environ.get('CEX_SECRET'), | ||
uid=os.environ.get('CEX_UID')) | ||
|
||
conn = Cex(auth_param) | ||
|
||
archive_orders = [] | ||
|
||
|
||
async def get_archive_orders(symbol1, symbol2): | ||
global archive_orders | ||
res = await conn.private_get(f"archived_orders/{symbol1}/{symbol2}") | ||
archive_orders += res | ||
|
||
|
||
async def start(): | ||
request = {'e': "get-balance", 'oid': '1'} | ||
|
||
await conn.ws.send_json(request) | ||
|
||
my_balance = {} | ||
data = await conn.ws.receive() | ||
if data.type == aiohttp.WSMsgType.TEXT: | ||
data = data.json() | ||
if data.get('ok') == 'ok': | ||
balance = data['data']['balance'] | ||
for key, value in balance.items(): | ||
if float(value) != 0.00: | ||
my_balance[key] = value | ||
|
||
print(my_balance) | ||
|
||
coroutines = [] | ||
data = await conn.public_get("currency_limits") | ||
|
||
if data.get('ok') == 'ok': | ||
for pair in data['data']['pairs']: | ||
if pair['symbol1'] in my_balance and pair['symbol2'] in my_balance: | ||
print(pair) | ||
coroutines.append(get_archive_orders(pair['symbol1'], pair['symbol2'])) | ||
break | ||
|
||
if coroutines: | ||
await asyncio.gather(*coroutines) | ||
for order in archive_orders: | ||
print(order) | ||
|
||
await conn.stop() | ||
|
||
|
||
conn.on_connect_ws = start | ||
loop = asyncio.get_event_loop() | ||
|
||
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,41 @@ | ||
#!/usr/bin/env python | ||
import asyncio | ||
import logging | ||
|
||
from ssc2ce import Cex | ||
|
||
logging.basicConfig(format='%(asctime)s %(name)s %(funcName)s %(levelname)s %(message)s', level=logging.INFO) | ||
logger = logging.getLogger("bitfinex-basic-example") | ||
|
||
conn = Cex() | ||
|
||
|
||
async def subscribe(): | ||
data = await conn.public_get("currency_limits") | ||
if data.get('ok') == 'ok': | ||
for pair in data['data']['pairs']: | ||
if pair['symbol1'] == 'BTC' and pair['symbol2'] == 'EUR': | ||
print(pair) | ||
|
||
data = await conn.public_get("ticker/BTC/EUR") | ||
print(data) | ||
|
||
request = {'e': "subscribe", 'rooms': ["ticker"]} | ||
|
||
await conn.ws.send_json(request) | ||
|
||
|
||
def print_ticker(msg): | ||
print(msg) | ||
return True | ||
|
||
|
||
conn.on_connect_ws = subscribe | ||
conn.on_message = print_ticker | ||
|
||
loop = asyncio.get_event_loop() | ||
|
||
try: | ||
loop.run_until_complete(conn.run_receiver()) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env python | ||
import asyncio | ||
import logging | ||
import os | ||
|
||
from examples.common.book_watcher import BookWatcher | ||
from ssc2ce import Cex, CexParser | ||
from dotenv import load_dotenv | ||
|
||
logging.basicConfig(format='%(asctime)s %(name)s %(funcName)s %(levelname)s %(message)s', level=logging.INFO) | ||
logger = logging.getLogger("bitfinex-basic-example") | ||
|
||
env_path = os.path.join(os.path.dirname(__file__), '.env') | ||
load_dotenv(env_path) | ||
|
||
auth_param = dict(apiKey=os.environ.get('CEX_API_KEY'), | ||
secret=os.environ.get('CEX_SECRET'), | ||
uid=os.environ.get('CEX_UID')) | ||
|
||
print(auth_param) | ||
|
||
conn = Cex(auth_param) | ||
parser = CexParser() | ||
watcher = BookWatcher(parser) | ||
conn.on_message = parser.parse | ||
|
||
|
||
async def subscribe(): | ||
for market in ["BTC-EUR", 'ETH-EUR', "ETH-BTC"]: | ||
pair = list(market.split('-')) | ||
request = {'e': "order-book-subscribe", | ||
'oid': 'book-1', | ||
'data': {'pair': [pair[0], pair[1]], 'subscribe': True, 'depth': 0} | ||
} | ||
|
||
await conn.ws.send_json(request) | ||
|
||
|
||
output = open("cex_dump_1h.jsonl", "w") | ||
|
||
|
||
def dump(msg: str): | ||
output.write(msg) | ||
output.write('\n') | ||
|
||
|
||
conn.on_connect_ws = subscribe | ||
conn.on_before_handling = dump | ||
loop = asyncio.get_event_loop() | ||
|
||
|
||
def stop(): | ||
asyncio.ensure_future(conn.ws.close()) | ||
|
||
|
||
loop.call_later(3600, stop) | ||
try: | ||
loop.run_until_complete(conn.run_receiver()) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
COINBASE_PRO_KEY=YOUR_KEY | ||
COINBASE_PRO_SECRET=YOUR_SECRET | ||
COINBASE_PRO_PASSPHRASE=YOUR_PASSPHRASE |
Empty file.
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,65 @@ | ||
#!/usr/bin/env python | ||
import asyncio | ||
import logging | ||
import os | ||
|
||
from dotenv import load_dotenv | ||
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") | ||
|
||
env_path = os.path.join(os.path.dirname(__file__), '.env') | ||
load_dotenv(env_path) | ||
|
||
auth_param = dict(api_key=os.environ.get('COINBASE_PRO_KEY'), | ||
secret_key=os.environ.get('COINBASE_PRO_SECRET'), | ||
passphrase=os.environ.get('COINBASE_PRO_PASSPHRASE')) | ||
|
||
print(auth_param) | ||
|
||
|
||
def handle_message(message: str): | ||
logger.info(message) | ||
|
||
|
||
conn = Coinbase(auth_param=auth_param) | ||
conn.on_message = handle_message | ||
|
||
|
||
async def start(): | ||
res = await conn.private_get('/accounts') | ||
print(res) | ||
await conn.stop() | ||
# await conn.ws.send_json({ | ||
# "type": "subscribe", | ||
# "product_ids": [ | ||
# "BTC-USD", | ||
# "ETH-BTC" | ||
# ], | ||
# "channels": [ | ||
# "level2", | ||
# "heartbeat" | ||
# ] | ||
# }) | ||
|
||
|
||
def handle_heartbeat(data: dict) -> bool: | ||
logger.info(f"{repr(data)}") | ||
return True | ||
|
||
|
||
conn.on_connect_ws = start | ||
|
||
|
||
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
Oops, something went wrong.