Skip to content

Commit

Permalink
BLD: made some adjustments during testing
Browse files Browse the repository at this point in the history
  • Loading branch information
fredfortier committed Feb 7, 2018
1 parent 2320a14 commit c5bed6e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion catalyst/examples/mean_reversion_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def analyze(context=None, perf=None):
algo_namespace=NAMESPACE,
base_currency='eth',
live_graph=False,
simulate_orders=False,
simulate_orders=True,
stats_output=None,
# auth_aliases=dict(poloniex='auth2')
)
Expand Down
46 changes: 27 additions & 19 deletions catalyst/marketplace/marketplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ def sign_transaction(self, from_address, tx):
'Gas Limit:\t\t{gas}\n'
'Nonce:\t\t\t{nonce}\n'
'Data:\t\t\t{data}\n'.format(
_from=from_address,
to=tx['to'],
value=tx['value'],
gas=tx['gas'],
nonce=tx['nonce'],
data=tx['data'],
)
)
_from=from_address,
to=tx['to'],
value=tx['value'],
gas=tx['gas'],
nonce=tx['nonce'],
data=tx['data'],
)
)

signed_tx = input('Copy and Paste the "Signed Transaction" '
'field here:\n')
Expand Down Expand Up @@ -197,6 +197,7 @@ def list(self):
print(df)

def subscribe(self, dataset):
# TODO: what happens if we are already subscribed?
dataset = dataset.lower()

address = self.choose_pubaddr()[0]
Expand All @@ -217,11 +218,13 @@ def subscribe(self, dataset):
print('Checking that the ENG balance in {} is greater than '
'{} ENG... '.format(address, price), end='')

wallet_address = address[2:]
balance = self.web3.eth.call({
'from': address,
'to': self.eng_contract_address,
'data': '0x70a08231000000000000000000000000{}'.format(
address[2:])
wallet_address
)
})
try:
balance = int(balance[2:], 16) // 10 ** 8
Expand All @@ -242,7 +245,7 @@ def subscribe(self, dataset):
agree_pay = input('Please confirm that you agree to pay {} ENG '
'for a monthly subscription to the dataset "{}" '
'starting today. [default: Y] '.format(
price, dataset)) or 'y'
price, dataset)) or 'y'
if agree_pay.lower() not in ('y', 'n'):
print("Please answer Y or N.")
else:
Expand All @@ -259,22 +262,25 @@ def subscribe(self, dataset):
'2. Second transaction is the actual subscription for the '
'desired dataset'.format(price))

grains = price * 10 ** 8
tx = self.eng_contract.functions.approve(
self.mkt_contract_address,
price,
grains,
).buildTransaction(
{'nonce': self.web3.eth.getTransactionCount(address)})
{'nonce': self.web3.eth.getTransactionCount(address)}
)

if 'ropsten' in ETH_REMOTE_NODE:
tx['gas'] = min(int(tx['gas'] * 1.5), 4700000)

signed_tx = self.sign_transaction(address, tx)

try:
tx_hash = '0x{}'.format(bin_hex(
self.web3.eth.sendRawTransaction(signed_tx)))
print('\nThis is the TxHash for this transaction: '
'{}'.format(tx_hash))
tx_hash = '0x{}'.format(
bin_hex(self.web3.eth.sendRawTransaction(signed_tx))
)
print(
'\nThis is the TxHash for this transaction: {}'.format(tx_hash)
)

except Exception as e:
print('Unable to subscribe to data source: {}'.format(e))
Expand Down Expand Up @@ -350,7 +356,7 @@ def subscribe(self, dataset):
'You can now ingest this dataset anytime during the '
'next month by running the following command:\n'
'catalyst marketplace ingest --dataset={}'.format(
dataset, address, dataset))
dataset, address, dataset))

def process_temp_bundle(self, ds_name, path):
"""
Expand Down Expand Up @@ -381,6 +387,7 @@ def process_temp_bundle(self, ds_name, path):
def ingest(self, ds_name, start=None, end=None, force_download=False):

ds_name = ds_name.lower()
# TODO: catch error conditions
provider_info = self.mkt_contract.functions.getDataProviderInfo(
bytes32(ds_name)
).call()
Expand All @@ -391,7 +398,8 @@ def ingest(self, ds_name, start=None, end=None, force_download=False):
return

address, address_i = self.choose_pubaddr()
check_sub = self.mkt_contract.functions.checkAddressSubscription(
fns = self.mkt_contract.functions
check_sub = fns.checkAddressSubscription(
address, bytes32(ds_name)
).call()

Expand Down
7 changes: 4 additions & 3 deletions tests/marketplace/test_marketplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ def test_register(self):

def test_subscribe(self):
marketplace = Marketplace()
marketplace.subscribe('marketcap1')
marketplace.subscribe('marketcap1234')
pass

def test_ingest(self):
marketplace = Marketplace()
ds_def = marketplace.ingest('marketcap1')
ds_def = marketplace.ingest('marketcap1234')
pass

def test_publish(self):
marketplace = Marketplace()
datadir = '/Users/fredfortier/Downloads/marketcap_test_single'
marketplace.publish('marketcap1', datadir, False)
marketplace.publish('marketcap1234', datadir, False)
pass

def test_clean(self):
marketplace = Marketplace()
Expand Down

0 comments on commit c5bed6e

Please sign in to comment.