Beispiel #1
0
async def okex_spot_k_line(api_key: str,
                           secret_key: str,
                           symbol: str,
                           k_line_type: str,
                           size: int = None,
                           since: int = None):
    """
    获取币币K线数据,每个周期数据条数2000左右
    :param api_key:
    :param secret_key:
    :param symbol: 交易对
    :param k_line_type: 1min/3min/5min/15min/30min/1day/3day/1week/1hour/2hour/4hour/6hour/12hour
    :param size: 获取数据的条数,默认全部获取
    :param since: 时间戳,返回时间戳以后的数据,默认全部获取
    :return: is_ok, status_code, response, result
    """
    # 校验参数
    if k_line_type not in K_LINE_TYPE:
        return PARAMS_ERROR
    try:
        if size:
            size = int(size)
        if since:
            since = int(since)
    except Exception as e:
        logger.error(e)
        return PARAMS_ERROR
    okex_spot = OKExSpot(api_key, secret_key)

    return await okex_spot.k_line(symbol, k_line_type, size, since)
Beispiel #2
0
async def okex_account_records(api_key: str, secret_key: str, symbol: str,
                               account_type: int, current_page: int,
                               page_length: int):
    """
    获取用户提现/充值记录
    :param api_key:
    :param secret_key:
    :param symbol:
    :param account_type:
    :param current_page:
    :param page_length:
    :return:
    """
    try:
        account_type = int(account_type)
        current_page = int(current_page)
        page_length = int(page_length)
    except Exception as e:
        logger.error(e)
        return PARAMS_ERROR

    if account_type not in ACCOUNT_RECORDS_TYPE:
        return PARAMS_ERROR
    if page_length < 0 or page_length > 50:
        return PARAMS_ERROR

    okex_spot = OKExSpot(api_key, secret_key)
    return await okex_spot.account_records(symbol, account_type, current_page,
                                           page_length)
Beispiel #3
0
async def okex_funds_transfer(api_key: str, secret_key: str, symbol: str,
                              amount: int, funds_from: int, funds_to: int):
    """
    资金划转
    :param api_key:
    :param secret_key:
    :param symbol:
    :param amount:
    :param funds_from:
    :param funds_to:
    :return:
    """
    try:
        amount = int(amount)
        funds_from = int(funds_from)
        funds_to = int(funds_to)
    except Exception as e:
        logger.error(e)
        return PARAMS_ERROR
    if funds_to not in FUNDS_TRANSFER_TYPE:
        return PARAMS_ERROR
    if funds_from not in FUNDS_TRANSFER_TYPE:
        return PARAMS_ERROR

    okex_spot = OKExSpot(api_key, secret_key)
    return await okex_spot.account_records(symbol, amount, funds_from,
                                           funds_to)
Beispiel #4
0
async def okex_spot_order_history(api_key: str, secret_key: str, symbol: str,
                                  status: int, current_page: int,
                                  page_length: int):
    """
    获取历史订单信息 只返回最近两天的信息
    :param api_key:
    :param secret_key:
    :param symbol:
    :param status:查询状态 0:未完成的订单 1:已经完成的订单(最近两天的数据)
    :param current_page:当前页数
    :param page_length:每页数据条数,最多不超过200
    :return:
    """
    # 校验参数
    try:
        status = int(status)
        current_page = int(current_page)
        page_length = int(page_length)
    except Exception as e:
        logger.error(e)
        return PARAMS_ERROR
    if status not in ORDER_HISTORY_STATUS:
        return PARAMS_ERROR
    if page_length > 200 or page_length < 0:
        return PARAMS_ERROR

    okex_spot = OKExSpot(api_key, secret_key)
    return await okex_spot.order_history(symbol, status, current_page,
                                         page_length)
Beispiel #5
0
async def okex_withdraw(api_key: str,
                        secret_key: str,
                        symbol: str,
                        charge_fee: float,
                        trade_pwd: str,
                        withdraw_address: str,
                        withdraw_amount: float,
                        target: str = 'OKEX'):
    """
    提币
    :param api_key
    :param secret_key
    :param symbol: 交易对
    :param charge_fee: 网路手续费 BTC[0.002,0.005] LTC[0.001,0.2] ETH[0.01] ETC[0.0001,0.2] BCH范围 [0.0005,0.002]
    :param trade_pwd: 交易密码
    :param withdraw_address: 提币认证地址
    :param withdraw_amount: 提币数量
    :param target: 地址类型
    :return:
    """
    try:
        charge_fee = float(charge_fee)
        withdraw_amount = float(withdraw_amount)
    except Exception as e:
        logger.error(e)
        return PARAMS_ERROR

    okex_spot = OKExSpot(api_key, secret_key)
    return await okex_spot.withdraw(symbol, charge_fee, trade_pwd,
                                    withdraw_address, withdraw_amount, target)
Beispiel #6
0
async def okex_spot_batch_trade(api_key: str,
                                secret_key: str,
                                symbol: str,
                                orders_data: str,
                                trade_type=None):
    """
    批量下单,访问频率20次/2秒 最大下单量为5
    :param api_key:
    :param secret_key:
    :param symbol:交易对
    :param trade_type: buy/sell/
    :param orders_data: '[{价格,数量,买卖类型},{}]'
    :return: is_ok, status_code, response, result
    """
    # 校验参数
    if trade_type:
        if trade_type not in BATCH_TRADE_TYPE:
            return PARAMS_ERROR
    try:
        if len(re.findall('price', orders_data)) > 5 or len(
                re.findall('price', orders_data)) < 1:
            return PARAMS_ERROR
    except Exception as e:
        logger.error(e)
        return PARAMS_ERROR

    okex_spot = OKExSpot(api_key, secret_key)
    return await okex_spot.batch_trade(symbol, orders_data, trade_type)
Beispiel #7
0
async def okex_spot_place_order(api_key: str, secret_key: str, symbol: str,
                                trade_type: str, amount: str, price: str,
                                **kwargs):
    """
    下单交易,访问频率20次/2秒
    市价买单不传amount,市价买单需传peice作为买入总金额
    市价卖单不传price,
    卖单 amount一位小数
    卖单
    :param api_key:
    :param secret_key:
    :param symbol: 交易对
    :param trade_type: 买卖类型
    :param price: 下单价格,
    :param amount: 交易数量,
    :return: is_ok, status_code, response, result
    """
    # 校验参数
    if trade_type not in TRADE_TYPE:
        return PARAMS_ERROR
    try:
        price = float(price)
        amount = round(float(amount), 1)
    except Exception as e:
        logger.error(e)
        return PARAMS_ERROR
    if trade_type == 'sell_market':
        price = None
    if trade_type == 'buy_market':
        amount = None

    okex_spot = OKExSpot(api_key, secret_key)

    return await okex_spot.trade(symbol, trade_type, price, amount)
Beispiel #8
0
async def okex_wallet_info(api_key: str, secret_key: str):
    """
    获取用户钱包账户信息
    :param api_key:
    :param secret_key:
    :return:
    """
    okex_spot = OKExSpot(api_key, secret_key)
    return await okex_spot.wallet_info()
Beispiel #9
0
async def okex_spot_ticker(api_key: str, secret_key: str, symbol: str):
    """
    获取币币交易行情
    :param api_key:
    :param secret_key:
    :param symbol: 交易对
    :return: is_ok, status_code, response, result
    """
    # 校验参数
    okex_spot = OKExSpot(api_key, secret_key)
    return await okex_spot.ticker(symbol)
Beispiel #10
0
async def okex_spot_user_info(
    api_key: str,
    secret_key: str,
):
    """
    获取用户信息,访问频率6次/2秒
    :param api_key:
    :param secret_key:
    :return:is_ok, status_code, response, result
    """
    okex_spot = OKExSpot(api_key, secret_key)

    return await okex_spot.user_info()
Beispiel #11
0
async def okex_withdraw_info(api_key: str, secret_key: str, symbol: str,
                             withdraw_id: str):
    """
    查询提币BTC/LTC/ETH/ETC/BCH信息
    :param api_key
    :param secret_key
    :param symbol:
    :param withdraw_id:
    :return:
    """
    try:
        int(withdraw_id)
    except Exception as e:
        logger.error(e)
        return PARAMS_ERROR
    okex_spot = OKExSpot(api_key, secret_key)
    return await okex_spot.withdraw_info(symbol, withdraw_id)
Beispiel #12
0
async def okex_spot_order_info(api_key: str, secret_key: str, symbol: str,
                               order_id: str):
    """
    获取用户的订单信息 访问频率 20次/2秒(未成交)
    :param api_key
    :param secret_key
    :param symbol:
    :param order_id: -1:未完成订单,否则查询相应订单号的订单
    :return:
    """
    try:
        order_id = int(order_id)
    except Exception as e:
        logger.error(e)
        return PARAMS_ERROR
    okex_spot = OKExSpot(api_key, secret_key)
    return await okex_spot.order_info(symbol, order_id)
Beispiel #13
0
async def okex_spot_cancel_order(api_key: str, secret_key: str, order_id: str,
                                 symbol: str):
    """
    撤销订单 访问频率20次/2秒 一次最多三个
    :param api_key
    :param secret_key
    :param symbol: 交易对
    :param order_id: 订单ID,多个订单已','分隔
    :return: is_ok, status_code, response, result
    """
    # 校验参数
    try:
        if len(re.findall(',', order_id)) > 3:
            return PARAMS_ERROR
    except Exception as e:
        logger.error(e)
        return PARAMS_ERROR

    okex_spot = OKExSpot(api_key, secret_key)
    return await okex_spot.cancel_order(symbol, order_id)
Beispiel #14
0
async def okex_spot_trades_info(api_key: str,
                                secret_key: str,
                                symbol: str,
                                since: int = None):
    """
    获取币币交易信息,60条
    :param api_key:
    :param secret_key:
    :param symbol: 交易对
    :param since: tid:交易记录ID(返回数据不包括当前tid值,最多返回60条数据)
    :return:is_ok, status_code, response, result
    """
    if since:
        try:
            since = int(since)
            if since < 0:
                return PARAMS_ERROR
        except Exception as e:
            logger.error(e)
            return PARAMS_ERROR
    okex_spot = OKExSpot(api_key, secret_key)

    return await okex_spot.trades_info(symbol, since)
Beispiel #15
0
async def okex_spot_orders_info(api_key: str, secret_key: str, symbol: str,
                                orders_id: str, info_type: int):
    """
    批量获取用户订单 访问频率20次/2次 最多50个订单
    :param api_key:
    :param secret_key:
    :param symbol:
    :param orders_id:多个订单ID中间以","分隔,一次最多允许查询50个订单
    :param info_type:查询类型 0:未完成的订单 1:已经完成的订单
    :return:
    """
    # 校验参数
    if info_type not in ORDERS_INFO_TYPE:
        return PARAMS_ERROR
    try:
        if len(re.findall(',', orders_id)) > 50:
            return PARAMS_ERROR
    except Exception as e:
        logger.error(e)
        return PARAMS_ERROR

    okex_spot = OKExSpot(api_key, secret_key)
    return await okex_spot.orders_info(symbol, orders_id, info_type)
Beispiel #16
0
async def okex_spot_depth(api_key: str,
                          secret_key: str,
                          symbol: str,
                          size: int = 200):
    """
    获取币币市场深度
    :param api_key:
    :param secret_key:
    :param symbol: 交易对
    :param size: value:1-200
    :return: is_ok, status_code, response, result
    """
    # 校验参数
    try:
        if 1 <= size <= 200:
            size = size
        else:
            return PARAMS_ERROR
    except Exception as e:
        logger.error(e)
        return PARAMS_ERROR
    okex_spot = OKExSpot(api_key, secret_key)

    return await okex_spot.depth(symbol, size=size)