コード例 #1
0
 def place_order(self, symbol, order_type, amount, price=None):
     """
     下订单,暂时不使用借贷资产交易
     对于iostbtc, huobi的市场价买里面填的是比特币的数量,市场价卖填的是iost的数量
     :param symbol:
     :param order_type:
     :param amount: 限价单表示下单数量,市价买单时表示买多少钱,市价卖单时表示卖多少币 string类型
     :param price: 下单价格,市价单不传该参数
     :return: order_id
     """
     path = '/v1/order/orders/place'
     params = {
         'account-id': self.account_id,
         'amount': amount,
         'source': 'api',
         'symbol': symbol,
         'type': order_type
     }
     if order_type == OrderType.BuyLimit or order_type == OrderType.SellLimit:
         if price is None:
             raise ParamsError('Missing price in limit order')
         params['price'] = price
     order_result = self.api_key_post(params=params, request_path=path)
     if order_result['status'] == 'ok':
         return order_result['data']
     else:
         raise ApiRequestError('Error Place Order, Error Code {}, Error Message {}'.
                               format(order_result['err-code'], order_result['err-msg']))
コード例 #2
0
 def batch_cancel_order(self, order_id_list):
     """
     批量申请取消订单
     注意,返回OK表示撤单请求成功。订单是否撤销成功请调用订单查询接口查询该订单状态
     :param order_id_list:
     :return:
     "success": [
       "1",
       "3"
     ],
     "failed": [
       {
         "err-msg": "记录无效",
         "order-id": "2",
         "err-code": "base-record-invalid"
       }
     ]
     """
     path = '/v1/order/orders/batchcancel'
     params = {'order-ids': order_id_list}
     cancel_result = self.api_key_post(params=params, request_path=path)
     if cancel_result['status'] == 'ok':
         return cancel_result['data']
     else:
         raise ApiRequestError('Error Batch Cancel Order, Error Code {}, Error Message {}'.
                               format(cancel_result['err-code'], cancel_result['err-msg']))
コード例 #3
0
 def batch_query_orders(self, symbol, states, order_type=None, start_date=None, end_date=None,
                        from_order_id=None, direct=None, size=None):
     """
     查询当前委托、历史委托,先只支持
     :param symbol: 交易对
     :param states: str 查询的订单状态组合,使用','分割
     :param order_type: 查询的订单类型组合,使用','分割
     :param start_date: 查询开始日期, 日期格式yyyy-mm-dd
     :param end_date: 查询结束日期, 日期格式yyyy-mm-dd
     :param from_order_id: 查询起始 ID
     :param direct: 查询方向
     :param size: 查询记录大小
     [
         {
           "id": 59378,
           "symbol": "ethusdt",
           "account-id": 100009,
           "amount": "10.1000000000",
           "price": "100.1000000000",
           "created-at": 1494901162595,
           "type": "buy-limit",
           "field-amount": "10.1000000000",
           "field-cash-amount": "1011.0100000000",
           "field-fees": "0.0202000000",
           "finished-at": 1494901400468,
           "user-id": 1000,
           "source": "api",
           "state": "filled",
           "canceled-at": 0,
           "exchange": "huobi",
           "batch": ""
         }
     ]
     :return:
     """
     path = '/v1/order/orders'
     params = {
         'symbol': symbol,
         'states': states
     }
     if order_type:
         params['types'] = order_type
     if start_date:
         params['start-date'] = start_date
     if end_date:
         params['end-date'] = end_date
     if from_order_id:
         params['from'] = from_order_id
     if direct:
         params['direct'] = direct
     if size:
         params['size'] = size
     query_result = self.api_key_get(params=params, request_path=path)
     if query_result['status'] == 'ok':
         return query_result['data']
     else:
         raise ApiRequestError('Error Batch Query Order, Error Code {}, Error Message {}'.
                               format(query_result['err-code'], query_result['err-msg']))
コード例 #4
0
 def query_order(self, order_id):
     """
     获取订单信息
     :param order_id:
     :return: order info
     """
     path = '/v1/order/orders/{order_id}'.format(order_id=order_id)
     order_info = self.api_key_get(dict(), path)
     if order_info['status'] == 'ok':
         return order_info['data']
     else:
         raise ApiRequestError('Error Query Order, Error Code {}, Error Message {}'.
                               format(order_info['err-code'], order_info['err-msg']))
コード例 #5
0
 def cancel_order(self, order_id):
     """
     申请取消订单
     注意,返回OK表示撤单请求成功。订单是否撤销成功请调用订单查询接口查询该订单状态
     :param order_id:
     :return: 申请提交不成功则抛出异常
     """
     path = '/v1/order/orders/{order_id}/submitcancel'.format(order_id=order_id)
     cancel_result = self.api_key_post(params={}, request_path=path)
     if cancel_result['status'] == 'ok':
         return cancel_result['data']
     else:
         raise ApiRequestError('Error Cancel Order, Error Code {}, Error Message {}'.
                               format(cancel_result['err-code'], cancel_result['err-msg']))
コード例 #6
0
 def get_balance(self):
     """
     获取账号币种余额
     :return:
     {
     "id": 100009,
     "type": "spot",
     "state": "working",
     "list": [
       {
         "currency": "usdt",
         "type": "trade",
         "balance": "500009195917.4362872650"
       },
       {
         "currency": "usdt",
         "type": "frozen",
         "balance": "328048.1199920000"
       },
      {
         "currency": "etc",
         "type": "trade",
         "balance": "499999894616.1302471000"
       },
       {
         "currency": "etc",
         "type": "frozen",
         "balance": "9786.6783000000"
       }
      {
         "currency": "eth",
         "type": "trade",
         "balance": "499999894616.1302471000"
       },
       {
         "currency": "eth”,
         "type": "frozen",
         "balance": "9786.6783000000"
       }
     ],
   }
     """
     path = '/v1/account/accounts/{account_id}/balance'.format(account_id=self.account_id)
     balance_result = self.api_key_get(dict(), path)
     if balance_result['status'] == 'ok':
         return balance_result['data']
     else:
         raise ApiRequestError('Error Get Balance, Error Code {}, Error Message {}'.
                               format(balance_result['err-code'], balance_result['err-msg']))
コード例 #7
0
 def get_huobi_point(self):
     """
     获取火币点数
     :return: Decimal
     """
     if not self.huobipoint_account_id:  # 没有火币点卡账号
         return Decimal('0')
     path = '/v1/account/accounts/{account_id}/balance'.format(account_id=self.huobipoint_account_id)
     balance_result = self.api_key_get(dict(), path)
     if balance_result['status'] == 'ok':
         huobi_point_data = balance_result['data']['list']
         res = Decimal('0')
         for item in huobi_point_data:
             if item['currency'] == 'hbpoint':
                 res += Decimal(item['balance'])
         return res
     else:
         raise ApiRequestError('Error Get Balance, Error Code {}, Error Message {}'.
                               format(balance_result['err-code'], balance_result['err-msg']))
コード例 #8
0
 def account_info(self):
     """
     账号信息
     :return:
     [
     {
       "id": 100009,
       "type": "spot",
       "state": "working",
       "user-id": 1000
     }
   ]
     """
     path = '/v1/account/accounts'
     account_result = self.api_key_get(dict(), path)
     if account_result['status'] == 'ok':
         return account_result['data']
     else:
         print account_result
         raise ApiRequestError('Error Get Account, Error Code {}, Error Message {}'.
                               format(account_result['err-code'], account_result['err-msg']))