Exemple #1
0
def test_reset(stream):
    stream.add_record(entry("ETH_SALT", 1.1, 0.7, 6.2, 0.1, 0.5)) \
        .add_record(entry("ETH_SALT", 1.2, 0.5, 6.7, 0.3, 0.9)).finish()
    multi = ShapeShiftRates(stream)
    move_to_end(multi)
    multi.reset()
    assert next(iter(multi))["ETH_SALT"] == entry("ETH_SALT", 1.1, 0.7, 6.2, 0.1, 0.5)
Exemple #2
0
def test_filter_exchange(stream):
    stream.add_record(entry("ETH_BTC", "1.1", 0.7, 6.2, 0.1, "0.5"),
                      entry("ETH_1ST", "1.5", 0.1, 4.1, 1.1, "1.9")).finish()
    filtered = ShapeShiftRates(io.StringIO(rates_filter(ShapeShiftRates(stream), ["ETH_1ST"])))
    pairs = next(iter(filtered))
    assert pairs["ETH_1ST"] == entry("ETH_1ST", "1.5", 0.1, 4.1, 1.1, "1.9")
    assert "ETH_BTC" not in pairs
Exemple #3
0
def test_multiple_pair_entries(stream):
    stream.add_record(entry("ETH_SALT", 1.1, 0.7, 6.2, 0.1, 0.5),
                      entry("RCN_1ST", 1.52, 0.1, 4.1, 1.1, 1.9)).finish()
    single = ShapeShiftRates(stream)
    pairs = next(iter(single))
    assert pairs["ETH_SALT"] == entry("ETH_SALT", 1.1, 0.7, 6.2, 0.1, 0.5)
    assert pairs["RCN_1ST"] == entry("RCN_1ST", 1.52, 0.1, 4.1, 1.1, 1.9)
Exemple #4
0
def test_filter_exchange_of_multiple_records(stream):
    stream.add_record(entry("ETH_BTC", "1.1", 0.7, 6.2, 0.1, "0.5"),
                      entry("ETH_1ST", "1.5", 0.1, 4.1, 1.1, "1.9"))\
          .add_record(entry("ETH_BTC", "1.2", 0.7, 6.2, 0.1, "0.4"),
                      entry("BTC_ETH", "1.0", 0.7, 6.2, 0.1, "0.4"),
                      entry("ETH_1ST", "1.4", 0.1, 4.1, 1.1, "1.8"))\
          .add_record(entry("ETH_BTC", "1.3", 0.7, 6.2, 0.1, "0.3"),
                      entry("BTC_ETH", "1.1", 0.7, 6.2, 0.1, "0.5")).finish()
    filtered = ShapeShiftRates(io.StringIO(rates_filter(ShapeShiftRates(stream), ["ETH_1ST"])))
    pairs = next(iter(filtered))
    assert pairs["ETH_1ST"] == entry("ETH_1ST", "1.5", 0.1, 4.1, 1.1, "1.9")
    assert "ETH_BTC" not in pairs
    pairs = next(iter(filtered))
    assert pairs["ETH_1ST"] == entry("ETH_1ST", "1.4", 0.1, 4.1, 1.1, "1.8")
    assert "ETH_BTC" not in pairs
    assert "BTC_ETH" not in pairs
    with pytest.raises(StopIteration):
        next(iter(filtered))
def env():
    dir = os.path.dirname(
        os.path.abspath(inspect.getfile(inspect.currentframe())))
    path = os.path.join(
        dir,
        "test_data/2018-02-28-shapeshift-BTC_ETH.json".format(COIN_A, COIN_B))
    with open(path) as stream:
        rates = ShapeShiftRates(stream, preload=True)
        yield ExchangeTradingAiEnvironment(rates, COIN_A, 10, 1, {
            1: COIN_A,
            2: COIN_B
        }, TotalBalanceReward())
Exemple #6
0
def test_interim_look_ahead(stream, should_preload):
    stream.add_record(entry("ETH_SALT", 1.1, 0.7, 6.2, 0.1, 0.5))\
        .add_record(entry("ETH_SALT", 1.2, 0.5, 6.7, 0.3, 0.9))\
        .add_record(entry("ETH_SALT", 1.3, 0.6, 6.3, 0.2, 0.7)).finish()

    rates = ShapeShiftRates(stream, preload=should_preload)
    next(rates)
    with interim_lookahead(rates):
        assert next(rates)["ETH_SALT"] == entry("ETH_SALT", 1.2, 0.5, 6.7, 0.3, 0.9)
        assert next(rates)["ETH_SALT"] == entry("ETH_SALT", 1.3, 0.6, 6.3, 0.2, 0.7)
    assert next(rates)["ETH_SALT"] == entry("ETH_SALT", 1.2, 0.5, 6.7, 0.3, 0.9)
    assert next(rates)["ETH_SALT"] == entry("ETH_SALT", 1.3, 0.6, 6.3, 0.2, 0.7)
