def __init__(self):
        self.fcoin = Fcoin()
        self.fcoin.auth(config.api_key, config.api_secret)
        self.log = Log("")
        self.symbol = 'ftusdt'
        self.order_id = None
        self.dic_balance = defaultdict(lambda: None)
        self.now_price = 0.0
        self.type = 0
        self.fee = 0.0
        self.count_flag = 0
        self.fall_rise = 0
        self.buy_price = 0.0
        # 正在卖出
        self.in_sell = False
        # 卖出价格
        self.sell_price = 0.0
        # 价格队列
        self.price_queue = []
        # 验证是否卖出价格
        self.check_sell_price = 0.0
        # 总共的增量
        self.total_increment = 0.0
        # 服务器时间
        self.diff_server_time = None

        stategy_quick.set_app(self)
        candle_data.set_app(self)
Beispiel #2
0
    def __init__(self):
        self.fcoin = Fcoin()
        self.fcoin.auth(config.api_key, config.api_secret)

        self.symbol = 'ethusdt'
        self.order_id = None
        self.dic_balance = defaultdict(lambda: None)
        self.time_order = time.time()
Beispiel #3
0
    def __init__(self):
        self.fcoin = Fcoin()
        self.fcoin.auth(config.api_key, config.api_secret)

        self.symbol = 'ftusdt'
        self.order_id = None
        self.dic_balance = defaultdict(lambda: None)
        self.time_order = time.time()
        self.oldprice = self.digits(self.get_ticker(), 6)
Beispiel #4
0
 def __init__(self):
     self.fcoin = Fcoin()
     self.fcoin.auth(config.api_key, config.api_secret)
     self.symbol = config.socket+config.blc
     self.order_id = None
     self.dic_balance = defaultdict(lambda: None)
     self.time_order = time.time()
     self.oldprice = self.get_prices()
     self.socket_sxf=0.0
     self.blc_sxf=0.0
     self.begin_balance=self.get_blance()
Beispiel #5
0
 def __init__(self):
     self.fcoin = Fcoin()
     self.fcoin.auth(config.api_key, config.api_secret)
     self.log = Log("coin")
     self.symbol = 'ftusdt'
     self.order_id = None
     self.dic_balance = defaultdict(lambda: None)
     self.time_order = time.time()
     self.oldprice = [self.digits(self.get_ticker(),6)]
     self.now_price = 0.0
     self.type = 0
     self.fee = 0.0
     self.begin_balance=self.get_blance()
Beispiel #6
0
 def __init__(self):
     self.fcoin = Fcoin()
     self.fcoin.auth(config.api_key, config.api_secret)
     self.log = Log("")
     self.symbol = 'ftusdt'
     self.order_id = None
     self.dic_balance = defaultdict(lambda: None)
     self.now_price = 0.0
     self.type = 0
     self.fee = 0.0
     self.count_flag = 0
     self.fall_rise = 0
     self.buy_price =0.0
     self.sell_price = 0.0
Beispiel #7
0
    def __init__(self):
        # initialize the Fcoin API
        self.fcoin = Fcoin()
        self.fcoin.auth(config.api_key, config.api_secret)

        self.symbol = 'fteth'
        self.order_id = None
        self.dic_balance = defaultdict(lambda: None)
        self.time_order = time.time()
        self.oldprice = [self.digits(self.get_ticker(), 6)]
        # don't quite know what are these
        self.eth_sxf = 0.0
        self.ft_sxf = 0.0
        self.begin_balance = self.get_balance()
Beispiel #8
0
 def __init__(self):
     self.fcoin = Fcoin()
     self.fcoin.auth(config.api_key, config.api_secret)
     self.log = Log("")
     self.symbol = 'ftusdt'
     self.order_id = None
     self.dic_balance = defaultdict(lambda: None)
     self.time_order = time.time()
     self.oldprice = self.digits(self.get_ticker(), 6)
     self.now_price = 0.0
     self.type = 0
     self.fee = 0.0
     self.count_flag = 0
     self.fall_rise = 0
     self.buy_price = 0.0
     self.sell_price = 0.0
     self.executor = ThreadPoolExecutor(max_workers=4)
