1 Replies - 707 Views - Last Post: 11 January 2015 - 07:15 PM Rate Topic: -----

#1 grafs50   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 23-March 14

Problems creating a concept Bitcoin trader

Posted 11 January 2015 - 06:34 PM

First off, obviously I'm just using this as a practice. I don't intend on creating a real, trading software with my limited knowledge of programming.

I'm trying to create a simple program that creates a Bitcoin price, starting at $270, which changes either 1, 3, or 5 upwards or downwards.If the price goes up 3 times in a row, I would like to issue a "buy," and put $1000 in at whatever price Bitcoin is currently at, and sell out when the price has declined twice in a row. Right now, I'm simply trying to create 3 variables, each holding one of the last 3 prices. Here is my code, and the error:

import random

class pricechanger(object):

    price = 270
    pricedirection = random.randint(1,4)
    pricevelocity = random.randrange(1,3)


    def _init_(self):

        return 0

    def pricemover(self):

        if pricedirection == 1 or pricedirection == 3:

            if pricevelocity == 1:
                price += 1

            if pricevelocity == 2:
                price+=3 

            if pricevelocity == 3:
                price+=5

        if  pricedirection == 4:
            if pricevelocity == 1:
                price = price-1

            if pricevelocity == 2:
                price = price-3

            if pricevelocity == 3:
                price=price-5

    
    


import pricechanger
import time

class FakeBitcoinTrader():

    def prices():

            while True:
                a=1
                price = pricechanger.pricemover(x)

                if a == 1:
                    price = price1

                if a == 2:
                    price = price2

                if a == 3:
                    a=0

                print("price:"+price)
                print("price1"+price1)
                print("price2"+price2)
                print("a:"+a)
                time.sleep(10)

                a=a+1

    prices()
        #price1
        #price2
        




Error:

Every other time the code runs, it does not return an error. Sometimes it outputs a value 270+/-5, sometimes it doesn't output anything.
Every second time (so far anyways) it outputs this.

Traceback (most recent call last):
File "/home/matthew/FakeBitcoinTrader.py", line 44, in <module>
class FakeBitcoinTrader():
File "/home/matthew/FakeBitcoinTrader.py", line 69, in FakeBitcoinTrader
prices()
File "/home/matthew/FakeBitcoinTrader.py", line 50, in prices
price = pricechanger.pricemover(x)
AttributeError: 'module' object has no attribute 'pricemover'

Is This A Good Question/Topic? 0
  • +

Replies To: Problems creating a concept Bitcoin trader

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5612
  • View blog
  • Posts: 14,686
  • Joined: 18-April 07

Re: Problems creating a concept Bitcoin trader

Posted 11 January 2015 - 07:15 PM

Two things I can mention about this code is...

1) Your init function should not return a value. Init is designed to return itself (it is used to build the object itself). So delete the return 0 part.
2) I think the error you are getting is because you have the class named the same as the module. So when you call pricemover on your pricechanger class, it thinks you are talking about the module named pricecharger. One way you can solve this is to change your import to the format from pricecharger import pricecharger which is saying "import the class pricecharger from the module called pricecharger" which may be more specific. Another way is to change the case of the class to PriceCharger so it is seen as being different as the lowercase package name.

So try these recommendations and let us know how this goes. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1