Ejemplo n.º 1
0
 def test_list_order(self):
     order = self.order
     params = {
         'id':
         1,
         'access_key':
         'xxx',
         'signature':
         'c242b60f1830337f7618afab08d378b7cb2e9501fe226e76e0cab0ee93ac1933'
     }
     responses.add(
         responses.GET,
         concat_url_and_params(order.build_url(order.ORDER_URI), params),
         json={
             'id': 1,  # Unique order id.
             'side': 'buy',  # Either 'sell' or 'buy'.
             'ord_type': 'limit',  # Type of order, now only 'limit'.
             'price':
             '0.002',  # Price for each unit. e.g. If you sell/buy 1 OTB at 0.002 ETH, the price is '0.002'
             'avg_price':
             '0.0',  # Average execution price, average of price in trades.
             'state':
             'wait',  # One of 'wait', 'done', or 'cancel'. An order in 'wait' is an active order, waiting fullfillment; a 'done' order is an order fullfilled; 'cancel' means the order has been cancelled.
             'market':
             'otbeth',  # The market in which the order is placed, e.g. 'otbeth'. All available markets can be found at /api/v2/markets.
             'created_at':
             '2017-02-01T00:00:00+08:00',  # Order create time in iso8601 format.
             'volume':
             '100.0',  # The amount user want to sell/buy. An order could be partially executed, e.g. an order sell 100 otb can be matched with a buy 60 otb order, left 40 otb to be sold; in this case the order's volume would be '100.0', its remaining_volume would be '40.0', its executed volume is '60.0'.
             'remaining_volume': '100.0',  # The remaining volume
             'executed_volume': '0.0',  # The executed volume
             'trades_count': 1  # Number of trades under this order
         })
     resp = order.list_order(id=1)
     assert resp['id'] == 1
Ejemplo n.º 2
0
 def test_fetch(self):
     kline = self.kline
     market = 'otbeth'
     params = {
         'market': market,
         'limit': 2,
         'period': 1,
     }
     responses.add(
         responses.GET,
         concat_url_and_params(kline.build_url(kline.KLINES_URI), params),
         json=[
             [
                 1517833860,  # An integer represents the seconds elapsed since Unix epoch.
                 0.001159,  # K line open price
                 0.001162,  # K line highest price
                 0.001157,  # K line lowest price
                 0.001158,  # K line close price
                 1000  # K line volume
             ],
             [1517833920, 0.001142, 0.001160, 0.001142, 0.001159, 500]
         ],
         match_querystring=True)
     resp = kline.fetch(market=market, limit=2, period=1)
     assert len(resp) == 2
Ejemplo n.º 3
0
 def test_fetch(self):
     trade = self.trade
     market = 'otbeth'
     params = {'market': market, 'limit': '1', 'order_by': 'desc'}
     responses.add(
         responses.GET,
         concat_url_and_params(trade.build_url(trade.TRADES_URI), params),
         json=[{
             'id': 25073,  # Unique trade id
             'price': '0.00116',  # Trade's price
             'volume': '473.3586',  # Trade's volume
             'funds':
             '0.549095976',  # Trade's funds, calculated by price * volume
             'market':
             'otbeth',  # The market in which the order is placed, e.g. 'otbeth'. All available markets can be found at /api/v2/markets.
             'created_at':
             '2018-02-05T20:45:22+08:00',  # Order create time in iso8601 format.
             'at':
             1517834722,  # An integer represents the seconds elapsed since Unix epoch.
             'side':
             'up'  # Trade's side, 'up' means the price is higher than the previous one, 'down' is lower than the previous one
         }],
         match_querystring=True)
     resp = trade.fetch(market=market, limit=1, order_by='desc')
     assert len(resp) == 1
     assert resp[0]['market'] == market
