コード例 #1
0
ファイル: seed.py プロジェクト: Ssawalha/Deployable-TTrader
def seed(dbpath=DBPATH):
    ORM.dbpath = dbpath

    default = Account(username='******',
                      balance=10000.00,
                      first='sami',
                      last='s',
                      api_key="12345678912345678902")
    default.set_password('1234')
    default.save()

    default_buy = Trade(buy_sell='Buy',
                        username='******',
                        ticker='tsla',
                        price='100',
                        shares='10',
                        time=time())
    default_buy.save()

    default_sale = Trade(buy_sell='Sell',
                         username='******',
                         ticker='tsla',
                         price='110',
                         shares='5',
                         time=time())
    default_sale.save()

    default_position = Position(username='******', ticker='tsla', shares='5')
    default_position.save()
コード例 #2
0
ファイル: testPosition.py プロジェクト: ahadbadruddin/ttrader
    def setUp(self):
        build_user()
        build_positions()

        mike = User(**{
             "username": "******",
             "realname": "Mike Bloom",
             "balance": 10000.0
        })
        mike.hash_password("password")
        mike.save()

        appl = Position(**{
            "ticker" : "AAPL",
            "amount": 5,
            "user_info_pk": mike.pk
        })

        tsla = Position(**{
            "ticker" : "TSLA",
            "amount": 10,
            "user_info_pk": mike.pk
        })

        appl.save()
        tsla.save()
コード例 #3
0
ファイル: user.py プロジェクト: ahadbadruddin/ttrader
 def buy(self, ticker, amount):
     #TODO make a trade
     """ buy a stock. if there is no current position, create one, if there is
     increase its amount. no return value """
     if amount < 0:
         raise ValueError
     cost = get_price(ticker)* amount
     if self.balance < cost:
         raise InsufficientFundsError
     self.balance -= cost
     current_position = self.position_for_stock(ticker)
     if current_position is None:
         current_position = Position(ticker=ticker, amount=0, user_info_pk=self.pk)
     current_position.amount += amount
     current_position.save()
     self.save
コード例 #4
0
ファイル: pms.py プロジェクト: zhangkaiqiang128/PMS
def position_submit():

    position = Position()

    position.lng = float(request.args.get("lng"))
    position.lat = float(request.args.get("lat"))
    position.device_id = request.args.get("id")
    position.device_type = request.args.get("type")
    position.coords_type = request.args.get("coords_type")

    position.post_time = time.strftime(
        "%Y-%m-%d %H:%M:%S",
        time.localtime(int(request.args.get("time")) / 1000))
    position.receive_time = time.strftime("%Y-%m-%d %H:%M:%S",
                                          time.localtime())

    Cache.write(position)
    position.save()

    res = {"status": 200, "message": "success", "content": {}}

    return json.dumps(res)
コード例 #5
0
ファイル: pms.py プロジェクト: zhangkaiqiang128/PMS
def position_submit():

    position = Position()

    position.lng = float(request.args.get("lng"))
    position.lat = float(request.args.get("lat"))
    position.device_id = request.args.get("id")
    position.device_type = request.args.get("type")
    position.coords_type = request.args.get("coords_type")

    position.post_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(request.args.get("time"))/1000))
    position.receive_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    Cache.write(position)
    position.save()

    res = {
        "status": 200,
        "message": "success",
        "content": {}
    }

    return json.dumps(res)