Exemplo n.º 1
0
def send_margin_order(amount, source, symbol, _type, price=0):
    """
    :param amount:
    :param source: 'margin-api'
    :param symbol:
    :param _type: 可选值 {buy-market:市价买, sell-market:市价卖, buy-limit:限价买, sell-limit:限价卖}
    :param price:
    :return:
    """
    try:
        accounts = get_accounts()
        acct_id = accounts['data'][0]['id']
    except BaseException as e:
        print('get acct_id error.%s' % e)
        acct_id = Utils.ACCOUNT_ID

    params = {
        "account-id": acct_id,
        "amount": amount,
        "symbol": symbol,
        "type": _type,
        "source": 'margin-api'
    }
    if price:
        params["price"] = price

    url = '/v1/order/orders/place'
    return Utils.api_key_post(params, url)
Exemplo n.º 2
0
def get_accounts():
    """
    :return:
    """
    path = "/v1/account/accounts"
    params = {}
    return Utils.api_key_get(params, path)
Exemplo n.º 3
0
def orders_matchresults(symbol,
                        types=None,
                        start_date=None,
                        end_date=None,
                        _from=None,
                        direct=None,
                        size=None):
    """

    :param symbol:
    :param types: 可选值 {buy-market:市价买, sell-market:市价卖, buy-limit:限价买, sell-limit:限价卖}
    :param start_date:
    :param end_date:
    :param _from:
    :param direct: 可选值{prev 向前,next 向后}
    :param size:
    :return:
    """
    params = {'symbol': symbol}

    if types:
        params[types] = types
    if start_date:
        params['start-date'] = start_date
    if end_date:
        params['end-date'] = end_date
    if _from:
        params['from'] = _from
    if direct:
        params['direct'] = direct
    if size:
        params['size'] = size
    url = '/v1/order/matchresults'
    return Utils.api_key_get(params, url)
Exemplo n.º 4
0
def loan_orders(symbol,
                currency,
                start_date="",
                end_date="",
                start="",
                direct="",
                size=""):
    """
    :param symbol:
    :param currency:
    :param direct: prev 向前,next 向后
    :return:
    """
    params = {"symbol": symbol, "currency": currency}
    if start_date:
        params["start-date"] = start_date
    if end_date:
        params["end-date"] = end_date
    if start:
        params["from"] = start
    if direct and direct in ["prev", "next"]:
        params["direct"] = direct
    if size:
        params["size"] = size
    url = "/v1/margin/loan-orders"
    return Utils.api_key_get(params, url)
Exemplo n.º 5
0
def get_symbols(long_polling=None):
    """
    """
    params = {}
    if long_polling:
        params['long-polling'] = long_polling
    path = '/v1/common/symbols'
    return Utils.api_key_get(params, path)
Exemplo n.º 6
0
def repay_margin(order_id, amount):
    """
    :param order_id:
    :param amount:
    :return:
    """
    params = {"order-id": order_id, "amount": amount}
    url = "/v1/margin/orders/{0}/repay".format(order_id)
    return Utils.api_key_post(params, url)
Exemplo n.º 7
0
def order_info(order_id):
    """

    :param order_id:
    :return:
    """
    params = {}
    url = "/v1/order/orders/{0}".format(order_id)
    return Utils.api_key_get(params, url)
Exemplo n.º 8
0
def get_ticker(symbol):
    """
    :param symbol:
    :return:
    """
    params = {'symbol': symbol}

    url = Utils.MARKET_URL + '/market/detail/merged'
    return Utils.http_get_request(url, params)
Exemplo n.º 9
0
def get_detail(symbol):
    """
    :param symbol
    :return:
    """
    params = {'symbol': symbol}

    url = Utils.MARKET_URL + '/market/detail'
    return Utils.http_get_request(url, params)
Exemplo n.º 10
0
def order_matchresults(order_id):
    """

    :param order_id:
    :return:
    """
    params = {}
    url = "/v1/order/orders/{0}/matchresults".format(order_id)
    return Utils.api_key_get(params, url)
Exemplo n.º 11
0
def cancel_order(order_id):
    """

    :param order_id:
    :return:
    """
    params = {}
    url = "/v1/order/orders/{0}/submitcancel".format(order_id)
    return Utils.api_key_post(params, url)
Exemplo n.º 12
0
def get_margin(symbol, currency, amount):
    """
    :param amount:
    :param currency:
    :param symbol:
    :return:
    """
    params = {"symbol": symbol, "currency": currency, "amount": amount}
    url = "/v1/margin/orders"
    return Utils.api_key_post(params, url)
Exemplo n.º 13
0
def get_depth(symbol, type):
    """
    :param symbol
    :param type: 可选值:{ percent10, step0, step1, step2, step3, step4, step5 }
    :return:
    """
    params = {'symbol': symbol, 'type': type}

    url = Utils.MARKET_URL + '/market/depth'
    return Utils.http_get_request(url, params)
Exemplo n.º 14
0
def get_kline(symbol, period, size=150):
    """
    :param symbol
    :param period: 可选值:{1min, 5min, 15min, 30min, 60min, 1day, 1mon, 1week, 1year }
    :param size: 可选值: [1,2000]
    :return:
    """
    params = {'symbol': symbol, 'period': period, 'size': size}

    url = Utils.MARKET_URL + '/market/history/kline'
    return Utils.http_get_request(url, params)
Exemplo n.º 15
0
def margin_balance(symbol):
    """
    :param symbol:
    :return:
    """
    params = {}
    url = "/v1/margin/accounts/balance"
    if symbol:
        params['symbol'] = symbol

    return Utils.api_key_get(params, url)
Exemplo n.º 16
0
def margin_to_exchange(symbol, currency, amount):
    """
    :param amount:
    :param currency:
    :param symbol:
    :return:
    """
    params = {"symbol": symbol, "currency": currency, "amount": amount}

    url = "/v1/dw/transfer-out/margin"
    return Utils.api_key_post(params, url)
Exemplo n.º 17
0
def cancel_withdraw(address_id):
    """
    :param address_id:
    :return: {
              "status": "ok",
              "data": 700
            }
    """
    params = {}
    url = '/v1/dw/withdraw-virtual/{0}/cancel'.format(address_id)

    return Utils.api_key_post(params, url)
Exemplo n.º 18
0
def get_balance(acct_id=None):
    """
    :param acct_id
    :return:
    """

    if not acct_id:
        accounts = get_accounts()
        acct_id = accounts['data'][0]['id']

    url = "/v1/account/accounts/{0}/balance".format(acct_id)
    params = {"account-id": acct_id}
    return Utils.api_key_get(params, url)
Exemplo n.º 19
0
def withdraw(address, amount, currency, fee=0, addr_tag=""):
    """
    :param address_id:
    :param amount:
    :param currency:btc, ltc, bcc, eth, etc ...(火币Pro支持的币种)
    :param fee:
    :param addr-tag:
    :return: {
              "status": "ok",
              "data": 700
            }
    """
    params = {
        'address': address,
        'amount': amount,
        "currency": currency,
        "fee": fee,
        "addr-tag": addr_tag
    }
    url = '/v1/dw/withdraw/api/create'

    return Utils.api_key_post(params, url)
Exemplo n.º 20
0
def orders_list(symbol,
                states,
                types=None,
                start_date=None,
                end_date=None,
                _from=None,
                direct=None,
                size=None):
    """

    :param symbol:
    :param states: 可选值 {pre-submitted 准备提交, submitted 已提交, partial-filled 部分成交, partial-canceled 部分成交撤销, filled 完全成交, canceled 已撤销}
    :param types: 可选值 {buy-market:市价买, sell-market:市价卖, buy-limit:限价买, sell-limit:限价卖}
    :param start_date:
    :param end_date:
    :param _from:
    :param direct: 可选值{prev 向前,next 向后}
    :param size:
    :return:
    """
    params = {'symbol': symbol, 'states': states}

    if types:
        params[types] = types
    if start_date:
        params['start-date'] = start_date
    if end_date:
        params['end-date'] = end_date
    if _from:
        params['from'] = _from
    if direct:
        params['direct'] = direct
    if size:
        params['size'] = size
    url = '/v1/order/orders'
    return Utils.api_key_get(params, url)