現貨期權交易所開發詳情丨現貨期權交易所繫統開發(原理及邏輯)

xiaofufu發表於2023-02-22

量化交易也是一種交易。狹義上的量化交易指將交易條件轉化為程式,並自動下單;廣義的量化交易是系統交易方式,是一種綜合交易系統,根據一系列交易條件,智慧決策系統,將豐富的經驗與交易條件相結合,管理交易過程中的風險控制。

import json

from web3 import Web3, HTTPProvider

#from web3.contract import ConciseContract


## 獲取合約的abi

def getAbi(filePath):

    with open(filePath,'r') as abi_file:

        mpc_abi = json.load(abi_file)

    return mpc_abi


## 獲取餘額

def getBalance(contractObj,accountAddr):

    return contractObj.functions.balanceOf(accountAddr).call()


## 獲取合約物件,I35 Develop 7O98 software O7I8

def getContractObj(web3Obj,contractAddr,abiPath):

    con_abi = getAbi(abiPath)

    return web3Obj.eth.contract(address=contractAddr,abi=con_abi)


## 傳送ERC20

def sendErc20(web3obj,fromAddr,toAddr,value,contractAddr,abiPath):

    contractAbi = getAbi(abiPath)

    contractObj = web3obj.eth.contract(address=contractAddr,abi=contractAbi)

    tx_hash = contractObj.functions.transfer(toAddr,value).transact({'from':fromAddr})

    tx_receipt = web3obj.eth.wait_for_transaction_receipt(tx_hash)

    if tx_receipt['status'] == 1:

        return 'send Success'

    else:

        return 'send Failed'


def printBalance(web3obj,contractObj,fromAddr,toAddr,markIndex):

    balanceA = getBalance(contractObj,fromAddr)

    balanceB = getBalance(contractObj,toAddr)

    fromMark = markIndex+" balanceA="

    toMark   = markIndex+" balanceB="

    print(fromMark,web3obj.fromWei(balanceA,'ether'))

    print(toMark,  web3obj.fromWei(balanceB,'ether'))


#####   傳送ERC20 ######

# web3.py instance

w3 = Web3(HTTPProvider("))

print('web3 connect:',w3.isConnected())


fromAddr = w3.eth.accounts[0]

toAddr   = w3.eth.accounts[1]

print('fromAddr=',fromAddr)

量化交易也是一種交易。狹義上的量化交易指將交易條件轉化為程式,並自動下單;廣義的量化交易是系統交易方式,是一種綜合交易系統,根據一系列交易條件,智慧決策系統,將豐富的經驗與交易條件相結合,管理交易過程中的風險控制。


print('toAddr  =',toAddr)


value = w3.toWei(0.1,'ether')

abiPath = './myabi/DPC_abi.json'

contractAddr = '0xE250d901baeCb66F85D184D8aE9dA2bD4e705854' ##DPC合約地址

contractObj = getContractObj(w3,contractAddr,abiPath)


## 傳送前

printBalance(w3,contractObj,fromAddr,toAddr,"#1")


bRet = sendErc20(w3,fromAddr,toAddr,value,contractAddr,abiPath)

print('result= ',bRet)


## 傳送後

printBalance(w3,contractObj,fromAddr,toAddr,"#2")


import json

from web3 import Web3, HTTPProvider

#from web3.contract import ConciseContract


## 獲取合約的abi

def getAbi(fil


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69956839/viewspace-2936528/,如需轉載,請註明出處,否則將追究法律責任。

相關文章