Пример #1
0
    def __init__(self, r0obj):
        self.r0obj = r0obj
        self.HOST = "127.0.0.1"
        self.dest_port = 5020
        self.verbosity = self.r0obj.log_level

        self.logger = get_logger("Dumbfuzz", self.verbosity)
Пример #2
0
    def __init__(self, parent: QWidget = None):
        super(ApikeysManagerWindow, self).__init__(parent=parent)
        self._logger = get_logger(__name__)
        self._logger.debug('Constructed window!')
        self.mainwindow = None
        self.emcore = get_core_instance()

        self.setMinimumSize(500, 200)
        self.icon = QIcon('img/pyevemon.png')
        self.setWindowIcon(self.icon)
        self.setWindowTitle(self.tr('API Keys Manager'))

        self._layout = QVBoxLayout()
        self.setLayout(self._layout)

        # labels
        self._lbl_apikeys = QLabel(self.tr('API keys:'), self)

        # buttons
        self._btn_add_apikey = QPushButton(self.tr('Add API key...'), self)
        self._btn_add_apikey.clicked.connect(self.on_click_add_apikey)

        # layouts
        self._layout_top1 = QHBoxLayout()
        self._layout_top1.addWidget(self._lbl_apikeys)
        self._layout_top1.addStretch()
        self._layout_top1.addWidget(self._btn_add_apikey)

        self._layout.addLayout(self._layout_top1, 0)
        self._layout.setSizeConstraint(QLayout.SetMinimumSize)

        self.load_apikeys()
        self.show()
Пример #3
0
 def __init__(self, host, port, passwd, queue, mode,
              log=None, loop=None):
     self.host = host
     self.port = port
     self.passwd = passwd
     self.queue = queue
     self.mode = mode
     self.loop = loop
     self._auto_restart = True
     self._run = False
     if self.loop is None:
         self.loop = asyncio.get_event_loop()
     self.is_ready = asyncio.Event(loop=self.loop)
     if log is None:
         hdr = '[%s:%d %s]' % \
             (self.host, self.port, self.MODE_NAMES[self.mode])
         self.log = \
             get_logger(header=hdr,
                        color=self.MODE_COLORS[self.mode])
     else:
         self.log = log
     self.reader = None
     self.writer = None
     self.protocol = None
     self.transport = None
Пример #4
0
    def get(self, request: HttpRequest, *args, **kwargs):
        logger = get_logger()
        logger.bind(get=request.GET).info("cb GET data")

        form = TaoBaoCbForm(request.GET)
        data = form.to_data()
        logger.bind(data=data).info("cb parsed data")

        if data is None:
            return self.render_to_response({"success": False})

        logic = TaoBaoLogic(logger)
        try:
            ret = logic.android_try_bind(data.code, data.state)
            if ret:
                ctx = {"success": True}
            else:
                ctx = {"success": False}
            return self.render_to_response(ctx)
        except Exception as e:
            tb = traceback.extract_tb(e.__traceback__)
            logger.bind(tb=tb, exce=e).error("内部处理错误")

            ctx = {"success": False}
            return self.render_to_response(ctx)
Пример #5
0
    def __init__(self, sysobj):
        self.sysobj = sysobj
        self.target = self.sysobj.target
        self.compile_commands = self.sysobj.compile_commands
        self.verbosity = self.sysobj.log_level

        self.logger = get_logger("Bear", self.verbosity)
        self.output_path = os.path.join(os.getcwd(), "out/preprocessed/")
Пример #6
0
    def __init__(self, r0obj):
        self.r0obj = r0obj
        self.HOST = "127.0.0.1"
        self.src_port = 49901
        self.dest_port = 5020
        self.verbosity = self.r0obj.log_level

        self.logger = get_logger("Packgen", self.verbosity)
Пример #7
0
async def ztk_keyword() -> KeywordResponseModel:
    logger = get_logger()
    ztk = get_ztk_api_v2(logger)

    @api_inner_wrapper(logger)
    async def inner():
        data = await ztk.keyword()
        return ApiResp(data=data).to_dict()

    return await inner
Пример #8
0
async def ztk_keyword(request: HttpRequest) -> KeywordResponseModel:
    logger = get_logger()
    ztk = await get_ztk_std_api(logger)

    @api_inner_wrapper(logger)
    async def inner():
        data = await ztk.keyword()
        return ApiResp(data=data).to_dict()

    return await inner
Пример #9
0
async def sys_auth(request: HttpRequest) -> SysConfigResponseModel:
    logger = get_logger()

    @api_inner_wrapper(logger)
    async def inner():
        logic = SysLogic(logger)
        data = await logic.get_sys_config()
        return ApiResp.from_data(data)

    return await inner
Пример #10
0
    def __init__(self, r0obj):
        #needed pcap
        self.r0obj = r0obj
        self.input = self.r0obj.seed
        self.layer = "TCP"
        self.field = "load"
        self.PORT = 502
        self.verbosity = self.r0obj.log_level

        self.logger = get_logger("Extractor", self.verbosity)
Пример #11
0
async def user_cancel(request: HttpRequest,
                      g: UserTokenForm) -> UserCancelResponseModel:
    logger = get_logger()

    @api_inner_wrapper(logger)
    async def inner():
        user = UserV2Logic(logger)
        ret = await user.cancel_user_account(g.token)
        return ApiResp.from_data(ret)

    return await inner
Пример #12
0
async def auth_url(request: HttpRequest,
                   g: AuthUrlForm) -> TaoBaoAuthUrlResponseModel:
    logger = get_logger()

    @api_inner_wrapper(logger)
    async def inner():
        logic = TaoBaoLogic(logger)
        data = await logic.get_bind_channel_id_url(g.token)
        return ApiResp.from_data(data)

    return await inner
Пример #13
0
async def user_profile(request: HttpRequest,
                       g: UserTokenForm) -> UserProfileResponseModel:
    logger = get_logger()

    @api_ensure_login(g.token, logger)
    async def inner(user: User):
        ul = UserLogic(logger)
        data = await ul.profile(user=user)
        return ApiResp.from_data(data)

    return await inner
Пример #14
0
async def ztk_search(request: HttpRequest, f: SearchForm) -> SearchResponseModel:
    logger = get_logger()
    ztk = get_ztk_api_v2(logger)

    @api_inner_wrapper(logger)
    async def inner():
        data = f.to_data()
        j = await ztk.search(data)
        return ApiResp.from_data(j).to_dict()

    return await inner
Пример #15
0
async def ztk_suggest(request: HttpRequest, content: str) -> SuggestResponseModel:
    logger = get_logger()
    ztk = get_ztk_api_v2(logger)

    @api_inner_wrapper(logger)
    async def inner():
        args = SuggestArgs(content=content)
        j = await ztk.suggest(args)
        return ApiResp.from_data(j).to_dict()

    return await inner
Пример #16
0
async def user_tb(request: HttpRequest,
                  g: UserTokenForm) -> UserTbResponseModel:
    logger = get_logger()

    @api_inner_wrapper(logger)
    async def inner():
        logic = UserV2Logic(logger)
        await logic.ensure_bind_tb(g.token)
        return ApiResp.from_data(True)

    return await inner
Пример #17
0
async def guess_you_like(request: HttpRequest,
                         g: GuessYouLikeForm) -> GuessYouLikeResponseModel:
    logger = get_logger()
    ztk = await get_ztk_std_api(logger)

    @api_inner_wrapper(logger)
    async def inner():
        args = g.to_data()
        j = await ztk.guess_you_like(args)
        return ApiResp.from_data(j)

    return await inner
Пример #18
0
async def tmall_shang_pin(request: HttpRequest,
                          g: TMallShangPinForm) -> TMallShangPinResponseModel:
    logger = get_logger()
    ztk = await get_ztk_std_api(logger)

    @api_inner_wrapper(logger)
    async def inner():
        data = g.to_data()
        j = await ztk.tmall_shang_pin(data)
        return ApiResp.from_data(j).to_dict()

    return await inner
