How to use create_swap method in lisa

Best Python code snippet using lisa_python

market.py

Source:market.py Github

copy

Full Screen

...81 self.banks.sort(key=lambda x: x.balance)82 most_floated = self.banks[0]83 most_fixed = self.banks[-1]84 if(most_floated.balance < 0 and most_fixed.balance > 0):85 self.create_swap(most_floated,most_fixed)86 def get_tenure_time(self,irs_value):87 return self.max_tenure88 def create_swap(self,fl,fx):89 irs_val = min(self.max_irs_value,min(abs(fl.balance),fx.balance))90 tenure = self.max_tenure91 self.add_edge(fx,fl,IRS(irs_val,tenure,self.time))92 fx.set_dirty()93 fl.set_dirty()94 def icreate_swap(self,fs):95 self.create_swap(fs[0],fs[1])96#97# Market with chances for IRS creation instead of the default one swap per dt98#99class ShuffleIRSMarket(Market):100 def create_swaps(self):101 floats = [b for b in self.banks if b.balance < 0 and fabs(b.balance) > self.irs_threshold]102 fixs = [b for b in self.banks if b.balance > 0 and b.balance > self.irs_threshold]103 self.generator.shuffle(floats)104 self.generator.shuffle(fixs)105 map(self.icreate_swap, itertools.izip(floats,fixs))106 #for (fl,fx) in itertools.izip(floats,fixs):107 # self.create_swap(fl,fx)108class ConstShuffleIRSMarket(ShuffleIRSMarket):109 def create_swaps(self):110 floats = [b for b in self.banks if b.balance < 0 and fabs(b.balance) > self.irs_threshold]111 fixs = [b for b in self.banks if b.balance > 0 and b.balance > self.irs_threshold]112 self.generator.shuffle(floats)113 self.generator.shuffle(fixs)114 map(self.icreate_swap, itertools.izip_longest(floats,fixs))115 def icreate_swap(self,fs):116 if(fs[0] == None):117 fs[1].register_failed_irs()118 return119 if(fs[1] == None):120 fs[0].register_failed_irs()121 return122 self.create_swap(fs[0],fs[1])123 fs[0].register_success_irs()124 fs[1].register_success_irs()125 def create_swap(self,fl,fx):126 irs_val = self.irs_threshold127 tenure = self.max_tenure128 self.add_edge(fx,fl,IRS(irs_val,tenure,self.time))129 fx.set_dirty()130 fl.set_dirty()131#132# Market in which the agents most in need get swaps with eachother133#134class SortedIRSMarket(Market):135 def create_swaps(self):136 floats = [b for b in self.banks if b.balance < 0 and fabs(b.balance) > self.irs_threshold]137 fixs = [b for b in self.banks if b.balance > 0 and b.balance > self.irs_threshold]138 floats.sort()139 fixs.sort(reverse=True)140 for (fx,fl) in itertools.izip(fixs,floats):141 self.create_swap(fl,fx)142class SortedRandomIRSMarket(Market):143 def create_swaps(self):144 floats = [b for b in self.banks if b.balance < 0 and fabs(b.balance) > self.irs_threshold]145 fixs = [b for b in self.banks if b.balance > 0 and b.balance > self.irs_threshold]146 floats.sort()147 fixs.sort(reverse=True)148 for (fx,fl) in itertools.izip(fixs,floats):149 irs_val = min(self.max_irs_value,min(abs(fl.balance),fx.balance))150 if(self.generator.rand() < (irs_val/self.max_irs_value)):151 self.create_swap(fl,fx)152class ShuffleRandomIRSMarket(Market):153 def create_swaps(self):154 floats = [b for b in self.banks if b.balance < 0 and fabs(b.balance) > self.irs_threshold]155 fixs = [b for b in self.banks if b.balance > 0 and b.balance > self.irs_threshold]156 self.generator.shuffle(floats)157 self.generator.shuffle(fixs)158 for (fx,fl) in itertools.izip(fixs,floats):159 irs_val = min(self.max_irs_value,min(abs(fl.balance),fx.balance))160 if(self.generator.rand() < (irs_val/self.max_irs_value)):...

Full Screen

Full Screen

versum_create_swap.py

Source:versum_create_swap.py Github

copy

Full Screen

...5from hicdex.types.versum_market.parameter.create_swap import CreateSwapParameter6from hicdex.types.versum_market.storage import VersumMarketStorage7import logging8_logger = logging.getLogger(__name__)9async def versum_create_swap(10 ctx: HandlerContext,11 create_swap: Transaction[CreateSwapParameter, VersumMarketStorage],12) -> None:13 swap_id = int(create_swap.storage.swap_counter) - 114 fa2, _ = await models.Fa2.get_or_create(contract=create_swap.parameter.token.address)15 creator, _ = await models.Holder.get_or_create(address=create_swap.data.sender_address)16 token = await models.Token.filter(id=proper_integer(create_swap.parameter.token.nat), fa2_id=create_swap.parameter.token.address).first()17 try:18 ask_model = models.Ask(19 id=swap_id, # type: ignore20 platform='versum',21 creator=creator,22 objkt_id=str(create_swap.parameter.token.nat),23 fa2=fa2,...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

...10 title__iexact='binance-smart-chain',11 )12 )13 contract = Contract.get_contract_by_blockchain_id(1)14 ValidatorSwap.create_swap(15 rpc_provider=rpc_provider,16 contract=contract,17 txn_hash=self.transaction_hash,18 event=self.event_data,19 )20 validator_swap = ValidatorSwap.displayed_objects.get(21 transaction__hash__iexact=self.transaction_hash,22 )23 self.assertEqual(24 validator_swap.transaction.event_data['transactionHash'],25 self.transaction_hash,26 "create_swap doesn't saved ValidatorSwap correctly",27 )28 def test_send_signature_to_relayer(self):29 rpc_provider = CustomRpcProvider(30 Network.displayed_objects.get(31 title__iexact='binance-smart-chain',32 )33 )34 contract = Contract.get_contract_by_blockchain_id(1)35 validator_swap = ValidatorSwap.create_swap(36 rpc_provider=rpc_provider,37 contract=contract,38 txn_hash=self.transaction_hash,39 event=self.event_data,40 )41 validator_swap.signature = self.signature42 validator_swap.send_signature_to_relayer()43 self.assertEqual(44 validator_swap.status,45 ValidatorSwap.STATUS_SIGNATURE_SEND,46 "signature wasn't send",...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful