def __init__(self,
              blockchain='neo',
              contract_version='V3',
              api_url='https://test-api.switcheo.network/',
              api_version='/v2'):
     PublicClient.__init__(self,
                           blockchain=blockchain,
                           contract_version=contract_version,
                           api_url=api_url,
                           api_version=api_version)
     self.infura_dict = {
         'https://api.switcheo.network': 'https://infura.io/',
         'https://api.switcheo.network/': 'https://infura.io/',
         'api.switcheo.network': 'https://infura.io/',
         'api.switcheo.network/': 'https://infura.io/',
         'https://test-api.switcheo.network': 'https://ropsten.infura.io/',
         'https://test-api.switcheo.network/': 'https://ropsten.infura.io/',
         'test-api.switcheo.network': 'https://ropsten.infura.io/',
         'test-api.switcheo.network/': 'https://ropsten.infura.io/'
     }
     self.infura_url = self.infura_dict[api_url]
     self.blockchain_amount = {
         'eth': partial(to_wei, unit='ether'),
         'neo': to_neo_asset_amount
     }
     self.sign_create_cancellation_function = {
         'eth': sign_create_cancellation_eth,
         'neo': sign_create_cancellation_neo
     }
     self.sign_execute_cancellation_function = {
         'eth': sign_execute_cancellation_eth,
         'neo': sign_execute_cancellation_neo
     }
     self.sign_create_deposit_function = {
         'eth': sign_create_deposit_eth,
         'neo': sign_create_deposit_neo
     }
     self.sign_execute_deposit_function = {
         'eth': partial(sign_execute_deposit_eth,
                        infura_url=self.infura_url),
         'neo': sign_execute_deposit_neo
     }
     self.sign_create_order_function = {
         'eth': sign_create_order_eth,
         'neo': sign_create_order_neo
     }
     self.sign_execute_order_function = {
         'eth': sign_execute_order_eth,
         'neo': sign_execute_order_neo
     }
     self.sign_create_withdrawal_function = {
         'eth': sign_create_withdrawal_eth,
         'neo': sign_create_withdrawal_neo
     }
     self.sign_execute_withdrawal_function = {
         'eth': sign_execute_withdrawal_eth,
         'neo': sign_execute_withdrawal_neo
     }
Example #2
0
 def __init__(self,
              blockchain="neo",
              contract_version='V2',
              api_url='https://test-api.switcheo.network/',
              api_version='/v2'):
     PublicClient.__init__(self,
                           blockchain=blockchain,
                           api_url=api_url,
                           api_version=api_version)
     self.contract_version = contract_version
     self.contract_hash = self.get_contracts()['NEO'][self.contract_version]
Example #3
0
 def __init__(self,
              switcheo_network="test",
              blockchain_network="neo",
              private_key=None):
     self.api_url = url_dict[switcheo_network]
     self.blockchain = network_dict[blockchain_network]
     self.contract_version = current_contract_version(
         PublicClient().get_latest_contracts()[self.blockchain.upper()],
         PublicClient().get_contracts())
     super().__init__(blockchain=self.blockchain,
                      contract_version=self.contract_version,
                      api_url=self.api_url)
     self.private_key = private_key
 def test_current_contract_hash(self):
     pc = PublicClient()
     expected_current_contract_dict = {
         'NEO': 'a195c1549e7da61b8da315765a790ac7e7633b82',
         'ETH': '0x607af5164d95bd293dbe2b994c7d8aef6bec03bf'
     }
     self.assertDictEqual(current_contract_hash(pc.contracts),
                          expected_current_contract_dict)
 def test_current_contract_hash(self):
     pc = PublicClient()
     expected_current_contract_dict = {
         'NEO': '58efbb3cca7f436a55b1a05c0f36788d2d9a032e',
         'ETH': '0x4d19fd42e780d56ff6464fe9e7d5158aee3d125d',
         'QTUM': 'fake_qtum_contract_hash',
         'EOS': 'toweredbyob2'
     }
     self.assertDictEqual(current_contract_hash(pc.contracts),
                          expected_current_contract_dict)
