示例#1
0
from typing import Dict, Union, List, Any
import asyncio
import time
from ftx.ftx import FTX
from bot_base_error import APIRequestError, CycleError, PositionCycleError, OrderCycleError, _message
from line import push_message
from setting.settting import PYTHON_ENV, config
from logger import setup_logger

BOT_NAME = config['BOT_NAME']
MARKET = config['MARKET']
TRADABLE = config.getboolean('TRADABLE')
SEC_TO_EXPIRE = config.getfloat('SEC_TO_EXPIRE')
VERBOSE = config.getboolean('VERBOSE')
PUSH_NOTIF = config.getboolean('PUSH_NOTIF')
MAX_POSITION_SIZE = config.getfloat('MAX_POSITION_SIZE')
MAX_ORDER_NUMBER = config.getint('MAX_ORDER_NUMBER')


class BotBase:
    def __init__(self, _market, market_type, api_key, api_secret, subaccount):
        self.ftx = FTX(
            market=_market,
            api_key=api_key,
            api_secret=api_secret,
            subaccount=subaccount)
        self.logger = setup_logger(f'log/{BOT_NAME.lower()}.log')
        self.BOT_NAME: str = BOT_NAME
        self.MAX_ORDER_NUMBER: int = MAX_ORDER_NUMBER
        self.SUBACCOUNT = subaccount
        self.MARKET: str = _market
示例#2
0
from ftx_bot_base import BotBase
from setting.settting import PYTHON_ENV, FTX_API_KEY, FTX_API_SECRET, SUBACCOUNT, config
from twitter.wrapper import keywords_search, user_timeline, strftime_back

# essential
MARKET = config['MARKET']
MARKET_TYPE = config["MARKET_TYPE"]
SEC_TO_EXPIRE = config.getfloat('SEC_TO_EXPIRE')
MAX_POSITION_SIZE = config.getfloat('MAX_POSITION_SIZE')

# custom
SIZE = config.getfloat('SIZE')
USER_ID = config['USER_ID']
KEY_WORDS: List[str] = json.loads(config['KEY_WORDS'])
COND = config['COND']  # `or` OR `and`
CYCLE = config.getboolean('CYCLE')


class Bot(BotBase):
    def __init__(self, market, market_type, api_key, api_secret, subaccount):
        super().__init__(market, market_type, api_key, api_secret, subaccount)
        self.MARKET = MARKET
        # タスクの設定およびイベントループの開始
        loop = asyncio.get_event_loop()
        tasks = [self.run_strategy()]
        if CYCLE:
            tasks = [self.run(10)] + tasks
        # tasks = [self.run(10), self.run_strategy()]
        loop.run_until_complete(asyncio.wait(tasks))

    async def run_strategy(self):
示例#3
0
                                                postOnly=False,
                                                sec_to_expire=10)
            res_result.append(success)

        # if True in res_result:
        #     for sell_price in SELL_ORDER_PRICES:
        #         _, success = await self.place_order(
        #             side='sell',
        #             ord_type='limit',
        #             size=SIZE,
        #             price=sell_price,
        #             ioc=False,
        #             reduceOnly=True,
        #             postOnly=True,
        #             sec_to_expire=10
        #         )
        await asyncio.sleep(interval)


MARKET = config['MARKET']
BOT_NAME = config["BOT_NAME"]
TRADABLE = config.getboolean('TRADABLE')
VERBOSE = config.getboolean("VERBOSE")
MARKET_TYPE = config["MARKET_TYPE"]

SIZE = config["SIZE"]
BUY_ORDER_PRICES = json.loads(config["BUY_ORDER_PRICES"])
SELL_ORDER_PRICES = json.loads(config["SELL_ORDER_PRICES"])

bot = Bot(MARKET, MARKET_TYPE, FTX_API_KEY, FTX_API_SECRET, SUBACCOUNT)