Skip to content

Commit

Permalink
add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmiei committed Nov 16, 2024
1 parent ff8ee83 commit dfa3b10
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/ws_create_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import sys
import asyncio

Check failure on line 3 in examples/ws_create_order.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F401)

examples/ws_create_order.py:3:8: F401 `asyncio` imported but unused


root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(root)

from binance.client import Client

## create order using websockets sync
## the API is very similar to the REST API

def main():
api_key = "" # your api_key here
secret = "" # your secret here
client = Client(api_key, secret, testnet=True)
order = client.ws_create_order(
symbol="LTCUSDT",
side="BUY",
type="MARKET",
quantity=0.1,
)
print(order['orderId'])

main()
28 changes: 28 additions & 0 deletions examples/ws_create_order_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import sys
import asyncio


root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(root)

from binance import AsyncClient

## create order using websockets async
## the API is very similar to the REST API

async def main():
api_key = "" # your api_key here
secret = "" # your secret here
client = AsyncClient(api_key, secret, testnet=True)
order = await client.ws_create_order(
symbol="LTCUSDT",
side="BUY",
type="MARKET",
quantity=0.1,
)
print(order['orderId'])
await client.close_connection()


asyncio.run(main())

0 comments on commit dfa3b10

Please sign in to comment.