Exemple #7
0
def test_preloaded(stream):
    stream.add_record(entry("ETH_BTC", "1.1", 0.7, 6.2, 0.1, "0.5"),
                      entry("ETH_1ST", "1.5", 0.1, 4.1, 1.1, "1.9"))\
          .add_record(entry("ETH_BTC", "1.2", 0.7, 6.2, 0.1, "0.4"),
                      entry("ETH_1ST", "1.4", 0.1, 4.1, 1.1, "1.8"))\
          .add_record(entry("ETH_BTC", "1.3", 0.7, 6.2, 0.1, "0.3"),
                      entry("ETH_1ST", "1.1", 0.1, 4.1, 1.1, "0.5")).finish()

    rates = ShapeShiftRates(stream, preload=True)
    pairs = next(iter(rates))
    assert pairs["ETH_BTC"] == entry("ETH_BTC", "1.1", 0.7, 6.2, 0.1, "0.5")
    assert pairs["ETH_1ST"] == entry("ETH_1ST", "1.5", 0.1, 4.1, 1.1, "1.9")
    pairs = next(iter(rates))
    assert pairs["ETH_BTC"] == entry("ETH_BTC", "1.2", 0.7, 6.2, 0.1, "0.4")
    assert pairs["ETH_1ST"] == entry("ETH_1ST", "1.4", 0.1, 4.1, 1.1, "1.8")
    pairs = next(iter(rates))
    assert pairs["ETH_BTC"] == entry("ETH_BTC", "1.3", 0.7, 6.2, 0.1, "0.3")
    assert pairs["ETH_1ST"] == entry("ETH_1ST", "1.1", 0.1, 4.1, 1.1, "0.5")
    with pytest.raises(StopIteration):
        next(iter(rates))
import sys

import os

from pythia.core.streams.shape_shift_rates import ShapeShiftRates
from pythia.core.streams.rates_calculators import rates_filter

if __name__ == "__main__":
    in_path = "../data/recordings/2018-02-28-shapeshift-exchange-records.json" if len(
        sys.argv) == 1 else sys.argv[1]
    out_path = "../data/recordings/filtered/2018-02-28-shapeshift-RLC_WINGS.json" if len(
        sys.argv) == 1 else sys.argv[2]
    os.makedirs(os.path.dirname(out_path), exist_ok=True)
    with open(in_path, 'r') as in_stream, open(out_path, 'w') as out_stream:
        out_stream.write(
            rates_filter(ShapeShiftRates(in_stream),
                         ["RLC_WINGS", "WINGS_RLC"]))
Exemple #9
0
from pythia.core.environment.exchange_trading_environment import ExchangeTradingEnvironment
from pythia.core.sessions.rates_exchange_session import RatesExchangeSession
from pythia.core.streams.shape_shift_rates import ShapeShiftRates, SUPPORTED_COINS
from pythia.core.utils.profiling import clock_block
from pythia.core.visualization.coin_exchange_visualizer import CoinExchangeVisualizer

targets = list(SUPPORTED_COINS)
targets.remove("BTC")
agent = AnalyticalAgent('0.1', '0', 2, targets)

if __name__ == '__main__':
    path = "../data/recordings/2018-02-28-shapeshift-exchange-records.json" if len(
        sys.argv) == 1 else sys.argv[0]
    with open(path) as stream:
        with clock_block("Initialization"):
            rates = ShapeShiftRates(stream, preload=True)
            vis = CoinExchangeVisualizer(rates)
            env = ExchangeTradingEnvironment(rates, "BTC", "0.1")
            env.register_listener(vis.record_exchange)
            sess = RatesExchangeSession(env, agent)

        with clock_block("Running"):
            sess.run()

        print("The analytical agent crated a token difference of: {0}".format(
            sess.difference()))
        print("Current balance: {0} {1}".format(env.amount, env.token))
        print("Exchange actions: {0}".format(vis.actions))

        rates.reset()
        vis.render("BTC_GAME")
def empty():
    stream = io.StringIO("")
    yield ShapeShiftRates(stream)
    stream.close()
    return all


if __name__ == "__main__":
    in_path = "../data/recordings/2018-02-28-shapeshift-exchange-records.json" if len(
        sys.argv) == 1 else sys.argv[1]
    #out_path = "../data/recordings/analysis/2018-02-28-shapeshift.csv" if len(sys.argv) == 1 else sys.argv[2]
    #os.makedirs(os.path.dirname(out_path), exist_ok=True)
    #with open(in_path, 'r') as in_stream, open(out_path, 'w') as out_stream:
    #    out_stream.write(analyze(ShapeShiftRates(in_stream)).to_csv())

    max_profit = float("-inf")
    max_profit_exchange = None
    for l_ex, r_ex in all_combinations():
        with open(in_path, 'r') as in_stream:
            stream = StringIO((rates_filter(ShapeShiftRates(in_stream),
                                            [l_ex, r_ex])))
            rates = ShapeShiftRates(stream, preload=True)
            coin_a = l_ex.split('_')[0]
            coin_b = l_ex.split('_')[1]
            env = ExchangeTradingAiEnvironment(rates, coin_a, "10", 1, {
                1: coin_a,
                2: coin_b
            }, TotalBalanceReward())
            policy = RiggedPolicy(env,
                                  PolicyDummy(),
                                  1.0,
                                  rigging_distance=STOP_AT_THRESHOLD,
                                  threshold=0.1)
            s = env.reset()
            start_balance = env.balance_in(coin_a)
Exemple #12
0
def test_multiple_records(stream):
    stream.add_record(entry("ETH_SALT", 1.1, 0.7, 6.2, 0.1, 0.5)) \
        .add_record(entry("ETH_SALT", 1.2, 0.5, 6.7, 0.3, 0.9)).finish()
    multi = ShapeShiftRates(stream)
    assert next(iter(multi))["ETH_SALT"] == entry("ETH_SALT", 1.1, 0.7, 6.2, 0.1, 0.5)
    assert next(iter(multi))["ETH_SALT"] == entry("ETH_SALT", 1.2, 0.5, 6.7, 0.3, 0.9)
Exemple #13
0
def test_one_pair_entry(stream):
    stream.add_record(entry("ETH_SALT", 1.1, 0.7, 6.2, 0.1, 0.5)).finish()
    single = ShapeShiftRates(stream)
    assert next(iter(single))["ETH_SALT"] == entry("ETH_SALT", 1.1, 0.7, 6.2, 0.1, 0.5)