Пример #1
0
def main():
    configs = parse_configs(sys.argv)

    # create output file for all console output
    autonomy.outfile = new_output_file()
    tee = autonomy.Tee(sys.stdout, autonomy.outfile)
    sys.stdout = tee
    sys.stderr = tee

    # no comms simulation; that wouldn't be useful as this program is supposed to interact w/ GCS
    global XBEE
    XBEE = setup_xbee()

    # send connection message
    connection_message = {
        "type": "connect",
        "time": 0,  # This field is currently not used
        "sid": configs['vehicle_id'],
        "tid": 0,  # The ID of GCS
        "id": 0,  # The ID of this message
        "jobsAvailable": ["quickScan", "detailedSearch", "guide"]
    }

    # wait to receive the connection ack and start message
    XBEE.add_data_received_callback(xbee_callback)

    send_till_ack(configs["mission_control_MAC"], connection_message, 0)

    if not autonomy.outfile.closed:
        autonomy.outfile.close()
Пример #2
0
class TestAssetSelector(TestCase):

    config = parse_configs(path=os.path.join("../../", "config.ini"))
    args = parse_args()
    # if args.mode is None:
    #     args.mode = 'long'
    if args.period is None:
        args.period = "1D"
    if args.algorithm is None:
        args.algorithm = "efficient_frontier"
    if args.testperiods is None:
        args.testperiods = 30
    if args.max is None:
        args.max = 26
    if args.min is None:
        args.min = 6

    alpaca = REST(base_url=config["alpaca"]["APCA_API_BASE_URL"],
                  key_id=config["alpaca"]["APCA_API_KEY_ID"],
                  secret_key=config["alpaca"]["APCA_API_SECRET_KEY"],
                  api_version=config["alpaca"]["VERSION"])
    broker = Broker(alpaca)
    selector = AssetSelector(broker, cli_args=args)

    def test_get_assets(self):

        res = TestAssetSelector.selector.get_assets('equity',
                                                    'efficient_frontier')
        print('[] ')

    def test_candle_pattern_direction(self):
        pass
Пример #3
0
def quick_scan(GCS_TIMESTAMP = 0, CONNECTION_TIMESTAMP = 0):
    # Parse configs file
    configs = parse_configs(sys.argv)

    # Create output file if not already created
    if autonomy.outfile is None:
        autonomy.outfile = new_output_file()
        tee = autonomy.Tee(sys.stdout, autonomy.outfile)
        sys.stdout = tee
        sys.stderr = tee

    # Start autonomy and CV threads
    autonomyToCV = QuickScanAutonomyToCV()
    autonomy_thread = Thread(target=quick_scan_autonomy,
                             args=(configs, autonomyToCV, GCS_TIMESTAMP, CONNECTION_TIMESTAMP))
    autonomy_thread.daemon = True
    autonomy_thread.start()

    cv_thread = Thread(target=quick_scan_cv, args=(configs, autonomyToCV, GCS_TIMESTAMP, CONNECTION_TIMESTAMP))
    cv_thread.daemon = True
    cv_thread.start()

    # Wait for the threads to finish
    autonomy_thread.join()
    cv_thread.join()

    # Close XBee device
    if autonomy.xbee:
        autonomyToCV.xbeeMutex.release()
        autonomy.xbee.close()
        autonomyToCV.xbeeMutex.release()
Пример #4
0
def detailed_search(vehicle = None, gcs_timestamp = 0, connection_timestamp = 0):
    # Parse configs file
    configs = parse_configs(sys.argv)

    # Create output file if not already created
    if autonomy.outfile is None:
        autonomy.outfile = new_output_file()
        tee = autonomy.Tee(sys.stdout, autonomy.outfile)
        sys.stdout = tee
        sys.stderr = tee

    # Start autonomy and CV threads
    autonomyToCV = DetailedSearchAutonomyToCV()

    autonomy_thread = Thread(target = detailed_search_autonomy,
                            args = (configs, autonomyToCV, gcs_timestamp, connection_timestamp, vehicle))
    autonomy_thread.daemon = True
    autonomy_thread.start()

    cv_thread = Thread(target = detailed_search_cv, args = (configs, autonomyToCV))
    cv_thread.daemon = True
    cv_thread.start()

    # Wait for the threads to finish
    autonomy_thread.join()
    cv_thread.join()

    # Close XBee device
    if autonomy.xbee:
        autonomy.xbee.close()
