def test__003(self): """ About capital signals """ timestamp = epoch.to_long('2017-08-21 06:00:00 PDT') acc1_js = ensure_test_data({ "uid": "backtesting_gdx_" + random_str(), "timestamp__long": timestamp, "exchange": "gdax", "country": "usa", "usd__num": 0.0, "eth__num": 0.0, "btc__num": 0.0 }) acc1 = AccountModel.build(acc1_js) acc1.db_save(es) acc2_js = ensure_test_data({ "uid": "backtesting_cex_" + random_str(), "timestamp__long": timestamp, "exchange": "cex", "country": "gbr", "usd__num": 1700.0, "eth__num": 0.0, "btc__num": 0.0 }) acc2 = AccountModel.build(acc2_js) acc2.db_save(es) trading_acc1 = BacktestingTradingAccount(acc1.uid, 'gdax') trading_acc2 = BacktestingTradingAccount(acc2.uid, 'cex') strat = Strat1(trading_acc1, trading_acc2) signal = strat.get_signal__available_to_deposit(timestamp) assert signal['signal'] == False
def get_account(self): """ :return: AccountModel """ params = default_es_get_params() result = es.get('account', self.account_uid, params=params) account_js = result['_source'] account = AccountModel.build(account_js) return account
def sync_account_with_exh(self): exh_client = self._get_exh_client() balances = exh_client.get_balances() account_js = self.get_account().js account_js['eth__num'] = float(balances['eth']) account_js['btc__num'] = float(balances['btc']) account_js['usd__num'] = float(balances['usd']) account = AccountModel.build(account_js) account.db_save(es) return account
"timestamp__long": start_time, "exchange": "gdax", "country": "usa", "usd__num": 20000.0, "eth__num": 3.0, "btc__num": 0.0 } cex_acc_js = { "uid": cex_account_name, "timestamp__long": start_time, "exchange": "cex", "country": "gbr", "usd__num": 0.0, "eth__num": 60.0, "btc__num": 0.0 } gdax = AccountModel.build(gdax_acc_js) cex = AccountModel.build(cex_acc_js) gdax.db_save(es) cex.db_save(es) trading_acc1 = MockTradingAccount(gdax.uid, 'gdax') trading_acc2 = MockTradingAccount(cex.uid, 'cex') accounts = [trading_acc1, trading_acc2] # run strategies runner = StrategyRunner(execution_window, execution_interval, Strat1, strategy_running_id, strategy_desc, accounts) runner.start(fail_fast=False)