Example #6
0
class Switcheo:
    def __init__(self):
        self.client = PublicClient(api_url='https://api.switcheo.network/')

    def get_ticker(self, pairs):
        _pairs = [x[0] + '_' + x[1] for x in pairs]
        _last_24h = self.client.get_last_24_hours()
        _last_prices = self.client.get_last_price()
        rows = list()
        for x in _last_24h:
            if x['pair'] not in _pairs:
                continue
            pos = x['pair'].find('_')
            x['price'] = _last_prices[x['pair'][:pos]][x['pair'][pos + 1:]]
            x['ticker'] = x['pair'].split('_')[0]
            rows.append(x)
            if len(rows) == len(pairs):
                break
        return rows
Example #7
0
class Switcheo:
    def __init__(self):
        self.client = PublicClient(api_url="https://api.switcheo.network/")

    def get_ticker(self, pairs):
        _pairs = [x[0] + "_" + x[1] for x in pairs]
        _last_24h = self.client.get_last_24_hours()
        _last_prices = self.client.get_last_price()
        rows = []
        for x in _last_24h:
            if x["pair"] not in _pairs:
                continue
            pos = x["pair"].find("_")
            x["price"] = _last_prices[x["pair"][:pos]][x["pair"][pos + 1:]]
            x["ticker"] = x["pair"].split("_")[0]
            rows.append(x)
            if len(rows) == len(pairs):
                break
        return rows
 def test_current_contract_hash(self):
     pc = PublicClient()
     expected_current_contract_dict = {
         'NEO': '58efbb3cca7f436a55b1a05c0f36788d2d9a032e',
         'ETH': '0x4dcf0244742e72309666db20d367f6dd196e884e',
         'QTUM': '0x2b25406b0000c3661e9c88890690fd4b5c7b4234',
         'EOS': 'oboluswitch4'
     }
     self.assertDictEqual(current_contract_hash(pc.contracts),
                          expected_current_contract_dict)
Example #9
0
import unittest
import time
from switcheo.public_client import PublicClient

pc = PublicClient(blockchain='neo')


class TestPublicClient(unittest.TestCase):
    def test_get_exchange_status(self):
        exchange_status_dict = {'status': 'ok'}
        self.assertDictEqual(pc.get_exchange_status(), exchange_status_dict)

    def test_get_exchange_time(self):
        exchange_time_dict = {'timestamp': 1533362081336}
        self.assertGreater(pc.get_exchange_time()['timestamp'],
                           exchange_time_dict['timestamp'])

    def test_get_token_details(self):
        exchange_token_list = ['NEO', 'GAS', 'SWTH', 'ETH']
        exchange_token_request = pc.get_token_details()
        self.assertTrue(
            set(exchange_token_request.keys()).issuperset(
                set(exchange_token_list)))

    def test_get_candlesticks(self):
        candles_key_list = [
            'time', 'open', 'close', 'high', 'low', 'volume', 'quote_volume'
        ]
        candles_request = pc.get_candlesticks(pair="SWTH_NEO",
                                              start_time=round(time.time()) -
                                              360000,
Example #10
0
 def __init__(self):
     self.client = PublicClient(api_url='https://api.switcheo.network/')
import unittest
import time
from switcheo.public_client import PublicClient


pc = PublicClient(blockchain='neo')
pc_eth = PublicClient(blockchain='eth', contract_version='V1')


class TestPublicClient(unittest.TestCase):

    def test_get_exchange_status(self):
        exchange_status_dict = {'status': 'ok'}
        self.assertDictEqual(pc.get_exchange_status(), exchange_status_dict)

    def test_get_exchange_time(self):
        exchange_time_dict = {'timestamp': 1533362081336}
        self.assertGreater(pc.get_exchange_time()['timestamp'], exchange_time_dict['timestamp'])

    def test_get_token_details(self):
        exchange_token_list = ['NEO', 'GAS', 'SWTH', 'ETH']
        exchange_token_request = pc.get_token_details()
        self.assertTrue(set(exchange_token_request.keys()).issuperset(set(exchange_token_list)))

    def test_get_candlesticks(self):
        candles_key_list = ['time', 'open', 'close', 'high', 'low', 'volume', 'quote_volume']
        candles_request = pc.get_candlesticks(pair="SWTH_NEO",
                                              start_time=round(time.time()) - 360000,
                                              end_time=round(time.time()),
                                              interval=60)
        for candle in candles_request: