コード例 #1
0
ファイル: trading_analysis.py プロジェクト: Water-Drop/KID
 def get_analysis_result(self):
     print "get analysis result" 
     win_rate_class = WinRate(self.trading_record)
     win_rate_class.get_win_rate()
     capital_class = Capital(self.trading_record, self.initial_capital)
     capital_class.get_capital()
         
コード例 #2
0
    ]

vienna_pictures = [
    "http://ringview.vienna.info/ressources/streetview/images/ViennaRingView.jpg",
    "http://www.easyjet.com/en/holidays/shared/images/guides/austria/vienna.jpg",
    "http://airpano.ru/files/Vienna-Austria/images/image4.jpg"
]


paris_pictures = [
    "https://media-cdn.tripadvisor.com/media/photo-s/06/e5/55/c5/champs-elysees.jpg",
    "http://wikitravel.org/upload/shared//6/6f/Paris_Banner.jpg",
    "http://www.telegraph.co.uk/content/dam/Travel/leadAssets/35/02/france-hub_3502656a-xlarge.jpg"
]

vienna = Capital("Vienna", vienna_pictures)
rome = Capital("Rome", rome_pictures)
paris = Capital("Paris", paris_pictures)
capitals = [vienna, rome, paris]


class MainHandler(BaseHandler):
    def get(self):
        ri = randint(0, len(capitals)-1)
        params = {"capital": capitals[ri], "capital_index": ri}

        return self.render_template("hello.html", params=params)

    def post(self):
        guessed_capital_name = self.request.get("guessed_city")
        capital_index = int(self.request.get("capital_index"))
コード例 #3
0
"""Main Entrypoint for the Application"""

import json
import logging
import urlparse
from google.cloud import pubsub
from flask import Flask, request, jsonify, render_template
from capital import Capital
from cloudstorage import Storage
import utility

app = Flask(__name__)
capital = Capital()
storage = Storage()
client = pubsub.Client()


@app.route('/', methods=['GET'])
@app.route('/map', methods=['GET'])
def show_map():
    results = capital.get_all()
    return render_template('map.html', comment=None, results=results)


@app.route('/polymer', methods=['GET'])
def show_polymer_map():
    results = capital.get_all()
    return render_template('polymer_maps.html', comment=None, results=results)


@app.route('/countries', methods=['GET'])
コード例 #4
0
 def setUp(self):
     self.input = self.__get_test_entity()
     self.id = self.input['id']
     self.capital = Capital()
コード例 #5
0
class TestCapital(unittest.TestCase):
    if __name__ == '__main__':
        unittest.main()

    def setUp(self):
        self.input = self.__get_test_entity()
        self.id = self.input['id']
        self.capital = Capital()

    def tearDown(self):
        try:
            # clean up
            self.capital.delete(self.id)
        except:
            pass

    def test_get(self):
        try:
            entity = self.capital.get(id)
            self.fail("an exception is expected")
        except Exception as ex:
            pass

        try:
            self.capital.insert(id, input)
        except Exception as ex:
            self.fail('failed to insert an entity {}'.format(ex.message))

        entity = self.capital.get(id)
        self.assertEqual(input['name'], entity['name'])
        self.assertEqual(input['countryCode'], entity['countryCode'])
        self.assertEqual(input['country'], entity['country'])
        self.assertEqual(input['id'], entity['id'])
        self.assertEqual(input['continent'], entity['continent'])
        input_location = input['location']
        entity_location = entity['location']
        self.assertEqual(input_location['latitude'], entity_location['latitude'])
        self.assertEqual(input_location['longitude'], entity_location['longitude'])

    def test_get_all(self):
        try:
            self.capital.insert(id, input)
        except Exception as ex:
            self.fail('failed to insert an entity {}'.format(ex.message))

        results = self.capital.get_all()
        self.assertTrue(len(results) > 0)

    def test_insert(self):
        try:
            self.capital.insert(id, input)
        except Exception as ex:
            self.fail('failed to insert an entity {}'.format(ex.message))

    def test_delete(self):
        try:
            self.capital.insert(id, input)
        except Exception as ex:
            self.fail('failed to insert an entity {}'.format(ex.message))

        try:
            self.capital.delete(id)
        except Exception as ex:
            self.fail('failed to delete the created entity {}'.format(ex.message))

    def __get_test_entity(self):
        entity = {}
        location = {}
        entity['location'] = location
        entity['name'] = 'King Edward Point'
        entity['countryCode'] = 'GS'
        entity['country'] = 'South Georgia and South Sandwich Islands'
        entity['id'] = 999999
        entity['continent'] = 'Antarctica'
        location['latitude'] = -54.283333
        location['longitude'] = -36.5
        return entity
