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

Python3 WIP #61

Open
wants to merge 1 commit into
base: python3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gryphon/dashboards/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from gryphon.lib import environment
environment.load_environment_variables()

import pyximport; pyximport.install()
import pyximport; pyximport.install(language_level=3)
import gryphon.lib; gryphon.lib.prepare()

from gryphon.dashboards.routes import url_patterns
Expand Down
4 changes: 2 additions & 2 deletions gryphon/dashboards/handlers/admin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def write_error(self, status_code, **kwargs):
exc_info = kwargs.get('exc_info')

error_readout = [
unicode(line, 'utf8') for line in traceback.format_exception(*exc_info)
str(line, 'utf8') for line in traceback.format_exception(*exc_info)
]

logger.critical(u''.join(error_readout))
Expand All @@ -47,7 +47,7 @@ def get_current_user(self):

def get_secure_cookie(self, name, include_name=True, value=None):
cookie_value = super(AdminBaseHandler, self).get_secure_cookie(name)
return unicode(cookie_value or '', 'utf8')
return str(cookie_value or '', 'utf8')

def show_error_message(self, message):
self.set_secure_cookie('error_message', message)
Expand Down
2 changes: 1 addition & 1 deletion gryphon/dashboards/handlers/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def table_entries_from_transaction(self, transaction):
entry['date'] = date
entry['details'] = ''.join([
'%s:%s ' % (k, v)
for k, v in transaction.transaction_details.iteritems()
for k, v in transaction.transaction_details.items()
if k in ['external_transaction_id', 'notes'] and v not in ['xxx']
])

Expand Down
2 changes: 1 addition & 1 deletion gryphon/dashboards/handlers/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def get_system_balances(self, exchanges):
system_balance += e.exchange_account_db_object(self.trading_db).balance

total_fiat = sum([
balance.to("USD") for currency, balance in system_balance.iteritems()
balance.to("USD") for currency, balance in system_balance.items()
if currency not in Money.CRYPTO_CURRENCIES
])

Expand Down
2 changes: 1 addition & 1 deletion gryphon/dashboards/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
metadata = Base.metadata

def unicode_string(self):
return unicode(self).encode('utf-8')
return str(self).encode('utf-8')

Base.__str__ == unicode_string

Expand Down
2 changes: 1 addition & 1 deletion gryphon/dashboards/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ <h5>Custom Strategies<h5>
<li class="dropdown-header"><h4>Ledgers</h4></li>
<li class='divider'></li>
{% if len(args['exchanges']) > 0 %}
{% for key, name in args['exchanges'].iteritems() %}
{% for key, name in args['exchanges'].items() %}
<li role='presentation'>
{% set url = "/ledger/%s" % key %}
<a role='menuitem' tabindex='-1' href="{{ url }}">{{ name }}</a>
Expand Down
4 changes: 2 additions & 2 deletions gryphon/dashboards/util/balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_balance_time_series_from_audits(audits):
continue

# convert to Money objects
for currency, balance_str in balance_data.iteritems():
for currency, balance_str in balance_data.items():
balance_data[currency] = Money.loads(balance_str)

balance = Balance(balance_data)
Expand Down Expand Up @@ -103,7 +103,7 @@ def get_drift_from_audits(audits):
if 'drift' in audit.data:
data = json.loads(audit.data)

for currency, str_amount in data['drift'].iteritems():
for currency, str_amount in data['drift'].items():
drift_by_currency += Money.loads(str_amount)

return drift_by_currency
Expand Down
4 changes: 2 additions & 2 deletions gryphon/data_service/auditors/orderbook_auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,15 @@ def audit_orderbook(self, orderbook, orderbook_timestamp):
if not our_orderbooks:
log.msg('No orderbooks to audit against')

for key, value in fundamental_values.iteritems():
for key, value in fundamental_values.items():
log.msg(
'------ Fundamental Value Closeness:%.6f, DBfv:%s, HTTPfv:%s' % (
key,
value['db_fundamental_value'],
value['http_fundamental_value']
))

for key, value in change_dict.iteritems():
for key, value in change_dict.items():
log.msg('------ Change Count: %s' % key)

log.msg(
Expand Down
2 changes: 1 addition & 1 deletion gryphon/data_service/exchange_volume_consumer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pyximport; pyximport.install()
import pyximport; pyximport.install(language_level=3)

import json
import os
Expand Down
2 changes: 1 addition & 1 deletion gryphon/data_service/migrations/env.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import with_statement
import pyximport; pyximport.install()
import pyximport; pyximport.install(language_level=3)
from logging.config import fileConfig

from alembic import context
Expand Down
2 changes: 1 addition & 1 deletion gryphon/data_service/orderbook_consumer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pyximport; pyximport.install()
import pyximport; pyximport.install(language_level=3)
import json
import os
import subprocess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ def get_orderbook_to_publish(self):
bids = []
asks = []

for price, volume in sorted(self.bids_dict.iteritems(), reverse=True):
for price, volume in sorted(self.bids_dict.items(), reverse=True):
if volume > 0:
bids.append([str(price), str(volume), ''])

for price, volume in sorted(self.asks_dict.iteritems()):
for price, volume in sorted(self.asks_dict.items()):
if volume > 0:
asks.append([str(price), str(volume), ''])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,26 +211,26 @@ def apply_change_to_orderbook(self, change):
# Remove the 0 volumes from the orderbook.
self.orderbook['bids'].update(bids_changes)

for k, v in self.orderbook['bids'].iteritems():
for k, v in self.orderbook['bids'].items():
if v == "0":
self.orderbook['bids'].pop(k)

# Re-sort the bids.
self.orderbook['bids'] = OrderedDict(sorted(
self.orderbook['bids'].iteritems(),
self.orderbook['bids'].items(),
key=lambda (k, v): float(k),
reverse=True,
))

self.orderbook['asks'].update(asks_changes)

for k, v in self.orderbook['asks'].iteritems():
for k, v in self.orderbook['asks'].items():
if v == "0":
self.orderbook['asks'].pop(k)

# Re-sort the asks.
self.orderbook['asks'] = OrderedDict(
sorted(self.orderbook['asks'].iteritems(), key=lambda (k, v): float(k)),
sorted(self.orderbook['asks'].items(), key=lambda (k, v): float(k)),
)

def parse_orders(self, orders):
Expand All @@ -247,7 +247,7 @@ def get_orderbook_to_publish(self):
price_key_orderbook = self.orderbook

return {
'bids': [[k, v, ''] for k, v in price_key_orderbook['bids'].iteritems()],
'asks': [[k, v, ''] for k, v in price_key_orderbook['asks'].iteritems()],
'bids': [[k, v, ''] for k, v in price_key_orderbook['bids'].items()],
'asks': [[k, v, ''] for k, v in price_key_orderbook['asks'].items()],
}

4 changes: 2 additions & 2 deletions gryphon/data_service/pollers/trades/trades_poller.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def parse_response(self, resp_obj):
for trade in trades:
if trade['trade_id'] > self.most_recent_trade_id:
trade['price_currency'] = trade['price'].currency
trade['price'] = unicode(trade['price'].amount)
trade['price'] = str(trade['price'].amount)
trade['volume_currency'] = trade['volume'].currency
trade['volume'] = unicode(trade['volume'].amount)
trade['volume'] = str(trade['volume'].amount)
trade['timestamp'] = int(trade['timestamp'])
trade_string = json.dumps(trade, ensure_ascii=False)
self.producer.publish_message(trade_string)
Expand Down
2 changes: 1 addition & 1 deletion gryphon/data_service/runt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
import pyximport; pyximport.install()
import pyximport; pyximport.install(language_level=3)
import logging
import logging.handlers
import os
Expand Down
2 changes: 1 addition & 1 deletion gryphon/data_service/scripts/historical_trade_collector.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import csv
from datetime import timedelta
import gzip
import StringIO
from io import StringIO

from delorean import epoch
import requests
Expand Down
6 changes: 3 additions & 3 deletions gryphon/data_service/trades_consumer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pyximport; pyximport.install()
import pyximport; pyximport.install(language_level=3)

import json
import os
Expand Down Expand Up @@ -27,9 +27,9 @@ def trades_consumer_function(message, db):
t = Trade(
price=Money(trade_json['price'], price_currency),
volume=Money(trade_json['volume'], volume_currency),
exchange=unicode(trade_json['exchange']),
exchange=str(trade_json['exchange']),
timestamp=timestamp,
exchange_trade_id=unicode(trade_json['trade_id']),
exchange_trade_id=str(trade_json['trade_id']),
)

db.add(t)
Expand Down
2 changes: 1 addition & 1 deletion gryphon/execution/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pyximport; pyximport.install()
import pyximport; pyximport.install(language_level=3)

import importlib
import logging
Expand Down
2 changes: 1 addition & 1 deletion gryphon/execution/bots/overwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def check_spreads_are_normal(db):

sanity = True

for exchange_name, fv in native_fvs.iteritems():
for exchange_name, fv in native_fvs.items():
if abs(fv - current_core_fv) > INTER_EXCHANGE_SPREAD_THRESHOLD:
sanity = False
break
Expand Down
2 changes: 1 addition & 1 deletion gryphon/execution/bots/shoebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def manual_btc_withdrawals(db):

logger.info('Running manual BTC withdrawals')

for name, target in MANUAL_BTC_EXCHANGES.iteritems():
for name, target in MANUAL_BTC_EXCHANGES.items():
exchange_db = exchange_factory.make_exchange_data_from_key(name, db)
if exchange_db.balance['BTC'] > target:
withdrawal_amount = exchange_db.balance['BTC'] - target
Expand Down
2 changes: 1 addition & 1 deletion gryphon/execution/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
strategy config files.
"""

import pyximport; pyximport.install()
import pyximport; pyximport.install(language_level=3)

from datetime import datetime, timedelta
import logging
Expand Down
2 changes: 1 addition & 1 deletion gryphon/execution/controllers/balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_db_balances(exchanges):

def format_balances(exchange_balances, db_balances):
output_string = u"\n{0:15} : {1:15} | {2:15} || {3:15} | {4:15}\n".format("Balances", "FIAT", "BTC", "dbFIAT", "dbBTC")
for name, balance in sorted(exchange_balances.iteritems()):
for name, balance in sorted(exchange_balances.items()):
db_balance = db_balances[name]
chunk = u"{0:15} : {1:15} | {2:15.8f} || {3:15} | {4:15.8f}\n".format(
name,
Expand Down
2 changes: 1 addition & 1 deletion gryphon/execution/controllers/initialize_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[--execute]
"""

import pyximport; pyximport.install()
import pyximport; pyximport.install(language_level=3)

import os

Expand Down
2 changes: 1 addition & 1 deletion gryphon/execution/controllers/manual_accounting.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def manual_accounting(exchange_name, order_id, actor, execute=False):

old_balance = exchange_data.balance[exchange.volume_currency]

for currency_code, position in position_change.iteritems():
for currency_code, position in position_change.items():
exchange_data.position[currency_code] += position
exchange_data.balance[currency_code] += position

Expand Down
2 changes: 1 addition & 1 deletion gryphon/execution/controllers/run_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
gryphon-exec run-migrations [GDS | TRADING | DASHBOARD] [--execute]
"""

import pyximport; pyximport.install()
import pyximport; pyximport.install(language_level=3)

import logging
import os
Expand Down
10 changes: 4 additions & 6 deletions gryphon/execution/harness/exchange_coordinator.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ it makes sure that our database does not get out of sync with our our account wi
exchange.
"""

import pyximport; pyximport.install()

from sets import Set
import pyximport; pyximport.install(language_level=3)

from cdecimal import Decimal, ROUND_UP, ROUND_DOWN
from delorean import Delorean
Expand Down Expand Up @@ -81,9 +79,9 @@ class ExchangeCoordinator(object):
@tick_profile
def _get_current_orders(self, exchange_open_orders):
db_open_orders = self._get_db_open_orders()
db_open_order_ids = Set([o.exchange_order_id for o in db_open_orders])
db_open_order_ids = set([o.exchange_order_id for o in db_open_orders])

exchange_open_order_ids = Set([o['id'] for o in exchange_open_orders])
exchange_open_order_ids = set([o['id'] for o in exchange_open_orders])
eaten_order_ids = db_open_order_ids - exchange_open_order_ids
current_order_ids = db_open_order_ids & exchange_open_order_ids

Expand Down Expand Up @@ -226,7 +224,7 @@ class ExchangeCoordinator(object):
"""
Formerly harness:update_position.
"""
for currency_code, position in position_change.iteritems():
for currency_code, position in position_change.items():
self.exchange_account.position[currency_code] += position
self.exchange_account.balance[currency_code] += position

Expand Down
3 changes: 1 addition & 2 deletions gryphon/execution/harness/harness.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ backtesting. For this, you can write another harness (so long as it conforms to
interface), and reimplement the interface functions in a different way.
"""

from sets import Set
import termcolor as tc
import time

Expand Down Expand Up @@ -227,7 +226,7 @@ class Harness(ConfigurableObject):
This function simply attaches the date and colours to a log message, and then
dispatches to the appropriate logger function.
"""
timestamp = unicode(Delorean().datetime.strftime('%d/%m/%y %H:%M:%S %Z'))
timestamp = str(Delorean().datetime.strftime('%d/%m/%y %H:%M:%S %Z'))

result_string = u'[%s] (%s) %s' % (
self.strategy.name if self.strategy else 'HARNESS_SETUP',
Expand Down
4 changes: 2 additions & 2 deletions gryphon/execution/lib/auditing.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def order_audit(db, exchange, skip_recent=0, tolerance=Decimal('0')):

failed_order_data = []

for exchange_order_id, exchange_volume_filled in audit_data.iteritems():
for exchange_order_id, exchange_volume_filled in audit_data.items():
try:
db_volume_filled = db_order_hash[exchange_order_id]

Expand Down Expand Up @@ -287,7 +287,7 @@ def balance_equality(balance_a, balance_b):
are fixing it here with the intention of a later fix to the core lib.
"""

currencies = set(balance_a.keys() + balance_b.keys())
currencies = set(list(balance_a.keys()) + list(balance_b.keys()))

for currency in currencies:
if currency in balance_a and currency in balance_b:
Expand Down
4 changes: 2 additions & 2 deletions gryphon/execution/lib/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ConfigParser
import configparser

from gryphon.lib.logger import get_logger

Expand All @@ -8,7 +8,7 @@
def get_config_var(filepath, section, key):
print filepath

config = ConfigParser.RawConfigParser()
config = configparser.RawConfigParser()
config.read(filepath)
section_dict = dict(config.items('live'))

Expand Down
2 changes: 1 addition & 1 deletion gryphon/execution/lib/config_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
3) At no point is there a any guarantee a setting is in the configuration object.
"""

import ConfigParser
import configparser
import argparse

from cdecimal import Decimal, InvalidOperation
Expand Down
2 changes: 1 addition & 1 deletion gryphon/execution/lib/tick_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def record_tick_data(tick_start, strategy_name):


def record_tick_block_data(algo, tick_count, strategy_name):
for function_name, profile_times in tick_profile_data.iteritems():
for function_name, profile_times in tick_profile_data.items():
datum_name = datum_name_for_function_block(strategy_name, function_name)

for block_time in profile_times:
Expand Down
2 changes: 1 addition & 1 deletion gryphon/execution/live_runner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pyximport; pyximport.install()
import pyximport; pyximport.install(language_level=3)
from cdecimal import Decimal
import inspect
import os
Expand Down
Loading