Skip to content

Contractchange #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,22 @@
hash=hashlib.blake2b(intent,digest_size=32)
#then we finally sign the hash
```
## Margin Bank:
1. When you insert money to margin bank we give it in BASE6 but when we see balance it is in base9. internally the functions are implemented that way.
2. We expect you to give the arguments directly in DECIMALS.


## Making Direct Contract Calls:
1. for making contract calls. The one interacting with our contracts are implemented internally in `client.py`
2. we have exposed some generic functions through which you can make direct contract calls yourself
1. `def rpc_unsafe_moveCall(url,params, function_name: str, function_library: str, userAddress ,packageId, gasBudget=100000000 ):`
2. `def rpc_sui_executeTransactionBlock(url, txBytes, signature):`
3. The first one is used to serialise the contract calls you are going to make.
4. for second one you need to sign the result of first call with your signer and then make call along with serialised call and signature.
5. internally all our contract calls to packages uses these functions. for more information have a look at `rpc.py`
3. For making calls to SUI functions
1. For that we have exposed `def rpc_call_sui_function(url, params, method="suix_getCoins"):`
2. Here you can specify the params and the name of the sui function you are calling.
3. internally we use these calls to get the chain balance, usdc coins.


10 changes: 3 additions & 7 deletions examples/1.initialization.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import os
import sys

print (os.getcwd())
sys.path.append(os.getcwd()+"/src/")

import sys,os
#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")
from config import TEST_ACCT_KEY, TEST_NETWORK

from bluefin_client_sui import FireflyClient, Networks
from pprint import pprint
import asyncio
Expand Down
3 changes: 2 additions & 1 deletion examples/10.1.socket_readonly.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys,os
sys.path.append(os.getcwd()+"/src/")
#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")

import time
from config import TEST_ACCT_KEY, TEST_NETWORK
Expand Down
4 changes: 3 additions & 1 deletion examples/10.sockets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import sys,os
sys.path.append(os.getcwd()+"/src/")
#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")


import time
from config import TEST_ACCT_KEY, TEST_NETWORK
Expand Down
14 changes: 10 additions & 4 deletions examples/11.sub_accounts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import sys,os
#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")

from config import TEST_ACCT_KEY, TEST_SUB_ACCT_KEY, TEST_NETWORK
from bluefin_client_sui import FireflyClient, MARKET_SYMBOLS, ORDER_SIDE, ORDER_TYPE, Networks, OrderSignatureRequest
import asyncio
from bluefin_client_sui.utilities import *


async def main():
Expand All @@ -16,22 +21,23 @@ async def main():
print("Child: ", clientChild.get_public_address())

# # whitelist sub account
status = await clientParent.update_sub_account(MARKET_SYMBOLS.ETH, clientChild.get_public_address(), True)
status = await clientParent.update_sub_account(clientChild.get_public_address(), True)
print("Sub account created: {}".format(status))


clientChild.add_market(MARKET_SYMBOLS.ETH)

parent_leverage = await clientParent.get_user_leverage(MARKET_SYMBOLS.ETH)

await clientParent.adjust_leverage(MARKET_SYMBOLS.ETH,1)
parent_leverage = await clientParent.get_user_leverage(MARKET_SYMBOLS.ETH)
signature_request = OrderSignatureRequest(
symbol=MARKET_SYMBOLS.ETH, # sub account is only whitelisted for ETH market
maker=clientParent.get_public_address(), # maker of the order is the parent account
price=0,
quantity=0.02,
quantity=toSuiBase(0.02),
side=ORDER_SIDE.BUY,
orderType=ORDER_TYPE.MARKET,
leverage=parent_leverage,
leverage=toSuiBase(parent_leverage),
)

# order is signed using sub account's private key
Expand Down
4 changes: 3 additions & 1 deletion examples/12.open_order_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
an event, log its data and terminate connection
'''
import sys,os
sys.path.append(os.getcwd()+"/src/")
#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")

import time
from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_client_sui import FireflyClient, Networks, MARKET_SYMBOLS, SOCKET_EVENTS, ORDER_SIDE, ORDER_TYPE, OrderSignatureRequest
Expand Down
4 changes: 3 additions & 1 deletion examples/13.orderbook_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
In this code example we open a socket connection and listen to orderbook update event
'''
import sys,os
sys.path.append(os.getcwd()+"/src/")
#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")

import time
from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_client_sui import FireflyClient, Networks, MARKET_SYMBOLS, SOCKET_EVENTS, ORDER_SIDE, ORDER_TYPE, OrderSignatureRequest
Expand Down
5 changes: 3 additions & 2 deletions examples/14.web_sockets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import sys,os
sys.path.append(os.getcwd()+"/src/")
#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")

import time
from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_client_sui import FireflyClient, Networks, MARKET_SYMBOLS, SOCKET_EVENTS, config_logging
Expand Down
4 changes: 3 additions & 1 deletion examples/15.get_funding_history.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

import sys,os
sys.path.append(os.getcwd()+"/src/")
#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")

from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_client_sui import FireflyClient, Networks, MARKET_SYMBOLS, GetFundingHistoryRequest
from pprint import pprint
Expand Down
4 changes: 4 additions & 0 deletions examples/16.listening_events_using_sub_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
has no position of its own. So when placing orders or listening to position updates
the sub account must specify the parent address whose position its listening.
'''
import sys,os
#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")

import time, sys
from config import TEST_ACCT_KEY, TEST_NETWORK, TEST_SUB_ACCT_KEY
from bluefin_client_sui import FireflyClient, Networks, MARKET_SYMBOLS, OrderSignatureRequest, ORDER_SIDE, ORDER_TYPE, SOCKET_EVENTS
Expand Down
4 changes: 3 additions & 1 deletion examples/17.1.get_orders_readonly.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
'''

import sys,os
sys.path.append(os.getcwd()+"/src/")
#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")

from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_client_sui import FireflyClient, Networks, MARKET_SYMBOLS, ORDER_STATUS, ORDER_TYPE
import asyncio
Expand Down
4 changes: 3 additions & 1 deletion examples/17.get_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
mixed together to fetch the exact data that user needs.
'''
import sys,os
sys.path.append(os.getcwd()+"/src/")
#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")

from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_client_sui import FireflyClient, Networks, MARKET_SYMBOLS, ORDER_STATUS, ORDER_TYPE
import asyncio
Expand Down
4 changes: 3 additions & 1 deletion examples/18.dms_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json

import sys,os
sys.path.append(os.getcwd()+"/src/")
#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")

from config import TEST_ACCT_KEY, TEST_SUB_ACCT_KEY, TEST_NETWORK
from bluefin_client_sui import FireflyClient, MARKET_SYMBOLS, ORDER_SIDE, ORDER_TYPE, Networks, OrderSignatureRequest
import asyncio
Expand Down
4 changes: 3 additions & 1 deletion examples/19.Generate_readonly_token.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

import sys,os
sys.path.append(os.getcwd()+"/src/")
#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")

from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_client_sui import FireflyClient, Networks
from pprint import pprint
Expand Down
4 changes: 3 additions & 1 deletion examples/2.user_info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import sys,os
sys.path.append(os.getcwd()+"/src/")
#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")

from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_client_sui import FireflyClient, Networks, MARKET_SYMBOLS
from pprint import pprint
Expand Down
46 changes: 0 additions & 46 deletions examples/20.contract_call.py

This file was deleted.

19 changes: 14 additions & 5 deletions examples/3.balance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys,os
sys.path.append(os.getcwd()+"/src/")

#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")
from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_client_sui import FireflyClient, Networks
import asyncio
Expand Down Expand Up @@ -32,18 +32,27 @@ async def main():

# deposit usdc to margin bank
# must have native chain tokens to pay for gas fee
print('USDC deposited:', await client.deposit_margin_to_bank(10))
usdc_coins=client.get_usdc_coins()
## we expect that you have some coins in your usdc,
coin_obj_id=usdc_coins["data"][1]["coinObjectId"]
print('USDC deposited:', await client.deposit_margin_to_bank(50, coin_obj_id))

# check margin bank balance
resp = await client.get_margin_bank_balance()
print('Margin bank balance:', resp)

# withdraw margin bank balance
print('USDC Withdrawn:', await client.withdraw_margin_from_bank(resp))
# withdraw 10 USD from margin bank balance
print('USDC Withdrawn:', await client.withdraw_margin_from_bank(10))

# check margin bank balance
print('Margin bank balance:', await client.get_margin_bank_balance())


print ("Withdraw everything from margin balance", await client.withdraw_all_margin_from_bank())

# check margin bank balance
print('Margin bank balance:', await client.get_margin_bank_balance())

await client.close_connections()


Expand Down
22 changes: 6 additions & 16 deletions examples/4.placing_orders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import sys,os
sys.path.append(os.getcwd()+"/src/")
#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")

from bluefin_client_sui.utilities import toSuiBase
from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_client_sui import FireflyClient, Networks, MARKET_SYMBOLS, ORDER_SIDE, ORDER_TYPE, OrderSignatureRequest
Expand Down Expand Up @@ -40,29 +42,17 @@ async def place_market_order(client: FireflyClient):


# default leverage of account is set to 3 on firefly
user_leverage = await client.get_user_leverage(MARKET_SYMBOLS.ETH)
await client.adjust_leverage(MARKET_SYMBOLS.BTC,1)

# creates a LIMIT order to be signed
'''
signature_request = OrderSignatureRequest(
symbol=MARKET_SYMBOLS.ETH, # market symbol
price=0, # price at which you want to place order
quantity=0.01, # quantity
side=ORDER_SIDE.BUY,
orderType=ORDER_TYPE.MARKET,
leverage=user_leverage
) '''
signature_request = OrderSignatureRequest(
symbol=MARKET_SYMBOLS.ETH,
# market = "0x25a869797387e2eaa09c658c83dc0deaba99bb02c94447339c06fdbe8287347e",
symbol=MARKET_SYMBOLS.BTC,
price = toSuiBase(0),
quantity = toSuiBase(1),
leverage = toSuiBase(1),
side = ORDER_SIDE.BUY,
reduceOnly = False,
postOnly = False,
orderbookOnly = True,
maker = "0xa3c3504d90c428274beaa89f1238a769ea1d1c3516c31c0f4157f33787367af0",
expiration = 1700530261000,
salt = 1668690862116,
orderType = ORDER_TYPE.MARKET,
Expand Down Expand Up @@ -93,9 +83,9 @@ async def main():
await client.init(True)

# add market that you wish to trade on ETH/BTC are supported currently
client.add_market(MARKET_SYMBOLS.BTC)
client.add_market(MARKET_SYMBOLS.ETH)

# await place_limit_order(client)
await place_market_order(client)
await place_limit_order(client)

Expand Down
7 changes: 5 additions & 2 deletions examples/5.adjusting_leverage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import sys,os
sys.path.append(os.getcwd()+"/src/")
#Commented as of now, to be only uncommented when testing library
#sys.path.append(os.getcwd()+"/src/")


from config import TEST_ACCT_KEY, TEST_NETWORK
from bluefin_client_sui import FireflyClient, Networks, MARKET_SYMBOLS
Expand All @@ -12,7 +14,8 @@ async def main():
client = FireflyClient(
True, # agree to terms and conditions
Networks[TEST_NETWORK], # network to connect with
TEST_ACCT_KEY, # private key of wallet
TEST_ACCT_KEY # private key of wallet

)

await client.init(True)
Expand Down
Loading