Esempio n. 1
0
    def setUp(self):
        instrument_type = "IH"
        brokerID, userID, password, mdapi_front, trade_front = get_account(0)
        logger = get_logger("spread_arbitrage", "%s.log" % "mytdapi_test")

        mdapi1 = my_mdapi(brokerID, userID, password,
                          [_Instruments[instrument_type][0]], logger)
        mdapi1.RegisterFront(mdapi_front)
        mdapi1.Init()
        time.sleep(1)
        mdapi2 = my_mdapi(brokerID, userID, password,
                          [_Instruments[instrument_type][1]], logger)
        mdapi2.RegisterFront(mdapi_front)
        mdapi2.Init()
        time.sleep(5)
        logger.info('=========== 行情实例结束创建 ===========')

        self.trade = my_tdapi(broker_id=brokerID,
                              investor_id=userID,
                              passwd=password,
                              instrumentIDs=_Instruments[instrument_type],
                              mdapi1=mdapi1,
                              mdapi2=mdapi2,
                              logger=logger,
                              left_position=0)
        self.trade.Create(pszFlowPath='TdFile/')
        self.trade.SubscribePrivateTopic(ApiStruct.TERT_RESTART)
        self.trade.SubscribePublicTopic(ApiStruct.TERT_RESTART)
        self.trade.RegisterFront(trade_front)
        self.trade.Init()
        time.sleep(5)
Esempio n. 2
0
def transform_type():
    conn = mongo_service.get_remote_mongo_conn(user="******",
                                               pswd="tibame",
                                               host="10.120.26.31",
                                               port="27017")
    coll = conn["Allcars"]["usedcar_copy"]
    type_mapping = car_type_mapping()
    count = 0
    logger = myutils.get_logger(log_name="car type transform")
    for brand in type_mapping:
        print("type mapping get brand: ", brand)
        mapping = type_mapping[brand]
        for key in mapping:
            print("finding type : ", key)
            corsur = coll.find({"brand": brand, "type": key})
            for item in corsur:
                # print(item)
                logger.info(item)
                item["type"] = mapping[key]
                logger.info("to")
                logger.info(item)
                result = coll.update_one(
                    filter={"_id": item["_id"]},
                    update={"$set": {
                        "type": mapping[key]
                    }})
                logger.info(str(result) + " update success!")
Esempio n. 3
0
 def setUp(self):
     instrument_type = "IH"
     brokerID, userID, password, mdapi_front, trade_front = myutils.get_account(
         0)
     logger = myutils.get_logger("spread_arbitrage",
                                 "logs/%s.log" % "MdApi_test")
     self._mdapi1 = my_mdapi(brokerID, userID, password,
                             [myutils._Instruments[instrument_type][0]],
                             logger)
     mdapi1.RegisterFront(mdapi_front)
     mdapi1.Init()
     time.sleep(1)
"""Helper methods for parsing EC2 instance data from AWS SDK."""

import logging
import myutils

logger = myutils.get_logger(__name__, logging.INFO)


@myutils.log_calls(level=logging.DEBUG)
def parse(reservations):
    """Process raw EC2 instance data."""
    # consolidate the game server data
    servers = []
    for reservation in reservations.get('Reservations', []):
        servers.extend(map(map_instance, reservation.get('Instances', [])))
    return servers


@myutils.log_calls(level=logging.DEBUG)
def map_instance(instance):
    """Map AWS EC2 instance data to response message format."""
    tags = instance.get('Tags', [])
    full_name = myutils.get_first('Name', tags)
    return {
        'name': get_short_name(full_name),
        'fullName': full_name,
        'environment': myutils.get_first('Environment', tags),
        'instanceId': instance.get('InstanceId', ''),
        'state': instance.get('State', {}).get('Name', ''),
        'publicIpAddress': instance.get('PublicIpAddress', '')
    }
Esempio n. 5
0
"""Helper methods for parsing EBS-related data from AWS SDK."""

import logging
import myutils

logger = myutils.get_logger(__name__, logging.DEBUG)


@myutils.log_calls(level=logging.DEBUG)
def parse(sdk_snapshots):
    """Process raw EBS snapshot data."""
    snapshots = []
    snapshots.extend(map(map_snapshot, sdk_snapshots.get('Snapshots', [])))
    return snapshots


@myutils.log_calls(level=logging.DEBUG)
def map_snapshot(snapshot):
    """Map AWS EBS snapshot data to response message format."""
    tags = snapshot.get('Tags', [])
    return {
        'name': myutils.get_first('Name', tags),
        'server': get_server_name(tags),
        'snapshotId': snapshot.get('SnapshotId', ''),
        'event': myutils.get_first('Event', tags),
        'timestamp': myutils.get_first('Timestamp', tags)
    }


def get_server_name(tags):
    """Retrieve server name from across different tag scenarios."""
Esempio n. 6
0
            self.logger.info('交易日期: %s', self.GetTradingDay())
            self.SubscribeMarketData(self.instrumentIDs)

    def OnRspSubMarketData(self, pSpecificInstrument, pRspInfo, nRequestID,
                           bIsLast):
        if pRspInfo.ErrorID == 0:
            self.logger.info("行情订阅成功!合约号:%s", pSpecificInstrument.InstrumentID)
        else:
            self.logger.info("行情订阅失败...")
            self.logger.info("错误代码: %s, 错误信息 %s:", pRspInfo.ErrorID,
                             myutils.decode(pRspInfo.ErrorMsg))

    def OnRtnDepthMarketData(self, pDepthMarketData):
        self.depth_info = pDepthMarketData
        self.tick_change = True


if __name__ == '__main__':
    # simnow
    instrument_type = "IC"
    brokerID = b'9999'
    mdapi_front = b'tcp://180.168.146.187:10010'
    trade_front = b'tcp://180.168.146.187:10000'
    userID = b'097138'
    password = b'285135278'
    logger = myutils.get_logger("spread_arbitrage", "%s.log" % "IC")
    mdapi1 = my_mdapi(brokerID, userID, password,
                      [myutils._Instruments[instrument_type][0]], logger)
    mdapi1.RegisterFront(mdapi_front)
    mdapi1.Init()
    time.sleep(1)
Esempio n. 7
0
import myutils
import json
import service.mongo_service as mongo_service

logger = myutils.get_logger("car_8891", "8891.log")


def get_new_car_brand():
    # print("start")
    url = "https://c.8891.com.tw"
    ss = myutils.get_session()
    # get https://c.8891.com.tw/Models
    res = ss.get(url=url + "/Models", headers=myutils.get_header())
    soup = myutils.get_soup(res.text)
    # print(soup.select("div.scroll-area"))
    # 獲取車輛品牌清單
    new_car_brand_list = []
    for a in soup.select("div.scroll-area li"):
        new_car_brand = {}
        new_car_brand["country"] = a["country"]
        new_car_brand["brand_id"] = a["id"]
        atag = a.select_one("a")
        new_car_brand["brand"] = atag.text.strip()
        new_car_brand["link"] = url + atag["href"]
        new_car_brand_list.append(new_car_brand)
    return new_car_brand_list


def get_pic_page_url(url: str):
    ss = myutils.get_session()
    req = ss.get(url=url, headers=myutils.get_header())
Esempio n. 8
0
import prometheus_client as prometheus_client
import flask

from flask import Flask, request, render_template, Response, redirect
from data import ContentManager
from myutils import get_logger, get_limiter
from metrics_utils import setup_metrics

app = Flask(__name__)
cm = ContentManager(app)
logger = get_logger(app)
limiter = get_limiter(app)
setup_metrics(app)


@app.route('/')
def index():
    return render_template('main.html')


@app.route('/favicon.ico')
def favicon():
    return redirect('/static/favicon.ico')


@app.route('/content')
def get_content():
    contentKey = request.args.get('contentKey', default='Default')
    logger.info('content loaded')
    return Response(cm.get_content(contentKey), status=200)
Esempio n. 9
0
# -*- coding:utf-8 -*-
from MyMdApi import *
from MyTdApi import *
from strategy import *
import myutils
import time

account = myutils._YangRui
instrument_type = "IH"
left_position = 0

# 账户:
brokerID, userID, password, mdapi_front, trade_front = myutils.get_account(account=account)

# 日志类
logger = myutils.get_logger("spread_arbitrage", "logs/%s.log" % instrument_type)

# 远月价差行情实例
mdapi1 = my_mdapi(brokerID, userID, password, [myutils._Instruments[instrument_type][0]], logger)
mdapi1.RegisterFront(mdapi_front)
mdapi1.Init()
time.sleep(1)

# 远月价差行情实例
mdapi2 = my_mdapi(brokerID, userID, password, [myutils._Instruments[instrument_type][1]], logger)
mdapi2.RegisterFront(mdapi_front)
mdapi2.Init()
time.sleep(5)
logger.info('=========== 行情实例结束创建 ===========')

# 交易实例
Esempio n. 10
0
from pymongo import MongoClient
from bson.objectid import ObjectId
import myutils
import pandas as pd
import json
import datetime

db_user = "******"
db_pswd = "123456"
db_domain = "localhost"
db_port = "27017"
db_url = "mongodb://{}:{}@{}:{}/".format(db_user, db_pswd, db_domain, db_port)

conn = None  # type: MongoClient
logger = myutils.get_logger(log_name="mongo_service")


def close_conn():
    if conn is not None:
        conn.close()


def find_by_id(idd, db_name="data", collection="car"):
    db = get_mongo_conn()[db_name]
    coll = db[collection]
    result = coll.find_one({"_id": idd})
    return result


def is_exist(idd, db_name="data", collection="car"):
    db = get_mongo_conn()[db_name]