Пример #5
0
class TestKrakDealer(TestCase):

    config = parse_configs("../../config.ini")
    api = krakenex.API(key=config["kraken"]["api_key"],
                       secret=config["kraken"]["private_key"])
    kraken = KrakenAPI(api, tier="Starter")
    asset = "XXRP"
    pair = "XXRPXXBT"
    krak_deaker = KrakDealer(kraken, pair)

    def test_get_server_time(self):
        servertime = self.krak_deaker.get_server_time()
        print(servertime)

    def test_get_account(self):
        account = self.krak_deaker.get_account()
        print(account)

    def test_get_trade_balance(self):
        bal = self.krak_deaker.get_trade_balance(asset=self.asset)
        print(bal)

    def test_get_tradable_asset_pairs(self):
        pairs = self.krak_deaker.get_tradable_asset_pairs()
        print(pairs)

    def test_get_ticker_information(self):
        info = self.krak_deaker.get_ticker_information(pair=self.pair)
        print(info)

    def test_get_ohlc_data(self):
        ohlc = self.krak_deaker.get_ohlc_data(pair=self.pair)
        print(ohlc)

    def test_get_order_book(self):
        orderbook = self.krak_deaker.get_order_book(pair=self.pair)
        print(orderbook)

    def test_get_recent_spread_data(self):
        spread = self.krak_deaker.get_recent_spread_data(pair=self.pair)
        print(spread)
Пример #6
0
def quick_scan():
    # Parse configs file
    configs = parse_configs(sys.argv)

    # Start autonomy and CV threads
    autonomyToCV = QuickScanAutonomyToCV()
    autonomy_thread = Thread(target=quick_scan_autonomy,
                             args=(configs, autonomyToCV))
    autonomy_thread.daemon = True
    autonomy_thread.start()

    cv_thread = Thread(target=quick_scan_cv, args=(configs, autonomyToCV))
    cv_thread.daemon = True
    cv_thread.start()

    # Wait for the threads to finish
    autonomy_thread.join()
    cv_thread.join()

    # Close XBee device
    if autonomy.xbee:
        autonomy.xbee.close()
Пример #7
0
def detailed_search(vehicle=None):
    # Parse configs file
    configs = parse_configs(sys.argv)

    # Start autonomy and CV threads
    autonomyToCV = DetailedSearchAutonomyToCV()
    autonomy_thread = Thread(target=detailed_search_autonomy,
                             args=(configs, autonomyToCV, vehicle))
    autonomy_thread.daemon = True
    autonomy_thread.start()

    cv_thread = Thread(target=detailed_search_cv, args=(configs, autonomyToCV))
    cv_thread.daemon = True
    cv_thread.start()

    # Wait for the threads to finish
    autonomy_thread.join()
    cv_thread.join()

    # Close XBee device
    if autonomy.xbee:
        autonomy.xbee.close()
Пример #8
0
def main():
    configs = parse_configs(sys.argv)

    # no comms simulation; that wouldn't be useful as this program is supposed to interact w/ GCS
    global xbee
    xbee = setup_xbee()

    # send connection message
    connection_message = {
        "type": "connect",
        "time": 0,  # This field is currently not used
        "sid": configs['vehicle_id'],
        "tid": 0,  # The ID of GCS
        "id": 0,  # The ID of this message
        "jobsAvailable": ["quickScan", "detailedSearch", "guide"]
    }

    # Instantiate a remote XBee device object to send data.
    send_xbee = RemoteXBeeDevice(xbee, address)
    xbee.send_data(send_xbee, json.dumps(connection_message))

    # wait to receive the connection ack and start message
    xbee.add_data_received_callback(xbee_callback)
Пример #9
0
            raise error

        try:
            broker = Broker(alpaca)
        except (BrokerException, BrokerValidationException) as error:
            raise error
        else:
            # is our account restricted from trading?
            if broker.trading_blocked:
                raise BrokerException('[!] Account is currently restricted from trading.')

        # how much money can we use to open new positions?
        if args.cash is not None:
            print('[?] ${} in simulated account balance.'.format(args.cash))
        else:
            print('[?] ${} is available in cash.'.format(broker.cash))

    # try and import the corresponding Python file from algos
    try:
        algorithm = import_module(f'algos.{args.algorithm}', package='Algorithm')
    except ImportError as error:
        raise error
    else:
        algorithm.run(broker, args)


if __name__ == '__main__':
    configuration = parse_configs()
    arguments = parse_args()
    main(configuration, arguments)
Пример #10
0
    def __init__(self, parent=None):
        super(APP_EISeg, self).__init__(parent)

        # 初始化界面
        self.setupUi(self)

        # app变量
        self.controller = None
        self.image = None  # 可能先加载图片后加载模型,只用于暂存图片
        self.modelClass = MODELS[0]
        self.outputDir = None  # 标签保存路径
        self.labelPaths = []  # 保存所有从outputdir发现的标签文件路径
        self.filePaths = []  # 文件夹下所有待标注图片路径
        self.currIdx = 0  # 文件夹标注当前图片下标
        self.currentPath = None
        self.isDirty = False
        self.labelList = Labeler()
        self.settings = QtCore.QSettings(
            osp.join(pjpath, "config/setting.ini"), QtCore.QSettings.IniFormat)
        self.config = util.parse_configs(osp.join(pjpath,
                                                  "config/config.yaml"))
        self.recentModels = self.settings.value("recent_models", [])
        self.recentFiles = self.settings.value("recent_files", [])
        if not self.recentFiles:
            self.recentFiles = []
        self.maskColormap = ColorMask(osp.join(pjpath, "config/colormap.txt"))

        # 初始化action
        self.initActions()

        # 更新近期记录
        self.updateModelsMenu()
        self.updateRecentFile()

        # 帮助界面
        self.help_dialog = QtWidgets.QDialog()
        help_ui = Ui_Help()
        help_ui.setupUi(self.help_dialog)

        ## 画布部分
        self.canvas.clickRequest.connect(self.canvasClick)
        self.annImage = QtWidgets.QGraphicsPixmapItem()
        self.scene.addItem(self.annImage)

        ## 按钮点击
        self.btnSave.clicked.connect(self.saveLabel)  # 保存
        self.listFiles.itemDoubleClicked.connect(self.listClicked)  # 标签列表点击
        self.comboModelSelect.currentIndexChanged.connect(
            self.changeModel)  # 模型选择
        self.btnAddClass.clicked.connect(self.addLabel)
        self.btnParamsSelect.clicked.connect(self.changeParam)  # 模型参数选择

        ## 滑动
        self.sldOpacity.valueChanged.connect(self.maskOpacityChanged)
        self.sldClickRadius.valueChanged.connect(self.clickRadiusChanged)
        self.sldThresh.valueChanged.connect(self.threshChanged)

        ## 标签列表点击
        self.labelListTable.cellDoubleClicked.connect(
            self.labelListDoubleClick)
        self.labelListTable.cellClicked.connect(self.labelListClicked)
        self.labelListTable.cellChanged.connect(self.labelListItemChanged)
        self.labelList.readLabel(self.settings.value("label_list_file"))
        self.refreshLabelList()
Пример #11
0
def main():
    argv = ["f", "../configs.json"]
    for i in range(10):
        cv2.imshow('image', cv_simulation(parse_configs(argv)))
        cv2.waitKey(0)
        cv2.destroyAllWindows()
Пример #12
0
class TestBroker(TestCase):

    config = parse_configs(path=os.path.join('../../', 'config.ini'))
    alpaca = REST(base_url=config['alpaca']['APCA_API_BASE_URL'],
                  key_id=config['alpaca']['APCA_API_KEY_ID'],
                  secret_key=config['alpaca']['APCA_API_SECRET_KEY'],
                  api_version=config['alpaca']['VERSION'])
    broker = Broker(alpaca)

    def test_get_account(self):

        res = TestBroker.broker.get_account()
        self.assertIsInstance(res, Ent.Account)

    def test_get_clock(self):

        res = TestBroker.broker.get_clock()
        self.assertIsInstance(res, Ent.Clock)

    def test_get_calendar(self):
        start = time_from_timestamp(time.time() - (604800 * 54))
        end = time_from_timestamp(time.time())
        res = TestBroker.broker.get_calendar(start_date=start, end_date=end)
        self.assertIsInstance(res, list)
        self.assertIsInstance(res[0], Ent.Calendar)

    def test_get_assets(self):
        res = TestBroker.broker.get_assets()
        self.assertIsInstance(res, list)
        self.assertIsInstance(res[0], Ent.Asset)

    def test_get_asset(self):
        ticker = 'AAPL'
        res = TestBroker.broker.get_asset(ticker)
        self.assertIsInstance(res, Ent.Asset)

    def test_get_positions(self):
        res = TestBroker.broker.get_positions()
        self.assertIsInstance(res, list)
        self.assertIsInstance(res[0], Ent.Position)

    def test_get_position(self):
        ticker = 'AAPL'
        res = TestBroker.broker.get_position(ticker)
        self.assertIsInstance(res, Ent.Position)

    def test_close_all_positions(self):
        res = TestBroker.broker.close_all_positions()
        self.assertIsInstance(res, list)
        self.assertEqual(len(res), 0)

    def test_close_position(self):
        ticker = 'AAPL'
        res = TestBroker.broker.close_position(ticker)
        self.assertIsInstance(res, Ent.Order)

    def test_get_orders(self):
        res = TestBroker.broker.get_orders()
        self.assertIsInstance(res, list)
        self.assertIsInstance(res[0], Ent.Order)

    def test_get_order(self):
        ticker = 'AAPL'
        res = TestBroker.broker.get_order()
        print('[] ')

    def test_submit_order(self):

        res = TestBroker.broker.submit_order()
        print('[] ')

    def test_replace_order(self):

        res = TestBroker.broker.replace_order()
        print('[] ')

    def cancel_all_orders(self):

        res = TestBroker.broker.cancel_all_orders()
        print('[] ')

    def test_cancel_order(self):

        res = TestBroker.broker.cancel_order()
        print('[] ')

    def test_get_asset_df(self):

        res = TestBroker.broker.get_asset_df()
        print('[] ')

    def test_get_watchlists(self):

        res = TestBroker.broker.get_watchlists()
        print('[] ')

    def test_get_watchlist(self):

        res = TestBroker.broker.get_watchlist()
        print('[] ')

    def test_add_watchlist(self):

        res = TestBroker.broker.add_watchlist()
        print('[] ')

    def test_add_to_watchlist(self):

        res = TestBroker.broker.add_to_watchlist()
        print('[] ')

    def test_clear_watchlist(self):

        res = TestBroker.broker.clear_watchlist()
        print('[] ')

    def test_calculate_tolerable_risk(self):

        res = TestBroker.broker.calculate_tolerable_risk()
        print('[] ')

    def test_calculate_position_size(self):

        res = TestBroker.broker.calculate_position_size()
        print('[] ')