-
Notifications
You must be signed in to change notification settings - Fork 31
Support MARKET order type #82
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3210527
Support TPSL order type
alexex10 b5da96f
Support TPSL order type
alexex10 b01bae5
Support TPSL order type
alexex10 6deb2b0
Support TPSL order type
alexex10 0108276
Support MARKET order type
alexex10 c927bf9
Support MARKET order type
alexex10 7e426c1
Support MARKET order type
alexex10 29dc388
Support MARKET order type
alexex10 823249b
Support MARKET order type
alexex10 4ff9dcd
Support MARKET order type
alexex10 892fd47
Support MARKET order type
alexex10 46e5fcd
Support MARKET order type
alexex10 40ed9e9
Support MARKET order type
alexex10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import logging | ||
| from asyncio import run | ||
| from decimal import Decimal | ||
|
|
||
| from examples.init_env import init_env | ||
| from x10.config import BTC_USD_MARKET | ||
| from x10.perpetual.accounts import StarkPerpetualAccount | ||
| from x10.perpetual.configuration import TESTNET_CONFIG | ||
| from x10.perpetual.order_object import create_order_object | ||
| from x10.perpetual.orders import OrderSide, OrderType, TimeInForce | ||
| from x10.perpetual.trading_client import PerpetualTradingClient | ||
| from x10.utils.order import get_price_with_slippage | ||
|
|
||
| LOGGER = logging.getLogger() | ||
| MARKET_NAME = BTC_USD_MARKET | ||
| ENDPOINT_CONFIG = TESTNET_CONFIG | ||
| SLIPPAGE = Decimal(0.0075) | ||
|
|
||
|
|
||
| async def run_example(): | ||
| env_config = init_env() | ||
| stark_account = StarkPerpetualAccount( | ||
| api_key=env_config.api_key, | ||
| public_key=env_config.public_key, | ||
| private_key=env_config.private_key, | ||
| vault=env_config.vault_id, | ||
| ) | ||
| trading_client = PerpetualTradingClient(ENDPOINT_CONFIG, stark_account) | ||
| markets_dict = await trading_client.markets_info.get_markets_dict() | ||
| market_stats = await trading_client.markets_info.get_market_statistics(market_name=MARKET_NAME) | ||
|
|
||
| market = markets_dict[MARKET_NAME] | ||
|
|
||
| order_side = OrderSide.SELL | ||
| order_size = market.trading_config.min_order_size | ||
|
|
||
| best_market_price = market_stats.data.ask_price if order_side == OrderSide.BUY else market_stats.data.bid_price | ||
| order_price = get_price_with_slippage( | ||
| side=order_side, | ||
| price=best_market_price, | ||
| min_price_change=market.trading_config.min_price_change, | ||
| slippage=SLIPPAGE, | ||
| ) | ||
|
|
||
| LOGGER.info("Creating MARKET order object for market: %s", market.name) | ||
|
|
||
| new_order = create_order_object( | ||
| account=stark_account, | ||
| order_type=OrderType.MARKET, | ||
| starknet_domain=ENDPOINT_CONFIG.starknet_domain, | ||
| market=market, | ||
| side=order_side, | ||
| amount_of_synthetic=order_size, | ||
| price=order_price, | ||
| time_in_force=TimeInForce.IOC, | ||
| reduce_only=False, | ||
| post_only=False, | ||
| ) | ||
|
|
||
| LOGGER.info("Placing order...") | ||
|
|
||
| placed_order = await trading_client.orders.place_order(order=new_order) | ||
|
|
||
| LOGGER.info("Order is placed: %s", placed_order.to_pretty_json()) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| run(main=run_example()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicit for now