Ejemplo n.º 4
0
 def test_list_orders(self):
     order = self.order
     market = 'otbeth'
     params = {
         'market':
         market,
         'access_key':
         'xxx',
         'signature':
         'be0694b7c33e92da3ec6ee534f7391fb7d0332fc1d867681c5085c5194ed69c8'
     }
     responses.add(
         responses.GET,
         concat_url_and_params(order.build_url(order.ORDERS_URI), params),
         json=[
             {
                 'id': 1,  # Unique order id.
                 'side': 'buy',  # Either 'sell' or 'buy'.
                 'ord_type': 'limit',  # Type of order, now only 'limit'.
                 'price':
                 '0.002',  # Price for each unit. e.g. If you sell/buy 1 OTB at 0.002 ETH, the price is '0.002'
                 'avg_price':
                 '0.0',  # Average execution price, average of price in trades.
                 'state':
                 'wait',  # One of 'wait', 'done', or 'cancel'. An order in 'wait' is an active order, waiting fullfillment; a 'done' order is an order fullfilled; 'cancel' means the order has been cancelled.
                 'market':
                 'otbeth',  # The market in which the order is placed, e.g. 'otbeth'. All available markets can be found at /api/v2/markets.
                 'created_at':
                 '2017-02-01T00:00:00+08:00',  # Order create time in iso8601 format.
                 'volume':
                 '100.0',  # The amount user want to sell/buy. An order could be partially executed, e.g. an order sell 100 otb can be matched with a buy 60 otb order, left 40 otb to be sold; in this case the order's volume would be '100.0', its remaining_volume would be '40.0', its executed volume is '60.0'.
                 'remaining_volume': '100.0',  # The remaining volume
                 'executed_volume': '0.0',  # The executed volume
                 'trades_count': 1  # Counts of trades under this order
             },
             {
                 'id': 3,
                 'side': 'sell',
                 'ord_type': 'limit',
                 'price': '0.003',
                 'avg_price': '0.0',
                 'state': 'wait',
                 'market': 'otbeth',
                 'created_at': '2017-02-01T00:00:00+08:00',
                 'volume': '100.0',
                 'remaining_volume': '100.0',
                 'executed_volume': '0.0',
                 'trades_count': 0
             }
         ],
         match_querystring=True)
     resp = order.list_orders(market=market)
     assert isinstance(resp, list)
Ejemplo n.º 5
0
 def test_fetch(self):
     order_book = self.order_book
     market = 'otbeth'
     params = {'market': market, 'asks_limit': '1', 'bids_limit': '1'}
     responses.add(
         responses.GET,
         concat_url_and_params(order_book.build_url(order_book.URI),
                               params),
         json={
             'asks': [{
                 'id': 71468,  # Unique order id
                 'side': 'sell',  # Either 'sell' or 'buy'.
                 'ord_type': 'limit',  # Type of order, now only 'limit'.
                 'price':
                 '0.00116',  # Price for each unit. e.g. If you sell/buy 1 OTB at 0.00116 ETH, the price is '0.00116'
                 'avg_price':
                 '0.00116',  # Average execution price, average of price in trades.
                 'state':
                 'wait',  # One of 'wait', 'done', or 'cancel'. An order in 'wait' is an active order, waiting fullfillment; a 'done' order is an order fullfilled; 'cancel' means the order has been cancelled.
                 'market':
                 'otbeth',  # The market in which the order is placed, e.g. 'otbeth'. All available markets can be found at /api/v2/markets.
                 'created_at':
                 '2018-02-04T20:13:01+08:00',  # Order create time in iso8601 format.
                 'volume':
                 '5000.0',  # The amount user want to sell/buy. An order could be partially executed, e.g. an order sell 5000 otb can be matched with a buy 2146.6 otb order, left 2000 otb to be sold; in this case the order's volume would be '5000.0', its remaining_volume would be '2853.4', its executed volume is '2146.6'.
                 'remaining_volume': '2853.4',  # The remaining volume
                 'executed_volume': '2146.6',  # The executed volume
                 'trades_count': 3  # Counts of trades under this order
             }],
             'bids': [{
                 'id': 74866,
                 'side': 'buy',
                 'ord_type': 'limit',
                 'price': '0.00113212',
                 'avg_price': '0.00113212',
                 'state': 'wait',
                 'market': 'otbeth',
                 'created_at': '2018-02-05T20:32:35+08:00',
                 'volume': '849.15791612',
                 'remaining_volume': '845.15791612',
                 'executed_volume': '4.0',
                 'trades_count': 1
             }]
         },
         match_querystring=True)
     resp = order_book.fetch(market=market, asks_limit=1, bids_limit=1)
     assert 'asks' in resp
     assert 'bids' in resp
     assert len(resp['asks']) == 1
     assert len(resp['bids']) == 1