Пример #19
0
    def __init__(self, base_symbol, quote_symbol, trade_api, lever_rate=1):
        self.base_symbol = base_symbol
        self.quote_symbol = quote_symbol
        self.lever_rate = lever_rate
        self.df_minute_bars: pd.DataFrame = None
        self.orders: Sequence[object] = list()
        self.orders_dict: Dict[str:object] = dict()

        self.trade_api = trade_api

        # logger
        self.logger = get_logger('strategy')
Пример #20
0
async def ju_hua_suan(request: HttpRequest,
                      g: JuHuaSuanForm) -> JuHuanSuanResponseModel:
    logger = get_logger()
    ztk = get_ztk_api_v2(logger)

    @api_inner_wrapper(logger)
    async def inner():
        data = g.to_data()
        j = await ztk.ju_hua_suan(data)
        return ApiResp.from_data(j).to_dict()

    return await inner
Пример #21
0
async def tmall_chao_shi(request: HttpRequest,
                         g: TMallChaoShiForm) -> TMallChaoShiResponseModel:
    logger = get_logger()
    ztk = get_ztk_api_v2(logger)

    @api_inner_wrapper(logger)
    async def inner():
        data = g.to_data()
        j = await ztk.tmall_chao_shi(data)
        return ApiResp.from_data(j).to_dict()

    return await inner
Пример #22
0
async def nine_nine(request: HttpRequest,
                    g: NineNineForm) -> NineNineResponseModel:
    logger = get_logger()
    ztk = get_ztk_api_v2(logger)

    @api_inner_wrapper(logger)
    async def inner():
        data = g.to_data()
        j = await ztk.nine_nine(data)
        return ApiResp.from_data(j).to_dict()

    return await inner
Пример #23
0
async def dtk_top_100() -> DtkTop100ResponseModel:
    logger = get_logger()
    dtk = await get_dtk_async()

    @api_inner_wrapper(logger)
    async def inner():
        j = await dtk.category_get_top100()
        if j is None:
            return ApiResp.from_errno(AppErrno.dtk_error)
        return ApiResp.from_data(j.hotWords)

    return await inner
Пример #24
0
async def user_auth(
    request: HttpRequest, g: UserNativeAuthForm
) -> UserAuthResponseModel:
    logger = get_logger()
    ul = UserV2Logic(logger)
    token = await ul.auth(username=g.username, password=g.password)
    if token is None:
        return UserAuthResponseModel(
            errno=AppErrno.auth_failed, errmsg=str(AppErrno.auth_failed)
        )
    return UserAuthResponseModel(
        errno=AppErrno.success, errmsg="", data=UserNativeAuthDataModel(token=token)
    )
Пример #25
0
    def __init__(self, sysobj):
        self.sysobj = sysobj
        self.target = sysobj.target
        self.files = os.listdir(self.target)
        self.logger = get_logger("Extractor", sysobj.log_level)

        self.ioctls = []
        self.target_dir = join(os.getcwd(), "out/preprocessed/",
                               basename(self.target))

        if not exists(self.target_dir):
            os.mkdir(self.target_dir)
        self.ioctl_file = ""
Пример #26
0
async def share_android_relation_tkl(
        request: HttpRequest,
        g: ShareItemTklForm) -> ShareItemTklResponseModel:
    logger = get_logger()

    @api_inner_wrapper(logger)
    async def inner():
        logic = ShareLogic(logger)
        tkl = await logic.share_item(g.item_id, g.token, False)
        logger.bind(tkl=tkl, item_id=g.item_id).info("create tkl")
        return ApiResp.from_data(tkl)

    return await inner
Пример #27
0
async def bang_dan_tui_jian(
        request: HttpRequest,
        g: BangDanTuiJianForm) -> BangDanTuiJianResponseModel:
    logger = get_logger()
    ztk = get_ztk_api_v2(logger)

    @api_inner_wrapper(logger)
    async def inner():
        data = g.to_data()
        j = await ztk.bang_dan_tui_jian(data)
        return ApiResp.from_data(j).to_dict()

    return await inner
Пример #28
0
async def dtk_super_category(
    request: HttpRequest, ) -> DtkSuperCategoryResponseModel:
    logger = get_logger()
    dtk = await get_dtk_async()

    @api_inner_wrapper(logger)
    async def inner():
        j = await dtk.category_get_super_category()
        if j is None:
            return ApiResp.from_errno(AppErrno.dtk_error)
        return ApiResp.from_data(j)

    return await inner
