本文整理汇总了Python中wallet.wallet.get_asset_definition函数的典型用法代码示例。如果您正苦于以下问题:Python get_asset_definition函数的具体用法?Python get_asset_definition怎么用?Python get_asset_definition使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_asset_definition函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: btnSellClicked
def btnSellClicked(self):
valid = True
if not self.edtSellQuantity.text().toDouble()[1]:
self.edtSellQuantity.setStyleSheet('background:#FF8080')
valid = False
if not self.edtSellPrice.text().toDouble()[1]:
self.edtSellPrice.setStyleSheet('background:#FF8080')
valid = False
if not valid:
return
moniker = str(self.cbMoniker.currentText())
asset = wallet.get_asset_definition(moniker)
value = self.edtSellQuantity.text().toDouble()[0]
bitcoin = wallet.get_asset_definition('bitcoin')
price = self.edtSellPrice.text().toDouble()[0]
delta = wallet.get_available_balance(asset) - asset.parse_value(value)
if delta < 0:
message = 'The transaction amount exceeds available balance by %s %s' % \
(asset.format_value(-delta), moniker)
QtGui.QMessageBox.critical(self, '', message, QtGui.QMessageBox.Ok)
return
offer = wallet.p2ptrade_make_offer(True, {
'moniker': moniker,
'value': value,
'price': price,
})
wallet.p2p_agent.register_my_offer(offer)
self.update_offers()
self.edtSellQuantity.setText('')
self.edtSellPrice.setText('')
示例2: update_offers
def update_offers(self):
moniker = str(self.cbMoniker.currentText())
if moniker == '':
return
bitcoin = wallet.get_asset_definition('bitcoin')
asset = wallet.get_asset_definition(moniker)
color_desc = asset.get_color_set().color_desc_list[0]
wallet.p2p_agent.update()
selected_oids = [None, None]
viewsList = [
[0, self.tvBuy, self.proxyModelBuy],
[1, self.tvSell, self.proxyModelSell],
]
for i, view, proxy in viewsList:
selected = view.selectedIndexes()
if selected:
index = proxy.index(selected[0].row(), 3)
selected_oids[i] = str(proxy.data(index).toString())
self.modelBuy.removeRows(0, self.modelBuy.rowCount())
self.modelSell.removeRows(0, self.modelSell.rowCount())
offers = wallet.p2p_agent.their_offers.items() + wallet.p2p_agent.my_offers.items()
for i, item in enumerate(offers):
oid, offer = item
data = offer.get_data()
if data['A'].get('color_spec') == color_desc:
value = data['A']['value']
total = data['B']['value']
price = int(total*asset.unit/float(value))
self.modelSell.addRow([
bitcoin.format_value(price),
asset.format_value(value),
bitcoin.format_value(total),
oid,
])
if data['B'].get('color_spec') == color_desc:
value = data['B']['value']
total = data['A']['value']
price = int(total*asset.unit/float(value))
self.modelBuy.addRow([
bitcoin.format_value(price),
asset.format_value(value),
bitcoin.format_value(total),
oid,
])
for i, view, proxy in viewsList:
for row in xrange(proxy.rowCount()):
oid = str(proxy.data(proxy.index(row, 3)).toString())
if oid == selected_oids[i]:
view.selectRow(row)
示例3: updateAvailableBalance
def updateAvailableBalance(self):
moniker = str(self.cbMoniker.currentText())
if moniker:
asset = wallet.get_asset_definition(moniker)
balance = wallet.get_available_balance(moniker)
self.edtAmount.setMaximum(balance)
self.lblAvailaleBalance.setText("%s %s" % (asset.format_value(balance), moniker))
示例4: update_balance
def update_balance(self):
moniker = str(self.cbMoniker.currentText())
if moniker == '':
return
asset = wallet.get_asset_definition('bitcoin')
value = asset.format_value(wallet.get_available_balance(asset))
self.lblBuy.setText('<b>Buy</b> %s' % moniker)
self.lblBuyAvail.setText('(Available: %s bitcoin)' % value)
asset = wallet.get_asset_definition(moniker)
value = asset.format_value(wallet.get_available_balance(asset))
self.lblSell.setText('<b>Sell</b> %s' % moniker)
self.lblSellAvail.setText('(Available: %s %s)' % (value, moniker))
self.update_offers()
示例5: cbMonikerIndexChanged
def cbMonikerIndexChanged(self):
moniker = str(self.cbMoniker.currentText())
if moniker == '':
return
asset = wallet.get_asset_definition('bitcoin')
value = asset.format_value(wallet.get_available_balance(asset))
text = '<b>Buy</b> {0} (Available: {1} bitcoin)'.format(moniker, value)
self.lblBuy.setText(text)
asset = wallet.get_asset_definition(moniker)
value = asset.format_value(wallet.get_available_balance(asset))
text = '<b>Sell</b> {0} (Available: {1} {0})'.format(moniker, value)
self.lblSell.setText(text)
self.update_offers()
示例6: tvSellDoubleClicked
def tvSellDoubleClicked(self):
selected = self.tvSell.selectedIndexes()
if not selected:
return
index = self.proxyModelSell.index(selected[0].row(), 3)
oid = str(self.proxyModelSell.data(index).toString())
if oid in wallet.p2p_agent.their_offers:
offer = wallet.p2p_agent.their_offers[oid]
moniker = str(self.cbMoniker.currentText())
asset = wallet.get_asset_definition(moniker)
if wallet.get_available_balance(asset) < offer.get_data()['A']['value']:
QtGui.QMessageBox.warning(self, '', "Not enough money...",
QtGui.QMessageBox.Cancel)
return
message = "Buy <b>{value}</b> {moniker} for <b>{course}</b> \
bitcoin (Total: <b>{total}</b> bitcoin)".format(**{
'value': self.proxyModelSell.data(selected[1]).toString(),
'moniker': moniker,
'course': self.proxyModelSell.data(selected[0]).toString(),
'total': self.proxyModelSell.data(selected[2]).toString(),
})
retval = QtGui.QMessageBox.question(
self, "Confirm buy coins", message,
QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel,
QtGui.QMessageBox.Cancel)
if retval != QtGui.QMessageBox.Yes:
return
new_offer = wallet.p2ptrade_make_mirror_offer(offer)
wallet.p2p_agent.register_my_offer(new_offer)
else:
offer = wallet.p2p_agent.my_offers[oid]
wallet.p2p_agent.cancel_my_offer(offer)
self.update_offers()
示例7: contextMenuEvent
def contextMenuEvent(self, event):
selected = self.tableView.selectedIndexes()
if not selected:
return
actions = [
self.actionCopyMoniker,
self.actionCopyColorSet,
self.actionCopyUnit,
self.actionCopyAsJSON,
self.actionShowAddresses,
]
menu = QtGui.QMenu()
for action in actions:
menu.addAction(action)
result = menu.exec_(event.globalPos())
if result is None or result not in actions:
return
if actions.index(result) in [0, 1, 2]:
index = selected[actions.index(result)]
QtGui.QApplication.clipboard().setText(
self.proxyModel.data(index).toString())
elif actions.index(result) == 3:
moniker = str(self.proxyModel.data(selected[0]).toString())
asset = wallet.get_asset_definition(moniker)
QtGui.QApplication.clipboard().setText(
json.dumps(asset.get_data()))
elif actions.index(result) == 4:
window = self.parentWidget().parentWidget().parentWidget()
window.gotoReceivePage()
window.receivepage.setMonikerFilter(
self.proxyModel.data(selected[0]).toString())
示例8: updateAvailableBalance
def updateAvailableBalance(self):
moniker = str(self.cb_monikers.currentText())
if moniker:
balance = wallet.get_balance(moniker)
asset = wallet.get_asset_definition(moniker)
self.edt_amount.setMaximum(balance)
self.lbl_availaleBalance.setText(
'%s %s' % (asset.format_value(balance), moniker))
示例9: getData
def getData(self):
moniker = str(self.cbMoniker.currentText())
asset = wallet.get_asset_definition(moniker)
value = asset.parse_value(str(self.edtAmount.value()))
return {
'address': str(self.edtAddress.text()),
'value': value,
'moniker': moniker,
}
示例10: update
def update(self):
allowTextSelection = (
QtCore.Qt.LinksAccessibleByMouse |
QtCore.Qt.TextSelectableByKeyboard |
QtCore.Qt.TextSelectableByMouse)
self.scrollAreaContents = QtGui.QWidget()
self.scrollArea.setWidget(self.scrollAreaContents)
self.scrollAreaLayout = QtGui.QVBoxLayout(self.scrollAreaContents)
hbox = QtGui.QHBoxLayout()
hbox.addItem(QtGui.QSpacerItem(20, 0))
hbox.setStretch(0, 1)
updateButton = QtGui.QPushButton('Update', self.scrollAreaContents)
updateButton.clicked.connect(self.updateButtonClicked)
hbox.addWidget(updateButton)
self.scrollAreaLayout.addLayout(hbox)
for moniker in wallet.get_all_monikers():
asset = wallet.get_asset_definition(moniker)
address = wallet.get_some_address(asset)
total_balance = wallet.get_total_balance(asset)
unconfirmed_balance = wallet.get_unconfirmed_balance(asset)
groupBox = QtGui.QGroupBox(moniker, self.scrollAreaContents)
layout = QtGui.QFormLayout(groupBox)
label = QtGui.QLabel(groupBox)
label.setText('Balance:')
layout.setWidget(0, QtGui.QFormLayout.LabelRole, label)
balance_text = asset.format_value(total_balance)
if not (unconfirmed_balance == 0):
balance_text += " (%s unconfirmed, %s available)" % \
(asset.format_value(unconfirmed_balance),
asset.format_value(wallet.get_available_balance(asset)))
label = QtGui.QLabel(groupBox)
label.setTextInteractionFlags(allowTextSelection)
label.setCursor(QtGui.QCursor(QtCore.Qt.IBeamCursor))
label.setText(balance_text)
layout.setWidget(0, QtGui.QFormLayout.FieldRole, label)
label = QtGui.QLabel(groupBox)
label.setText('Address:')
layout.setWidget(1, QtGui.QFormLayout.LabelRole, label)
label = QtGui.QLabel(groupBox)
label.setTextInteractionFlags(allowTextSelection)
label.setCursor(QtGui.QCursor(QtCore.Qt.IBeamCursor))
label.setText(address)
layout.setWidget(1, QtGui.QFormLayout.FieldRole, label)
self.scrollAreaLayout.addWidget(groupBox)
self.scrollAreaLayout.addItem(QtGui.QSpacerItem(20, 0))
self.scrollAreaLayout.setStretch(self.scrollAreaLayout.count()-1, 1)
示例11: changeTotalBTC
def changeTotalBTC(self):
amount = self.edtUnits.text().toInt()
units = self.edtAtoms.text().toInt()
if amount[1] and units[1]:
need = amount[0] * units[0]
text = "%s bitcoin" % wallet.get_asset_definition("bitcoin").format_value(need)
if need > self.availableBTC:
text = '<font color="#FF3838">%s</font>' % text
self.lblTotalBTC.setText(text)
示例12: lblSellTotalChange
def lblSellTotalChange(self):
bitcoin = wallet.get_asset_definition('bitcoin')
quantity = self._to_decimal(self.edtSellQuantity)
price = bitcoin.parse_value(self._to_decimal(self.edtSellPrice))
total = quantity * price
if total:
self.lblSellTotal.setText('%sBTC' % bitcoin.format_value(total))
else:
self.lblSellTotal.setText('')
示例13: validate_sell_input
def validate_sell_input(self, quantity, price):
moniker = str(self.cbMoniker.currentText())
asset = wallet.get_asset_definition(moniker)
bitcoin = wallet.get_asset_definition('bitcoin')
# check if quantity was given
if quantity <= Decimal("0"): # no quantity
self.edtSellQuantity.setStyleSheet('background:#FF8080')
return False
# check if price was given
if price <= Decimal("0"): # no price
self.edtSellPrice.setStyleSheet('background:#FF8080')
return False
# quantity must be multiple of atom
if not asset.validate_value(quantity):
atom = asset.format_value(1)
message = "Quantity must be a multiple of %s!" % atom
QtGui.QMessageBox.critical(self, '', message, QtGui.QMessageBox.Ok)
self.edtSellQuantity.setStyleSheet('background:#FF8080')
return False
# price must be multiple of atom
if not bitcoin.validate_value(price):
atom = bitcoin.format_value(1)
message = "Price must be a multiple of %s!" % atom
QtGui.QMessageBox.critical(self, '', message, QtGui.QMessageBox.Ok)
self.edtSellPrice.setStyleSheet('background:#FF8080')
return False
# check if amount exceeds available balance
needed = asset.parse_value(quantity)
delta = wallet.get_available_balance(asset) - needed
if delta < 0:
args = (asset.format_value(-delta), moniker)
msg_str = 'The amount exceeds available balance by %s %s'
message = msg_str % args
QtGui.QMessageBox.critical(self, '', message, QtGui.QMessageBox.Ok)
self.edtSellQuantity.setStyleSheet('background:#FF8080')
self.edtSellPrice.setStyleSheet('background:#FF8080')
return False
return True
示例14: validate_buy_input
def validate_buy_input(self, quantity, price):
moniker = str(self.cbMoniker.currentText())
asset = wallet.get_asset_definition(moniker)
bitcoin = wallet.get_asset_definition('bitcoin')
# check if quantity was given
if quantity <= Decimal("0"): # no quantity
self.edtBuyQuantity.setStyleSheet('background:#FF8080')
return False
# check if price was given
if price <= Decimal("0"): # no price
self.edtBuyPrice.setStyleSheet('background:#FF8080')
return False
# quantity must be multiple of atom
if not asset.validate_value(quantity):
message = "Quantity must be a multiple of %s!" % asset.get_atom()
QtGui.QMessageBox.critical(self, '', message, QtGui.QMessageBox.Ok)
self.edtBuyQuantity.setStyleSheet('background:#FF8080')
return False
# price must be multiple of atom
if not bitcoin.validate_value(price):
message = "Price must be a multiple of %s!" % asset.get_atom()
QtGui.QMessageBox.critical(self, '', message, QtGui.QMessageBox.Ok)
self.edtBuyPrice.setStyleSheet('background:#FF8080')
return False
# check if amount exceeds available balance
needed = quantity * bitcoin.parse_value(price)
available = wallet.get_available_balance(bitcoin)
delta = available - needed
if delta < 0:
neg_delta = bitcoin.format_value(-delta)
msg_str = 'The amount exceeds available balance by %s bitcoin!'
message = msg_str % neg_delta
QtGui.QMessageBox.critical(self, '', message, QtGui.QMessageBox.Ok)
self.edtBuyQuantity.setStyleSheet('background:#FF8080')
self.edtBuyPrice.setStyleSheet('background:#FF8080')
return False
return True
示例15: lblSellTotalChange
def lblSellTotalChange(self):
self.lblSellTotal.setText('')
if self.edtSellQuantity.text().toDouble()[1] \
and self.edtSellPrice.text().toDouble()[1]:
value = self.edtSellQuantity.text().toDouble()[0]
bitcoin = wallet.get_asset_definition('bitcoin')
price = bitcoin.parse_value(
self.edtSellPrice.text().toDouble()[0])
total = value*price
self.lblSellTotal.setText('%s bitcoin' % bitcoin.format_value(total))