Ejemplo n.º 6
0
 def test_my_trades(self):
     trade = self.trade
     market = 'otbeth'
     params = {
         'access_key':
         'xxx',
         'market':
         market,
         'signature':
         '9dbe0ecdcd3db5030486764dd8b8a4f15a6ee3eae47856f864d11f34c9eba478'
     }
     responses.add(
         responses.GET,
         concat_url_and_params(trade.build_url(trade.MY_TRADES_URI),
                               params),
         json=[
             {
                 'id': 2,  # Unique trade id. 
                 'price':
                 '0.0015',  # Price for each unit. e.g. If you sell/buy 2 OTB at 0.0015 ETH, the price is '0.0015'.
                 'volume':
                 '2.0',  # The amount of base unit. e.g. If you sell/buy 2 OTB at 0.0015 ETH, the volume is '2.0'.
                 'funds':
                 '0.003',  # The amouut of quote unit. e.g. If you sell/buy 2 OTB at 0.0015 ETH, the funds is '0.003' ETH.
                 'market':
                 'otbeth',  # The market in which the order is placed, e.g. 'otbeth'. All available markets can be found at /api/v2/markets.
                 'created_at':
                 '2017-01-31T00:00:00+08:00',  # Trade create time in iso8601 format.
                 'at':
                 1485792000,  # An integer represents the seconds elapsed since Unix epoch.
                 'side': 'bid',  # Either 'bid' or 'ask'.
                 'order_id': 3  # Unique order id. 
             },
             {
                 'id': 1,
                 'price': '0.0018',
                 'volume': '1.0',
                 'funds': '0.0018',
                 'market': 'otbeth',
                 'created_at': '2017-01-30T00:00:00+08:00',
                 'at': 1485705600,
                 'side': 'ask',
                 'order_id': 1
             }
         ],
         match_querystring=True)
     with pytest.raises(ConnectionError):
         trade.my_trades(market=market)
     self.trade_with_auth.my_trades(market=market)
Ejemplo n.º 7
0
 def test_with_pending_trades(self):
     kline = self.kline
     market = 'otbeth'
     params = {
         'market': market,
         'trade_id': 1,
         'period': 1,
     }
     responses.add(
         responses.GET,
         concat_url_and_params(
             kline.build_url(kline.KLINES_WITH_PENDING_TRADES_URI), params),
         json={
             'k': [[
                 1517833860,
                 0.001159,  # K line open price
                 0.001162,  # K line highest price
                 0.001157,  # K line lowest price
                 0.001158,  # K line close price
                 1000  # K line volume
             ]],
             'trades': [{
                 'id': 25073,  # Unique trade id
                 'price': '0.00116',  # Trade's price
                 'volume': '473.3586',  # Trade's volume
                 'funds':
                 '0.549095976',  # Trade's funds, calculated by price * volume
                 'market':
                 'otbeth',  # The market in which the order is placed, e.g. 'otbeth'. All available markets can be found at /api/v2/markets.
                 'created_at':
                 '2018-02-05T20:45:22+08:00',  # Order create time in iso8601 format.
                 'at':
                 1517834722,  # An integer represents the seconds elapsed since Unix epoch till the trade create time.
                 'side':
                 'up'  # Trade's side, 'up' means the price is higher than the previous one, 'down' is lower than the previous one
             }]
         },
         match_querystring=True)
     resp = kline.with_pending_trades(market=market, trade_id=1, period=1)
     assert len(resp) == 2
Ejemplo n.º 8
0
 def test_fetch(self):
     user = self.user
     params = {
         'access_key':
         'xxx',
         'signature':
         'a71c1c5ee28fbd2196ee0bca9e334a18e6053526bd979020ef3839245136c763'
     }
     responses.add(
         responses.GET,
         concat_url_and_params(user.build_url(user.URI), params),
         json={
             'user_name':
             'u1513250056',  # your user name
             'email':
             '*****@*****.**',  # your email
             'accounts': [  # your account information
                 {
                     'currency': 'btc',  # your BTC account
                     'balance': '0.01',  # your current BTC balance amount
                     'locked': '0.001',  # your current BTC locked amount
                     'saving': '0.0'  # your current BTC saving amount
                 },
                 {
                     'currency': 'otb',
                     'balance': '1000.0',
                     'locked': '200.0',
                     'saving': '0.0'
                 },
             ]
         },
         match_querystring=True)
     resp = user.fetch()
     assert 'user_name' in resp
     assert 'email' in resp
     assert 'accounts' in resp