By Jose Manuel


2018-11-08 23:04:29 8 Comments

I have a function in Python that include self as the first argument. However, when I execute the function I got the following error:

NameError: name 'self' is not defined

The function is defined as per below. And I cannot understand what I should include in the function instead of self to make it work. I call the function as:

order_create_new(self, 'eth', 'buy', 50, 10)
def order_create_new(self, symbol, side, price, qty):
    now = int(time.time() * 1000)
    query_params = {
        'timestamp': now,
        'recvWindow': 5000,
        'order_symbol': symbol,
        'order_side': side,
        'order_price': str(price),
        'order_size': str(qty),
        'type': 'limit'
    }
    url = self.exchange_endpoint + self.order_add_api
    res = self._transmit_encrypted_request(HttpMethod.POST, url, query_params)
    order = Order(res.json())
    order.http_response_code = res.status_code
    return order

In addition, there are also a few classes included at the beginning of the script containing the init function.

class ExchangeCoss():
exchange_endpoint = "https://api.coss.io/v1"
order_add_api = "/order/add"

public_api_key = "x"
private_api_key_string = "x"
private_api_key = bytearray(private_api_key_string.encode())

def __init__(self):
    super(ExchangeCoss, self).__init__()
    self.symbol_list = {}
    self.trading_pairs = {}
    self.min_order_sizes = {}
    self.account_info = None

However, I cannot make it work...Any help is highly appreciated

0 comments

Related Questions

Sponsored Content

35 Answered Questions

[SOLVED] How do I list all files of a directory?

  • 2010-07-08 19:31:22
  • duhhunjonn
  • 2720165 View
  • 3051 Score
  • 35 Answer
  • Tags:   python directory

16 Answered Questions

[SOLVED] How to make a chain of function decorators?

49 Answered Questions

[SOLVED] How to merge two dictionaries in a single expression?

88 Answered Questions

[SOLVED] How do JavaScript closures work?

40 Answered Questions

[SOLVED] How do I check whether a file exists without exceptions?

41 Answered Questions

[SOLVED] How do I sort a dictionary by value?

34 Answered Questions

[SOLVED] var functionName = function() {} vs function functionName() {}

21 Answered Questions

[SOLVED] Set a default parameter value for a JavaScript function

18 Answered Questions

[SOLVED] Using global variables in a function

19 Answered Questions

[SOLVED] What is the purpose of self?

  • 2010-04-25 20:22:28
  • richzilla
  • 703107 View
  • 920 Score
  • 19 Answer
  • Tags:   python class oop self

Sponsored Content