Пример #29
0
async def dtk_goods_detail(
        request: HttpRequest,
        args: GoodsGetGoodsDetailsArgs) -> DtkGoodsDetailResponseModel:
    logger = get_logger()
    dtk = await get_dtk_async()

    @api_inner_wrapper(logger)
    async def inner():
        j = await dtk.goods_get_goods_details(args)
        if j is None:
            return ApiResp.from_errno(AppErrno.dtk_error)
        return ApiResp.from_data(j)

    return await inner
Пример #30
0
async def dtk_goods_nine_op_goods_list(
        request: HttpRequest,
        g: GoodsNineOpGoodsListArgs) -> GenericItemListResponseModel:
    logger = get_logger()
    dtk = await get_dtk_std()

    @api_inner_wrapper(logger)
    async def inner():
        j = await dtk.goods_nine_op_goods_list(g)
        if j is None:
            return ApiResp.from_errno(AppErrno.dtk_error)
        return ApiResp.from_data(j)

    return await inner
Пример #31
0
async def dtk_ranking_list(
        request: HttpRequest,
        args: GoodsGetRankingListArgs) -> GenericItemListResponseModel:
    logger = get_logger()
    dtk: DtkStdApi = await get_dtk_std()

    @api_inner_wrapper(logger)
    async def inner():
        j = await dtk.goods_get_ranking_list(args)
        if j is None:
            return ApiResp.from_errno(AppErrno.dtk_error)
        return ApiResp.from_data(j)

    return await inner
Пример #32
0
    def __init__(self, app, config_file=None, loop=None):
        self.log = get_logger(LOG_INFO, '[CONF]', COLOR_YELLOW)
        self.log('Initializing configuration')

        # queue for websocket listeners
        self._websockets = []

        self.app = app
        if config_file is None:
            self.config_file = CONFIG_FILE_NAME

        self.web = webserver.WebServer(config=self)
        self.tls = tls.Tls(self)
        self.systems = systems.Systems(self)

        self.load_file(self.config_file)
Пример #33
0
 def __init__(self, *args, **kwargs):
     self.log = None
     if len(args) == 1:
         obj = args[0]
         if isinstance(obj, system.System):
             self.system = obj
             self.log = obj.log
     elif len(args) == 3:
         if isinstance(args[0], str) and \
            isinstance(args[1], int) and \
            isinstance(args[2], str):
             self.address = args[0]
             self.port = args[1]
             self.passwd = args[2]
             self.available = True
     if self.log is None:
         self.log = get_logger(LOG_INFO, color=COLOR_LT_RED)
     self.log("Invalid parameters on creating Gateway")
     self.log(args)
     self.log(kwargs)
Пример #34
0
# -*- coding: utf-8 -*-
from json import JSONDecodeError
from time import sleep
from functools import partial

import pandas as pd
import quandl
import quandl.errors.quandl_error

import core.utility
from core.contract_store import Store, QuotesType, columns_mapping
from data.data_provider import DataProvider
from core.logger import get_logger

logger = get_logger('quandl_provider')


class QuandlProvider(DataProvider):

    def __init__(self):
        super().__init__()
        self.library = 'quandl'
        self.api_delay = 0
        self.quotes_formats = { QuotesType.futures: self._format_future,
                                QuotesType.currency: self._format_currency,
                                QuotesType.others: self._format_other}

    def connect(self):
        """
        Quandl doesn't require connection. Api key is specified in config.settings
        """
Пример #35
0
import datetime
import pandas as pd
import config.settings
import config.currencies
from core import data_feed
from core.logger import get_logger

logger = get_logger('currency')


class Currency(object):
    """
    Object representing currency exchange rate
    """

    @classmethod
    def load_all(cls):
        """Load all currencies in the system into a dictionary"""
        return {v['code']: Currency(v['code']) for v in config.currencies.currencies_definitions}

    def __init__(self, code):
        """Initialise the currency with defaults, taking overrides from the config/currencies.py"""
        self.code = code
        self.ib_symbol = None
        self.quandl_symbol = None
        self.bitmex_symbol = None
        self.currency_data = ['ib', 'quandl']
        kwargs = config.currencies.currencies_all[code]
        for key, value in kwargs.items():
            setattr(self, key, value)
