Skip to content

Commit

Permalink
Update for position mode switch and minor bugs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierXIEXIN committed May 21, 2020
1 parent 98cdeec commit 71678a6
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 215 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ binance_futures.egg-info/*

# jupyter
*.ipynb_checkpoints
*.ipynb
*.ipynb

# Mac system
.DS_Store
3 changes: 0 additions & 3 deletions binance_d/.vscode/settings.json

This file was deleted.

4 changes: 2 additions & 2 deletions binance_d/constant/system.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

class WebSocketDefine:
Uri = "wss://dstream.binance.com/ws"
Uri = "wss://stream.binancefuture.com/ws"

class RestApiDefine:
Url = "https://dapi.binance.com"
Url = "https://testnet.binancefuture.com"



Expand Down
47 changes: 39 additions & 8 deletions binance_d/impl/restapirequestimpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,38 @@ def parse(json_wrapper):

request.json_parser = parse
return request



def change_position_mode(self, dualSidePosition):
check_should_not_none(dualSidePosition, "dualSidePosition")
builder = UrlParamsBuilder()
builder.put_url("dualSidePosition", dualSidePosition)

request = self.__create_request_by_post_with_signature("/dapi/v1/positionSide/dual", builder)

def parse(json_wrapper):
result = CodeMsg.json_parse(json_wrapper)
return result

request.json_parser = parse
return request


def get_position_mode(self):

request = self.__create_request_by_get_with_signature("/dapi/v1/positionSide/dual", builder)

def parse(json_wrapper):
result = PositionMode.json_parse(json_wrapper)
return result

request.json_parser = parse
return request



def post_order(self, symbol, side, ordertype,
timeInForce, quantity, reduceOnly, price, newClientOrderId, stopPrice, workingType):
timeInForce, quantity, reduceOnly, price, newClientOrderId, stopPrice, workingType, closePosition, positionSide, callbackRate, activationPrice, newOrderRespType):
check_should_not_none(symbol, "symbol")
check_should_not_none(side, "side")
check_should_not_none(ordertype, "ordertype")
Expand All @@ -381,6 +410,12 @@ def post_order(self, symbol, side, ordertype,
builder.put_url("newClientOrderId", newClientOrderId)
builder.put_url("stopPrice", stopPrice)
builder.put_url("workingType", workingType)
builder.put_url("closePosition", closePosition)
builder.put_url("positionSide", positionSide)
builder.put_url("callbackRate", callbackRate)
builder.put_url("activationPrice", activationPrice)
builder.put_url("newOrderRespType", newOrderRespType)


request = self.__create_request_by_post_with_signature("/dapi/v1/order", builder)

Expand Down Expand Up @@ -431,11 +466,7 @@ def cancel_all_orders(self, symbol):
request = self.__create_request_by_delete_with_signature("/dapi/v1/allOpenOrders", builder)

def parse(json_wrapper):
result = list()
data_list = json_wrapper.convert_2_array()
for item in data_list.get_items():
element = Order.json_parse(item)
result.append(element)
result = CodeMsg.json_parse(json_wrapper)
return result

request.json_parser = parse
Expand Down Expand Up @@ -556,7 +587,7 @@ def change_margin_type(self, symbol, marginType):
request = self.__create_request_by_post_with_signature("/dapi/v1/marginType", builder)

def parse(json_wrapper):
result = ChangeMarginType.json_parse(json_wrapper)
result = CodeMsg.json_parse(json_wrapper)
return result

request.json_parser = parse
Expand Down
3 changes: 2 additions & 1 deletion binance_d/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
from binance_d.model.balance import Balance
from binance_d.model.accountinformation import AccountInformation
from binance_d.model.leverage import Leverage
from binance_d.model.changemargintype import ChangeMarginType
from binance_d.model.codeandmsg import CodeMsg
from binance_d.model.positionmode import PositionMode
from binance_d.model.positionmargin import PositionMargin
from binance_d.model.positionmarginhistory import PositionMarginHist
from binance_d.model.position import Position
Expand Down
2 changes: 2 additions & 0 deletions binance_d/model/accountinformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self):
self.leverage = 0.0
self.unrealizedProfit = 0.0
self.isolated = False
self.positionSide = ""

@staticmethod
def json_parse(json_data):
Expand All @@ -48,6 +49,7 @@ def json_parse(json_data):
result.symbol = json_data.get_string("symbol")
result.unrealizedProfit = json_data.get_float("unrealizedProfit")
result.isolated = json_data.get_boolean("isolated")
result.positionSide = json_data.get_string("positionSide")
return result


Expand Down
17 changes: 10 additions & 7 deletions binance_d/model/accountupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self):
self.unrealizedPnl = 0.0
self.marginType = ""
self.isolatedWallet = 0.0
self.positionSide = ""

@staticmethod
def json_parse(json_data):
Expand All @@ -35,6 +36,7 @@ def json_parse(json_data):
result.unrealizedPnl = json_data.get_float("up")
result.marginType = json_data.get_string("mt")
result.isolatedWallet = json_data.get_float("iw")
result.positionSide = json_data.get_string("ps")
return result


Expand All @@ -61,11 +63,12 @@ def json_parse(json_data):
element = Balance.json_parse(item)
element_list.append(element)
result.balances = element_list

element_list = list()
data_list = data_group.get_array("P")
for item in data_list.get_items():
element = Position.json_parse(item)
element_list.append(element)
result.positions = element_list

if data_group.contain_key("P"):
element_list = list()
data_list = data_group.get_array("P")
for item in data_list.get_items():
element = Position.json_parse(item)
element_list.append(element)
result.positions = element_list
return result
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class ChangeMarginType:
class CodeMsg:

def __init__(self):
self.code = 0
self.msg = ""

@staticmethod
def json_parse(json_data):
result = ChangeMarginType()
result = CodeMsg()
result.code = json_data.get_int("code")
result.msg = json_data.get_string("msg")

Expand Down
Loading

0 comments on commit 71678a6

Please sign in to comment.