コード例 #6
0
ファイル: test_code.py プロジェクト: Isaacmart/CryptoTrader
def application():

    if request.method == 'POST':

        new_request = request.get_json(force=True)
        new_ticker = get_ticker(new_request)

        private_client = AuthenticatedClient(Data.API_Public_Key,
                                             Data.API_Secret_Key,
                                             Data.Passphrase)

        new_order = Order(private_client)
        position = OpenPosition(new_order)
        funds = Capital(private_client)

        indicator = Indicator()
        macd = MACD()

        candle_ticker: str
        stop_time: int
        candle_gra = int

        if position.get_position() and last_instance():

            candle_ticker = new_order.get_key("product_id")
            stop_time = get_time(27976)
            candle_gra = 300

            writer = open(Data.Time, "w")
            writer.write(str(time.time() + 5.0))
            writer.close()

        elif position.get_position() is False:

            candle_ticker = new_ticker
            stop_time = get_time(83925)
            candle_gra = 900

        try:
            indicator.set_candles(product=candle_ticker,
                                  callback=stop_time,
                                  begin=get_time(0),
                                  granularity=candle_gra)
        except ValueError as ve:
            print(ve.with_traceback())
        except NameError as ne:
            print(ne.with_traceback())

        indicator_list = [indicator, macd]
        try:
            for value in indicator_list:
                value.candles = indicator.candles
                value.set_indicator()
                value.set_dates()
        except Exception as e:
            print(e.with_traceback())

        indicator_5m = Indicator()
        macd_5m = MACD()

        if position.get_position() is False:

            if macd.hist[-1] > macd.hist[-2]:
                try:
                    indicator_5m.set_candles(product=new_ticker,
                                             callback=get_time(27976),
                                             begin=get_time(0),
                                             granularity=900)
                except ValueError as ve:
                    print(ve.with_traceback())
        else:
            indicator_5m = indicator
            macd_5m = macd

        volume_5m = VolSMA(timeperiod=20)
        bands2dev_5m = BB()
        bands1dev_5m = BB(ndbevup=1, nbdevdn=1)
        rsi_5m = RSI()
        ema_5m = EMA()
        momentum_5m = Momentum()

        indicators = [
            indicator_5m, macd_5m, volume_5m, bands1dev_5m, bands2dev_5m,
            rsi_5m, ema_5m, momentum_5m
        ]

        try:
            for value in indicators:
                value.candles = indicator_5m.candles
                value.set_indicator()
                value.set_dates()
        except Exception as e:
            print(e.with_traceback())

        strategy_5m = Strategy(indicator_5m, macd_5m, bands1dev_5m,
                               bands2dev_5m, volume_5m, rsi_5m, ema_5m,
                               new_order)

        try:
            strategy_5m.strategy(-1)
        except Exception as e:
            print(e.with_traceback())

        trade_side: str
        trade_product: str
        trade_funds: str

        if (new_order.is_bottom()) and (position.get_position() is False):
            trade_side = "buy"
            trade_product = new_ticker
            trade_funds = funds.get_capital()
        elif (new_order.is_top()) and (position.get_position()):
            trade_side = "sell"
            trade_product = new_order.get_key("product_id")
            trade_funds = get_size(trade_product,
                                   new_order.get_key("filled_size"))

        try:
            new_trade = private_client.place_market_order(
                product_id=trade_product, side=trade_side, funds=trade_funds)
            writer = open(Data.Path, "w")
            writer.write(new_trade['id'])
            writer.close()
            writer = open(Data.Time, "w")
            writer.write(new_trade['done_at'])
            writer.close()
        except NameError as ne:
            print(ne.with_traceback())
        except KeyError as ke:
            print(ke.with_traceback())

        return 'success', 200

    elif request.method == 'GET':
        return redirect('http://3.218.228.129/login')

    else:
        abort(400)