Пример #36
0
 def __init__ (self):
     self.log = get_logger(header='[DEVS]', color=COLOR_LT_MAGENTA)
     self.log("Initializing device database")
     # TODO: better path handling
     self.conn = sqlite3.connect("device_catalog.db")
Пример #37
0
import numpy as np
import pandas as pd
from functools import lru_cache

import config.strategy
from core.instrument import Instrument
from core.utility import draw_sample, sharpe
from trading.accountcurve import accountCurve
import config.settings
import trading.bootstrap_portfolio as bp
import seaborn
import pyprind
from multiprocessing_on_dill import Pool
from contextlib import closing
from core.logger import get_logger
logger = get_logger('portfolio')


class Portfolio(object):
    """
    Portfolio is an object that is a group of instruments, with calculated positions based on the weighting and volatility target.
    """

    def __init__(self, weights=1, instruments=None):
        self.instruments = Instrument.load(instruments)
        self.weights = pd.Series(config.strategy.portfolio_weights)
        # remove weights for instruments that aren't in the portfolio
        self.weights = self.weights[self.weights.index.isin(instruments)]
        # instruments blacklisted due to validation errors
        self.inst_blacklist = []
Пример #38
0
import pandas as pd
from bravado.client import SwaggerClient
import bravado.exception
from core.contract_store import Store
from data.data_provider import DataProvider
from core.utility import contract_format
from core.logger import get_logger
from core.bitmex_auth import get_request_client, api_config, SPEC_URI
import numpy as np
from time import sleep
from functools import partial
logger = get_logger('bitmex_provider')


class BitmexProvider(DataProvider):

    def __init__(self):
        super().__init__()
        self.library = 'bitmex'
        # it's not necessary to use authorized access for data downloading,
        #  but API limitations will be more restrictive if you don't
        self.auth = True
        self.client = None

    def download_instrument(self, inst, **kwargs):
        """
        :param kwargs: 'clean=True' will force delete and re-download all data,
                        otherwise db will be updated with the new data
        """
        clean = kwargs.get('clean', False)
        if not clean:  # if clean is False, but no existing data found - force it to be True
Пример #39
0
from functools import lru_cache

import config.strategy
from core.currency import Currency
import numpy as np
import pandas as pd
from trading.accountcurve import accountCurve

import config.instruments
import config.settings
import trading.rules
from core import data_feed
from core.logger import get_logger
from core.utility import contract_to_tuple, cbot_month_code, generate_roll_progression, weight_forecast

logger = get_logger('instrument')


class Instrument(object):
    """
    Object representing a future instrument
    """

    @classmethod
    def load(self, instruments):
        """Loads all instruments in the system into a dict so that they can be easily worked with.
        
        For example:
        i = Instruments.load()  # Load all the instrument data to memory 
        i['corn'].contracts()   # Show the corn contracts
Пример #40
0
import pandas as pd
from ib.ext.Contract import Contract
from ib.ext.ExecutionFilter import ExecutionFilter
from ib.ext.Order import Order
from ib.ext.TagValue import TagValue
from ib.opt import ibConnection
import config.instruments
import config.portfolios
import config.settings
import data.db_mongo as db
import core.utility
from core.ib_connection import get_next_id
from core.logger import get_logger
from trading.account import Account

logger = get_logger('ibstate')


class IBstate(object):
    """
    Stateful object to help us interact with Interactive Brokers.
    """
    def __init__(self):
        self.orders_cache = {}      # market orders placed during the current trading session
        self.open_orders_raw = []   # list of orders that are placed, but not yet executed
        self.order_status_raw = []
        self.clientId = get_next_id()   # client ID fot TWS terminal
        self.port = getattr(config.settings, 'ib_port', 4001)   # socket port for TWS terminal
        if os.environ.get('D_HOST') is not None:    # host for TWS terminal
            self.host = os.environ.get('D_HOST')
        else: