রিসোর্স লোড হচ্ছে... লোডিং...

OkEX উন্নত এপিআই বৈশিষ্ট্য V.1.1.0 (ফিউচারঃ বাল্ক অর্ডার, অবিলম্বে; TBD) Python2/3

লেখক:ফক্সপ্যান, তারিখ: ২০১৮-০৮-২৯ 13:38:34
ট্যাগঃঠিক আছেপাইথনঠিক আছেএক্সটেন্ট-এপিআই

OkEX উন্নত এপিআই বৈশিষ্ট্যFMZ.com)

প্রাথমিকীকরণ

এই লাইব্রেরীটি কিছু OkEX উচ্চ-স্তরের API বৈশিষ্ট্যগুলিকে একীভূত করে, যা ব্যবহারের আগে প্রাথমিকীকরণ প্রয়োজন।

ওকেএক্স ফিউচার

# OkEX 期货
# future 可选参数 this_week next_week quarter , 不填默认 this_week
OkEXFuture = ext.OkEXFuturePlus(exchange, future=string)    # 创建一个新的接口对象 
# 多个交易所
OkEXFuture = ext.OkEXFuturePlus(exchanges[0], future=string)    # exchanges[这里取决于你的交易所添加在第几个]

ওকেএক্স

# এখনো লিখছি

অর্ডার অপারেশন - ফিউচার

বাল্ক অর্ডার

BulkAdd ((() স্থানীয় অর্ডার তালিকায় নতুন অর্ডার যুক্ত করুন
side price amount 为必填参数
symbol future 不填则使用默认交易对设置
matchPrice 默认为False , 设置为True 使用对手价交易
OkEXFuture.BulkAdd(side=string, price=float, amount=integer, matchPrice=False, symbol=string, future=string) 
BulkClear ((() স্থানীয়ভাবে জমা না দেওয়া অর্ডার মুছে ফেলুন
symbol 指定后可清除指定交易对订单 如不指定则清除所有订单
notify 是否显示日志 默认为显示
OkEXFuture.BulkClear(symbol=string, notify=True)
BulkPost ((() স্থানীয় অর্ডার জমা না
symbol 指定后只提交指定交易对订单 不指定则提交所有订单
future 必须同时指定symbol才能使用 指定后只提交特定交易对的特定合约的订单
OkEXFuture.BulkPost(symbol=string, future=string)
BulkOrders ((() দেখুন স্থানীয় অর্ডার জমা হয়নি
symbol 指定后只查看指定交易对订单 不指定则查看所有订单
future 必须同时指定symbol才能使用 指定后只查看特定交易对的特定合约的订单
OkEXFuture.BulkOrders(symbol=string, future=string)

যোগাযোগ করুন

মেইলবক্সi@fawkex.meটেলিগ্রামফক্সপ্যান

কৌশলগত কাস্টমাইজেশন গ্রহণ করুন

এই লাইব্রেরি সম্পর্কে

OkEX এপিআই নথি

GNU General Public License v3 ব্যবহার করে



#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# encoding: utf-8
#
# OkEX Advanced API Interface for FMZ.com.
#
# Copyright 2018 FawkesPan
# Contact : i@fawkex.me / Telegram@FawkesPan
#
# GNU General Public License v3.0
#

import json
import time

QUOTES = {}
QUOTES['ZH'] = {
    'GREET' : '[OkEX 接口已初始化]  币种: %s 合约: %s. %s',
    'INITF' : '使用的交易所不正确,当前交易所: %s',
    'PARAMERR' : '***传的参数不对 检查你的代码*** %s',
    'NEWORDER' : '[添加订单]  币种: %s 合约: %s 方向: %s 价格: %.4f 数量: %d 张. %s',
    'ORDCOUNT' : '[本次批量发送订单]  总计: %d 条. %s',
    'THISBATCH' : '[信息]  正在处理 币种: %s 合约: %s 条数: %d. %s',
    'ORDSENT' : '[已发送订单]  币种: %s 合约: %s 条数: %d. %s',
    'NEEDSPLIT' : '[信息]  由于单合约单量大于5条 需要进行分片处理. %s',
    'CLEARALL' : '[信息]  已清除所有本地订单. %s',
    'CLEARS' : '[信息]  已清除所有 %s 本地订单. %s',
    'CLEAR' : '[信息]  已清除所有 %s %s 本地订单. %s'
}

COLORS = {
    'DEEPBLUE' : '#1F618D',
    'BLUE' : '#0000FF',
    'LIGHTBLUE' : '#5DADE2',
    'DEEPGREEN' : '#27AE60',
    'GREEN' : '#00FF00',
    'LIGHTGREEN' : '#58D68D',
    'LAPIS' : '#26619C',
    'DEEPRED' : '#CB4335',
    'RED' : '#FF0000',
    'LIGHTRED' : '#EC7063'
}


class OkEXFuture:

    def __init__(self, exchange, future='this_week'):
        self.QUOTES = {}
        exchange.GetCurrency()
        if isinstance(exchange.GetCurrency(), bytes):
            self.symbol = str(exchange.GetCurrency(), "utf-8").lower()
            name = str(exchange.GetName(), "utf-8")
        else:
            self.symbol = exchange.GetCurrency()
            name = exchange.GetName()
        self.IO = exchange.IO
        self.future = future
        self.bulks = {}
        self.bulks[self.symbol] = {}
        self.bulks[self.symbol][self.future] = []
        if 'OKCoin' in str(name):
            Log(QUOTES[LANG]['GREET'] % (self.symbol.upper(),self.future.upper(),COLORS['LAPIS']))
        else:
            Log(QUOTES[LANG]['INITF'] % (name))

    def BulkAdd(self, side=None, price=None, amount=None, matchPrice=False, symbol=None, future=None):
        if type is None or price is None or amount is None:
            Log(QUOTES[LANG]['PARAMERR'] % (COLORS['RED']))
            return False
        side = side.lower()
        if side == 'buy':
            tp = 1
            cl = COLORS['DEEPGREEN']
        if side == 'sell':
            tp = 2
            cl = COLORS['DEEPRED']
        if side == 'closebuy':
            tp = 3
            cl = COLORS['LIGHTRED']
        if side == 'closesell':
            tp = 4
            cl = COLORS['LIGHTGREEN']
        if symbol is None:
            symbol = self.symbol
        if future is None:
            future = self.future

        order = {}
        order['price'] = price
        order['amount'] = amount
        order['type'] = tp

        if matchPrice:
            order['matchPrice'] = 1

        try:
            self.bulks[symbol]
        except KeyError:
            self.bulks[symbol] = {}
        try:
            self.bulks[symbol][future]
        except KeyError:
            self.bulks[symbol][future] = []

        self.bulks[symbol][future].append(order)

        Log(QUOTES[LANG]['NEWORDER'] % (symbol.upper(),future.upper(),side.upper(),price,amount,cl))

        return True

    def BulkOrders(self, symbol=None, future=None):
        if symbol is None:
            return self.bulks
        else:
            if future is None:
                return self.bulks[symbol]
            else:
                return self.bulks[symbol][future]

    def BulkClear(self, symbol=None, future=None, notify=True):
        if symbol is None:
            self.bulks = {}
            if notify:
                Log(QUOTES[LANG]['CLEARALL'] % (COLORS['RED']))
        else:
            if future is None:
                self.bulks[symbol] = {}
                if notify:
                     Log(QUOTES[LANG]['CLEARS'] % (symbol.encode().upper(), COLORS['RED']))
            else:
                self.bulks[symbol][future] = []
                if notify:
                    Log(QUOTES[LANG]['CLEAR'] % (symbol.encode().upper(), future.encode().upper(), COLORS['RED']))
                    #Log(QUOTES[LANG]['CLEAR'] % (symbol.upper(), future.upper(), COLORS['RED']))

        return True

    #exchange.IO("api", "POST", "/api/v1/future_batch_trade.do", "symbol=etc_usd&contract_type=this_week&orders_data="+json.dumps(orders))
    def __post(self, symbol='', future=''):
        count = len(self.bulks[symbol][future])
        orders = self.bulks[symbol][future]
        ret = []
        if count == 0:
            return
        Log(QUOTES[LANG]['THISBATCH'] % (symbol.upper(),future.upper(),count,COLORS['LAPIS']))
        if count <= 5:
            params = 'symbol=%s&contract_type=%s&orders_data=%s' % (symbol, future, json.dumps(orders))
            res = self.IO("api", "POST", "/api/v1/future_batch_trade.do", params)
            ret+=res['order_info']
            Log(QUOTES[LANG]['ORDSENT'] % (symbol.upper(),future.upper(),len(orders),COLORS['LAPIS']))
        if count > 5:
            Log(QUOTES[LANG]['NEEDSPLIT'] % (COLORS['LAPIS']))
            batch = []
            for item in orders:
                batch.append(item)
                if len(batch) == 5:
                    params = 'symbol=%s&contract_type=%s&orders_data=%s' % (symbol, future, json.dumps(batch))
                    res = self.IO("api", "POST", "/api/v1/future_batch_trade.do", params)
                    try:
                        ret+=res['order_info']
                    except:
                        pass
                    Log(QUOTES[LANG]['ORDSENT'] % (symbol.upper(),future.upper(),len(batch),COLORS['LAPIS']))
                    batch = []
                    time.sleep(0.3)               # OkEX限制每秒只能进行三个请求

            params = 'symbol=%s&contract_type=%s&orders_data=%s' % (symbol, future, json.dumps(batch))
            res = self.IO("api", "POST", "/api/v1/future_batch_trade.do", params)
            try:
                ret+=res['order_info']
            except:
                pass
            Log(QUOTES[LANG]['ORDSENT'] % (symbol.upper(),future.upper(),len(batch),COLORS['LAPIS']))

        return ret

    def BulkPost(self, symbol=None, future=None):
        ret = []
        count = 0
        if symbol is None:
            symbols = self.bulks.keys()
            for s in symbols:
                futures = self.bulks[s].keys()
                for f in futures:
                    count+=len(self.bulks[s][f])
                    ret+=self.__post(s, f)
                    time.sleep(0.3)               # OkEX限制每秒只能进行三个请求

            self.BulkClear(notify=False)
        else:
            if future is None:
                futures = self.bulks[symbol].keys()
                for f in futures:
                    count+=len(self.bulks[symbol][f])
                    ret+=self.__post(symbol, f)
                    time.sleep(0.3)               # OkEX限制每秒只能进行三个请求

                self.BulkClear(symbol=symbol, notify=False)
            else:
                count+=len(self.bulks[symbol][future])
                ret+=self.__post(symbol, future)

                self.BulkClear(symbol=symbol, future=future, notify=False)

        Log(QUOTES[LANG]['ORDCOUNT'] % (count,COLORS['LAPIS']))
        return ret

class OkEXSpot:

    def __init__(self, exchange):
        self.IO = exchange.IO

    #TBD

ext.OkEXFuturePlus = OkEXFuture # 导出OkEXFuture Class, 主策略可以通过FuturePlus = ext.OkEXFuturePlus(exchange, future)调用
ext.OkEXSpotPlus = OkEXSpot # 导出OkEXSpot Class, 主策略可以通过SpotPlus = ext.OkEXSpotPlus(exchange)调用

# 模块功能测试
def main():
    LogReset()
    Log(exchange.GetAccount())
    OKEXPlus = ext.OkEXFuturePlus(exchange)
    # 4 Buy 2 Sell 1 next_week
    base_price = exchange.GetTicker()['Last']
    OKEXPlus.BulkAdd("sell", base_price*1.2, 1)
    OKEXPlus.BulkAdd("closebuy", base_price*1.2, 1)
    OKEXPlus.BulkAdd("sell", base_price*1.3, 1)
    OKEXPlus.BulkAdd("buy", base_price*0.7, 1, future='next_week')

    OKEXPlus.BulkClear()

    OKEXPlus.BulkAdd("buy", base_price*0.8, 1)
    OKEXPlus.BulkAdd("closebuy", base_price*1.2, 1)
    OKEXPlus.BulkAdd("sell", base_price*1.3, 1)
    OKEXPlus.BulkAdd("buy", base_price*0.7, 1, future='next_week')

    OKEXPlus.BulkClear(symbol=(exchange.GetCurrency()).lower(),future='this_week')
    OKEXPlus.BulkClear(symbol=(exchange.GetCurrency()).lower(),future='next_week')

    OKEXPlus.BulkAdd("buy", base_price*0.8, 1)
    OKEXPlus.BulkAdd("buy", base_price*0.7, 1, future='next_week')
    OKEXPlus.BulkClear(symbol=(exchange.GetCurrency()).lower())

    OKEXPlus.BulkAdd("buy", base_price*0.8, 1)
    OKEXPlus.BulkAdd("buy", base_price*0.81, 1)
    OKEXPlus.BulkAdd("buy", base_price*0.82, 1)
    OKEXPlus.BulkAdd("closesell", base_price*0.8, 1)
    OKEXPlus.BulkAdd("sell", base_price*1.2, 1)
    OKEXPlus.BulkAdd("closebuy", base_price*1.2, 1)
    OKEXPlus.BulkAdd("sell", base_price*1.3, 1)
    OKEXPlus.BulkAdd("buy", base_price*0.7, 1, future='next_week')

    Log(OKEXPlus.BulkOrders())
    for item in OKEXPlus.BulkPost():
        Log(str(item))
    Log(OKEXPlus.BulkOrders())


সম্পর্কিত

আরো

যর্টিদয়া করে, আপনি কি এইটা ব্যবহার করতে চান?

যর্টিদয়া করে, আপনি কি এইটা ব্যবহার করতে চান?

ফক্সপ্যান https://www.fmz.com/robot/116112