# -*- coding: utf-8 -*-
"""

@author: 躺着也挣钱
QQ群 :  422922984

"""

import pandas as pd
from fcoin3 import Fcoin
from datetime import datetime
#if python3 use
#from fcoin import Fcoin

fcoin = Fcoin()
fcoin.auth('key ', 'secret')

#取K线数据

ft_usdt = fcoin.get_candle('M3', 'ftusdt')  #M3 = 分钟线,   取150条数据

# 取得当前账户信息
print(fcoin.get_balance())

#
print(fcoin.get_symbols())

print(fcoin.get_currencies())

#
#print(fcoin.buy('fteth', 0.0001, 10))
Beispiel #10
0
 def __init__(self):
     self.fcoin = Fcoin()
     self.fcoin.auth(config.api_key, config.api_secret)
     self.symbol = 'ftusdt'
     self.now_balance = None
     self.buy_balance = None
Beispiel #11
0
    def work(self):
        global gIniQueue

        self.printLog('软件启动!')
        file = open('./ini.json')
        dic = json.loads(file.read())
        apikey = dic['apikey']
        apisecret = dic['apisecret']
        file.close()

        while gFlag:
            try:

                try:
                    ini = gIniQueue.get(block=False)
                except:
                    pass
                else:
                    str1 = ini[0]
                    str2 = ini[1]
                    num = ini[2]
                    str3 = ini[3]
                    myTime = ini[4]
                    num2 = ini[5]
                    buyFlag = ini[6]
                    tel = ini[7]
                    myTime2 = ini[8]
                    num3 = ini[9]

                    # test
                    self.printLog(str(ini))

                # file = open('./mytxt.txt', 'a+')
                fcoin = Fcoin()
                # 主号
                # fcoin.auth('', '')
                # 刷号
                fcoin.auth(apikey, apisecret, tel)
                # os.system('fskl.mp3')
                # 获取账户资产
                data = fcoin.get_balance()
                self.printLog('交易对:%s' % (str3))
                level = fcoin.get_market_depth('L20', str3)
                if ('data' not in data.keys()) or (not data['data']):
                    continue
                for i in data['data']:
                    if i['currency'] == str1:
                        my_usdt = i['balance']
                        self.printLog(str1 + '余额: ' + my_usdt)
                    if i['currency'] == str2:
                        my_ft = i['balance']
                        self.printLog(str2 + '余额: ' + my_ft)

                nowBids = level['data']['bids'][0]
                sumBids = 0
                for i in range(0, len(level['data']['bids'])):
                    if (i % 2) == 0:
                        nowBids = level['data']['bids'][i]
                        self.printLog('本次价格:%s' % (nowBids))
                    else:
                        temp_Num2 = sumBids
                        sumBids += level['data']['bids'][i]
                        self.printLog(
                            '买盘 本次数量总和:%s  本次数量:%s 上次数量总和:%s  总数量:%s' %
                            (sumBids, level['data']['bids'][i], temp_Num2,
                             num3))
                        if sumBids > num3:  #num3是输入的数
                            if i != 0:
                                sumBids = temp_Num2
                            self.printLog('本次数量总和:%s' % (sumBids))
                            if i > 0:
                                nowBids = level['data']['bids'][i - 1]
                                self.printLog('买盘本次价格:%s' % (nowBids))
                            break
                        elif sumBids == num3:
                            break

                nowAsks = level['data']['asks'][0]
                sumAsks = 0
                for i in range(0, len(level['data']['asks'])):
                    if (i % 2) == 0:
                        nowAsks = level['data']['asks'][i]
                        self.printLog('本次价格:%s' % (nowAsks))
                    else:
                        temp_Num2 = sumAsks
                        sumAsks += level['data']['asks'][i]
                        self.printLog(
                            '卖盘 本次数量总和:%s  本次数量:%s  上次数量总和:%s  总数量:%s' %
                            (sumAsks, level['data']['asks'][i], temp_Num2,
                             num3))  #sumAsks+temp_Num2 这是什么意思
                        if sumAsks > num3:  #num3是输入的数
                            if i != 0:
                                sumAsks = temp_Num2
                            self.printLog('本次数量总和:%s' % (sumAsks))
                            if i > 0:
                                nowAsks = level['data']['asks'][i - 1]
                                self.printLog('卖盘本次价格:%s' % (nowAsks))
                            break
                        elif sumAsks == num3:
                            break

                self.printLog('价格小数:%s' % (num2))
                nowResult = round(
                    (round(nowAsks, num2) + round(nowBids, num2)) / 2, num2)

                logStr = str(data)
                # self.printLog(logStr)
                # file.write(logStr+ '\n')

                nowtime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                resultstr = fcoin.get_market_ticker(str3)
                logStr = str(resultstr)
                # self.printLog(logStr)
                # file.write(logStr+ '\n')
                wantstr = resultstr["data"]["ticker"]
                # a是买一价  b是卖一价
                a, b = wantstr[2], wantstr[4]
                # result = round(random.uniform(a, b), num2)
                result = nowResult
                logStr = "random price is:" + str(
                    result) + "now time:" + nowtime
                # self.printLog(logStr)
                # file.write(logStr+ '\n')

                #卖
                if num < float(my_ft):
                    sellop = fcoin.sell(str3, result, str(round(num, 2)))
                    if (sellop is not None) and (sellop['status'] == 0):
                        logStr = r'限价卖出成功 限价卖出%s个%s  卖出价格是%s  当前时间是%s' % (
                            num, str2, result, nowtime)
                        self.printLog(logStr)
                    else:
                        self.printLog(sellop['msg'])

                elif (num > float(my_ft)):

                    if buyFlag:
                        buyop = fcoin.buy_market(
                            str3,
                            round(
                                float(num) * float(result) -
                                float(my_ft) * float(result), 2))
                        tempFlag = False
                        if (buyop is not None) and (buyop['status'] == 3014):
                            tempFlag = True
                            temp_num = int(
                                re.search(r'\d+$', buyop['msg']).group(0))
                            buyop = fcoin.buy_market(str3, str(temp_num))
                            #
                            # if (buyop is not None) and (buyop['status'] == 0):
                            #     # print(num-float(my_ft))*(result/float(my_usdt))
                            #     logStr = r'市价补仓买入成功 市价买入%s个%s的%s  当前时间是%s' % (
                            #     str(round((num - float(my_ft)) * b + (((num - float(my_ft)) * b) * 0.1), 2)), str1,
                            #     str2, nowtime)
                            #     self.printLog(logStr)
                            #     continue
                            # file.write(logStr+ '\n')
                            # else:
                            #     self.printLog(buyop['msg'])
                            #     continue

                        # buyop = fcoin.buy(str3, result,str(float(num-float(my_ft))*(result/float(my_usdt))))
                        # buyop = fcoin.buy(str3, b, str(round(num-float(my_ft)+((num-float(my_ft))*0.1),2)))
                        if (buyop is not None) and (buyop['status'] == 0):
                            # print(num-float(my_ft))*(result/float(my_usdt))
                            if not tempFlag:
                                logStr = r'市价补仓买入成功 市价买入%s个%s的%s  当前时间是%s' % (
                                    str(
                                        round(
                                            float(num) * float(result) -
                                            float(my_ft) * float(result),
                                            2)), str1, str2, nowtime)
                            else:
                                logStr = r'市价补仓买入成功 市价买入%s个%s的%s  当前时间是%s' % (
                                    temp_num, str1, str2, nowtime)
                            self.printLog(logStr)
                            continue
                            # file.write(logStr+ '\n')

                        else:
                            self.printLog(buyop['msg'])
                            continue
                            # time.sleep(60*?)
                        # buyrecord = buyop["data"]

                        # sellop = fcoin.sell(str3, result, str(num))
                        # if (sellop is not None) and (sellop['status']==0):
                        #     logStr = r'限价卖出成功 卖出%s个s%  卖出价格是%s  当前时间是%s' % (num, str2,result, nowtime)
                        #     self.printLog(logStr)
                        #     # file.write(logStr+ '\n')
                        # else:
                        #     self.printLog(sellop['msg'])
                        # if sellop:
                        #     sellrecord = sellop["data"]
                    else:
                        smsResult = sms_send.send('您当前交易对数量不足,请及时处理', tel,
                                                  '44060')
                        #在这等15分钟
                        logStr = r'因为交易对数量不足程序已停止,30分钟后重新启动'
                        time.sleep(60 * 30)

                #买
                if num < float(my_usdt):
                    buyop = fcoin.buy(str3, result, str(round(num, 2)))
                    if (buyop is not None) and (buyop['status'] == 0):
                        logStr = r'限价买入成功 限价买入%s个%s  买入价格是%s  当前时间是%s' % (
                            num, str2, result, nowtime)
                        self.printLog(logStr)
                        # file.write(logStr+ '\n')
                    else:
                        self.printLog(buyop['msg'])

                    # buyrecord = buyop["data"]

                elif num > float(my_usdt):

                    if buyFlag:
                        # sell正常卖  sell_market非正常卖
                        # sellop = fcoin.sell_market(str3,  str(round(num-float(my_ft)+((num-float(my_ft))*0.1),2)))
                        sellop = fcoin.sell_market(
                            str3,
                            round(
                                (float(num) * float(result) - float(my_usdt)),
                                2))
                        # sellop = fcoin.sell_market(str3, num+(num*result)*0.01)
                        tempFlag = False
                        if (sellop is not None) and (sellop['status'] == 3014):
                            tempFlag = True
                            temp_num = int(
                                re.search(r'\d+$', sellop['msg']).group(0))
                            sellop = fcoin.buy_market(str3, str(temp_num))

                        # sellop =fcoin.sell(str3, round(a,num2), str(round(num-float(my_ft)+((num-float(my_ft))*0.1),2)))
                        if (sellop is not None) and (sellop['status'] == 0):
                            if not tempFlag:
                                logStr = r'市价补仓卖出成功 市价卖出%s个%s,当前时间是%s' % (str(
                                    round((float(num) * float(result) -
                                           float(my_usdt)))), str2, nowtime)
                            else:
                                logStr = r'市价补仓卖出成功 市价卖出%s个%s,当前时间是%s' % (
                                    temp_num + temp_num * 0.1, str2, nowtime)
                            self.printLog(logStr)
                            continue
                            # file.write(logStr+ '\n')
                        else:
                            self.printLog(sellop['msg'])
                            continue

                        # if sellop:
                        #     sellrecord = sellop["data"]

                        # buyop = fcoin.buy(str3, result, str(num))
                        # if (buyop is not None) and (buyop['status']==0):
                        #     logStr = r'限价买入成功 限价买入%s个%s  买入价格是%s  当前时间是%s' % (num,str2, result, nowtime)
                        #     self.printLog(logStr)
                        #     # file.write(logStr+ '\n')
                        # else:
                        #     self.printLog(buyop['msg'])
                        # # buyrecord = buyop["data"]
                    else:
                        smsResult = sms_send.send('您当前交易对数量不足,请及时处理', tel,
                                                  '44060')
                        logStr = r'因为交易对数量不足程序已停止,30分钟后重新启动'
                        time.sleep(60 * 30)
                time.sleep(myTime)

                # 获取订单列表
                if buyFlag:
                    rol = fcoin.list_orders(str3, 'submitted,partial_filled')
                    if ('data' not in rol.keys()) or (not rol['data']):
                        continue
                    lastTime = rol['data'][len(rol['data']) - 1]['created_at']
                    lastTime = int(re.sub(r'\d{3}$', '', str(lastTime)))
                    nowTime = int(time.time())

                    if not buyFlag:
                        if (nowTime - lastTime) > (myTime):
                            smsResult = sms_send.send('您当前有超过5分钟未成交的订单,请及时处理',
                                                      tel, '44060')
                    else:
                        # 这里加not true的else
                        if buyFlag:
                            for p in rol["data"]:
                                if p["side"] == "buy":
                                    lastTime = p['created_at']
                                    lastTime = int(
                                        re.sub(r'\d{3}$', '', str(lastTime)))
                                    nowTime = int(time.time())
                                    if (nowTime - lastTime) > (myTime2):
                                        # 市价卖
                                        sellamount = round(
                                            float(p["amount"]) -
                                            float(p["filled_amount"]), 2)
                                        temptemp_result = fcoin.cancel_order(
                                            p["id"])
                                        if (temptemp_result is None) or (
                                                temptemp_result['status'] !=
                                                0):
                                            logStr = "检测到有超过" + str(
                                                myTime2
                                            ) + "秒未完成订单 限价买入订单取消失败,因为已取消,现在时间是:" + nowtime
                                        else:
                                            logStr = "检测到有超过" + str(
                                                myTime2
                                            ) + "秒未完成订单 限价买入订单取消成功,现在时间是:" + nowtime

                                        self.printLog(logStr)
                                        file.write(logStr + '\n')

                                        temptemp_result1 = fcoin.buy_market(
                                            str3, sellamount)
                                        if (temptemp_result1 is None) or (
                                                temptemp_result1['status'] !=
                                                0):
                                            logStr = "检测到有超过" + str(
                                                myTime2
                                            ) + "秒未完成订单 限价买入订单取消失败,因为已取消,现在时间是:" + nowtime
                                        else:
                                            logStr = "检测到有超过" + str(
                                                myTime2
                                            ) + "秒未完成订单 限价买入订单取消成功,现在时间是:" + nowtime

                                        self.printLog(logStr)
                                        # file.write(logStr+ '\n')

                                elif p["side"] == "sell":
                                    lastTime = p['created_at']
                                    lastTime = int(
                                        re.sub(r'\d{3}$', '', str(lastTime)))
                                    nowTime = int(time.time())
                                    if (nowTime - lastTime) > (myTime2):
                                        # 市价卖
                                        sellamount = round(
                                            float(p["amount"]) -
                                            float(p["filled_amount"]), 2)
                                        temptemp_result = fcoin.cancel_order(
                                            p["id"])
                                        if (temptemp_result is None) or (
                                                temptemp_result['status'] !=
                                                0):
                                            logStr = "检测到有超过" + str(
                                                myTime2
                                            ) + "秒未完成订单 限价卖出订单取消失败,因为已取消,现在时间是:" + nowtime
                                        else:
                                            logStr = "检测到有超过" + str(
                                                myTime2
                                            ) + "秒未完成订单 限价卖出订单取消成功,现在时间是:" + nowtime

                                        self.printLog(logStr)
                                        file.write(logStr + '\n')

                                        temptemp_result = fcoin.sell_market(
                                            str3, sellamount)
                                        if (temptemp_result is None) or (
                                                temptemp_result['status'] !=
                                                0):
                                            logStr = "检测到有超过" + str(
                                                myTime2
                                            ) + "秒未完成订单 市价卖出结果失败,因为已取消,现在时间是:" + nowtime
                                        else:
                                            logStr = "检测到有超过" + str(
                                                myTime2
                                            ) + "秒未完成订单  市价卖出结果成功,现在时间是:" + nowtime
                                        self.printLog(logStr)
                                        file.write(logStr + '\n')

                                # elif ['side']=='buy':
                                #     lastTime = p['created_at']
                                #     lastTime = int(re.sub(r'\d{3}$', '', str(lastTime)))
                                #     nowTime = int(time.time())
                                #     if (nowTime - lastTime) > (myTime2):
                                #         # 市价买
                                #         sellamount = round(float(p["amount"]) - float(p["filled_amount"]), 2)
                                #         temptemp_result = fcoin.buy_market(str3, sellamount)
                                #         if (temptemp_result is None) or (temptemp_result['status'] != 0):
                                #             logStr = "检测到有超过" + str(myTime2) + "秒未完成订单 市价买入结果失败,因为已取消,现在时间是:" + nowtime
                                #         else:
                                #             logStr = "检测到有超过" + str(myTime2) + "秒未完成订单  市价买入结果成功,现在时间是:" + nowtime
                                #         self.printLog(logStr)
                                #         file.write(logStr + '\n')
                                # file.write(logStr+ '\n')

                # isemprol = fcoin.list_orders('ftusdt', 'submitted,partial_filled')
                # print(isemprol)
                # time.sleep(myTime)
                # if len(isemprol["data"]) != 0:
                #     flag = False
                #     # os.system('fskl.mp3')
                # file.close()
                # # 执行完等3秒继续循
                # time.sleep(1)

            except Exception as e:
                raise e
                time.sleep(myTime)

        self.printLog('软件结束!')